Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpAMP load/save effective configuration using remote_configuration_directory #1274

Merged
merged 17 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#1279]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1279
[v0.87.0-sumo-0]: https://github.com/SumoLogic/sumologic-otel-collector/compare/v0.86.0-sumo-0...v0.87.0-sumo-0

### Changed

- feat(opampextension): opamp effective configuration is only derived from the
remote_configuration_directory contents and the contents are managed by the
extension [#1274]

[#1274]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1274

## [v0.86.0-sumo-0]

### Released 2023-10-04
Expand Down
18 changes: 7 additions & 11 deletions pkg/extension/opampextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ extensions:
installation_token: <token>
api_base_url: <api_endpoint_url>
opamp:
instance_uid: <uniq_uid>
endpoint: <wss_endpoint_url>
remote_configuration_directory: /etc/otelcol-sumo/conf.d
remote_configuration_directory: /etc/otelcol-sumo/opamp.d
```

## API URLs
Expand All @@ -68,7 +67,7 @@ option:

Here is a list of valid values for the OpAMP `endpoint** configuration option:

**Note:** As of Jan 2023, these endpoints are not yet available.
portertech marked this conversation as resolved.
Show resolved Hide resolved
**Note:** These endpoints are not yet available.

| Deployment | API base URL |
|:-------------:|---------------------------------------------|
Expand All @@ -84,11 +83,8 @@ Here is a list of valid values for the OpAMP `endpoint** configuration option:
## Storing local configuration

When the OpAMP extension receives a remote configuration from the OpAMP server,
it persists the YAML configuration to a local file. The path of this file is
determined by the `remote_configuration_directory` configuration option and the
file name is `opamp-remote-config.yaml`. For example, if
`remote_configuration_directory` is set to `/etc/otelcol-sumo/conf.d`, the
resulting local configuration file path would be
`/etc/otelcol-sumo/conf.d/opamp-remote-config.yaml`. A configuration provider
must be used in order to load the stored configuration, for example: `--config
"glob:/etc/otelcol-sumo/conf.d/*"`.
it persists each received YAML configuration to a local file in the
`remote_configuration_directory`. The existing contents of the
`remote_configuration_directory` are removed before doing so. A configuration
provider must be used in order to load the stored configuration, for example:
`--config "glob:/etc/otelcol-sumo/opamp.d/*"`.
10 changes: 10 additions & 0 deletions pkg/extension/opampextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package opampextension

import (
"errors"
"fmt"
"os"

"github.com/oklog/ulid/v2"
"go.opentelemetry.io/collector/component"
Expand All @@ -34,6 +36,9 @@ type Config struct {
// RemoteConfigurationDirectory is where received OpAMP remote configuration
// is stored.
RemoteConfigurationDirectory string `mapstructure:"remote_configuration_directory"`

// AcceptsRemoteConfiguration indicates if the OpAMP agent will accept remote configuration.
AcceptsRemoteConfiguration bool `mapstructure:"accepts_remote_configuration"`
portertech marked this conversation as resolved.
Show resolved Hide resolved
}

// CreateDefaultHTTPClientSettings returns default http client settings
Expand All @@ -58,5 +63,10 @@ func (cfg *Config) Validate() error {
return errors.New("opamp remote_configuration_directory must be provided")
}

d := cfg.RemoteConfigurationDirectory
if _, err := os.Stat(d); err != nil {
return fmt.Errorf("opamp remote_configuration_directory %s must be readable: %v", d, err)
}

return nil
}
19 changes: 16 additions & 3 deletions pkg/extension/opampextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package opampextension

import (
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -50,7 +52,8 @@ func TestUnmarshalConfig(t *testing.T) {
},
},
InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZ",
RemoteConfigurationDirectory: "/tmp/",
RemoteConfigurationDirectory: "/tmp/opamp.d",
AcceptsRemoteConfiguration: true,
}, cfg)
}

Expand All @@ -59,9 +62,19 @@ func TestConfigValidate(t *testing.T) {
err := cfg.Validate()
require.Error(t, err)
assert.Equal(t, "opamp remote_configuration_directory must be provided", err.Error())
cfg.RemoteConfigurationDirectory = "/tmp/"

cfg.RemoteConfigurationDirectory = "/tmp/opamp.d"
err = cfg.Validate()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(err.Error(), "opamp remote_configuration_directory /tmp/opamp.d must be readable:"))

d, err := os.MkdirTemp("", "opamp.d")
assert.NoError(t, err)
defer os.RemoveAll(d)

cfg.RemoteConfigurationDirectory = d
err = cfg.Validate()
assert.NoError(t, err)

cfg.InstanceUID = "01BX5ZZKBKACTAV9WEVGEMMVRZFAIL"
err = cfg.Validate()
require.Error(t, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/extension/opampextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func NewFactory() extension.Factory {

func createDefaultConfig() component.Config {
return &Config{
HTTPClientSettings: CreateDefaultHTTPClientSettings(),
HTTPClientSettings: CreateDefaultHTTPClientSettings(),
AcceptsRemoteConfiguration: true,
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/extension/opampextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
AuthenticatorID: component.NewID("sumologic"),
},
},
AcceptsRemoteConfiguration: true,
})

assert.NoError(t, componenttest.CheckConfigStruct(cfg))
Expand Down
1 change: 1 addition & 0 deletions pkg/extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/SumoLogic/sumologic-otel-collector/pkg/extension/sumologicextension v0.77.0-sumo-0
github.com/google/uuid v1.3.0
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/rawbytes v0.1.0
github.com/knadh/koanf/v2 v2.0.1
Expand Down
2 changes: 2 additions & 0 deletions pkg/extension/opampextension/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
Expand Down
Loading
Loading