Skip to content

Commit

Permalink
OpAMP load/save effective configuration using remote_configuration_di…
Browse files Browse the repository at this point in the history
…rectory (#1274)

* opamp exclusive ulid config, semconv attrib keys

Signed-off-by: Sean Porter <[email protected]>

* opamp load and save effective config from/to remote configuration directory

Signed-off-by: Sean Porter <[email protected]>

* updated opamp readme to reflect the changes in remote config persistence

Signed-off-by: Sean Porter <[email protected]>

* configurable opamp accepts remote configuration

Signed-off-by: Sean Porter <[email protected]>

* opamp config validate remote_configuration_directory existence

Signed-off-by: Sean Porter <[email protected]>

* opamp don't use io/ioutil

Signed-off-by: Sean Porter <[email protected]>

* opamp changelog feat entry

Signed-off-by: Sean Porter <[email protected]>

* opamp platform agnostic directory stat testing

Signed-off-by: Sean Porter <[email protected]>

* opamp cross-platform glob path

Signed-off-by: Sean Porter <[email protected]>

* translate service id uuid to opamp agent ulid

Signed-off-by: Sean Porter <[email protected]>

* opamp enforce accepts remote config false

Signed-off-by: Sean Porter <[email protected]>

* removed opamp endpoint readme "as of" date

Signed-off-by: Sean Porter <[email protected]>

* opamp save config rm previous config error checking

Signed-off-by: Sean Porter <[email protected]>

* updated changelog entry for opamp changes

Signed-off-by: Sean Porter <[email protected]>

---------

Signed-off-by: Sean Porter <[email protected]>
  • Loading branch information
portertech authored Oct 13, 2023
1 parent 582210a commit c0520a1
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 139 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Released TBD

### 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
[Unreleased]: https://github.com/SumoLogic/sumologic-otel-collector/compare/v0.87.0-sumo-0...main

## [v0.87.0-sumo-0]
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.
**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"`
}

// 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

0 comments on commit c0520a1

Please sign in to comment.