From d4b247257d4301bc05917f18cee3a4a2832112d5 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Wed, 1 May 2024 12:22:45 -0400 Subject: [PATCH 1/9] add agent description to supervisor config --- cmd/opampsupervisor/e2e_test.go | 93 ++++++++++++++++++- .../supervisor/config/config.go | 32 ++++++- .../supervisor/config/config_test.go | 84 +++++++++++++++++ cmd/opampsupervisor/supervisor/supervisor.go | 51 +++++++++- .../supervisor_agent_description.yaml | 20 ++++ 5 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 cmd/opampsupervisor/supervisor/config/config_test.go create mode 100644 cmd/opampsupervisor/testdata/supervisor/supervisor_agent_description.yaml diff --git a/cmd/opampsupervisor/e2e_test.go b/cmd/opampsupervisor/e2e_test.go index 3756bed93152..8dfd6d35bacb 100644 --- a/cmd/opampsupervisor/e2e_test.go +++ b/cmd/opampsupervisor/e2e_test.go @@ -34,7 +34,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" semconv "go.opentelemetry.io/collector/semconv/v1.21.0" - "go.uber.org/zap" + "go.uber.org/zap/zaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor/config" @@ -139,7 +139,7 @@ func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, ca func newSupervisor(t *testing.T, configType string, extraConfigData map[string]string) *supervisor.Supervisor { cfgFile := getSupervisorConfig(t, configType, extraConfigData) - s, err := supervisor.NewSupervisor(zap.NewNop(), cfgFile.Name()) + s, err := supervisor.NewSupervisor(zaptest.NewLogger(t), cfgFile.Name()) require.NoError(t, err) return s @@ -416,6 +416,95 @@ func TestSupervisorBootstrapsCollector(t *testing.T) { }, 5*time.Second, 250*time.Millisecond) } +func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) { + // Load the Supervisor config so we can get the location of + // the Collector that will be run. + var cfg config.Supervisor + cfgFile := getSupervisorConfig(t, "nocap", map[string]string{}) + k := koanf.New("::") + err := k.Load(file.Provider(cfgFile.Name()), yaml.Parser()) + require.NoError(t, err) + err = k.UnmarshalWithConf("", &cfg, koanf.UnmarshalConf{ + Tag: "mapstructure", + }) + require.NoError(t, err) + + host, err := os.Hostname() + require.NoError(t, err) + + // Get the binary name and version from the Collector binary + // using the `components` command that prints a YAML-encoded + // map of information about the Collector build. Some of this + // information will be used as defaults for the telemetry + // attributes. + agentPath := cfg.Agent.Executable + componentsInfo, err := exec.Command(agentPath, "components").Output() + require.NoError(t, err) + k = koanf.New("::") + err = k.Load(rawbytes.Provider(componentsInfo), yaml.Parser()) + require.NoError(t, err) + buildinfo := k.StringMap("buildinfo") + command := buildinfo["command"] + version := buildinfo["version"] + + agentDescMessageChan := make(chan *protobufs.AgentToServer, 1) + + server := newOpAMPServer( + t, + defaultConnectingHandler, + server.ConnectionCallbacksStruct{ + OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + if message.AgentDescription != nil { + select { + case agentDescMessageChan <- message: + default: + } + } + + return &protobufs.ServerToAgent{} + }, + }) + + s := newSupervisor(t, "agent_description", map[string]string{"url": server.addr}) + defer s.Shutdown() + + waitForSupervisorConnection(server.supervisorConnected, true) + var ad *protobufs.AgentToServer + select { + case ad = <-agentDescMessageChan: + case <-time.After(5 * time.Second): + t.Fatal("Failed to get agent description after 5 seconds") + } + + expectedDescription := &protobufs.AgentDescription{ + IdentifyingAttributes: []*protobufs.KeyValue{ + stringKeyValue("client.id", "my-client-id"), + stringKeyValue(semconv.AttributeServiceInstanceID, ad.InstanceUid), + stringKeyValue(semconv.AttributeServiceName, command), + stringKeyValue(semconv.AttributeServiceVersion, version), + }, + NonIdentifyingAttributes: []*protobufs.KeyValue{ + stringKeyValue("env", "prod"), + stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH), + stringKeyValue(semconv.AttributeHostName, host), + stringKeyValue(semconv.AttributeOSType, runtime.GOOS), + }, + } + + require.Equal(t, expectedDescription, ad.AgentDescription) +} + +func stringKeyValue(key, val string) *protobufs.KeyValue { + return &protobufs.KeyValue{ + Key: key, + Value: &protobufs.AnyValue{ + Value: &protobufs.AnyValue_StringValue{ + StringValue: val, + }, + }, + } +} + // Creates a Collector config that reads and writes logs to files and provides // file descriptors for I/O operations to those files. The files are placed // in a unique temp directory that is cleaned up after the test's completion. diff --git a/cmd/opampsupervisor/supervisor/config/config.go b/cmd/opampsupervisor/supervisor/config/config.go index fc353dca4a0a..9e1e6f0eb218 100644 --- a/cmd/opampsupervisor/supervisor/config/config.go +++ b/cmd/opampsupervisor/supervisor/config/config.go @@ -4,9 +4,11 @@ package config import ( + "fmt" "net/http" "go.opentelemetry.io/collector/config/configtls" + semconv "go.opentelemetry.io/collector/semconv/v1.21.0" ) // Supervisor is the Supervisor config file format. @@ -17,6 +19,14 @@ type Supervisor struct { Storage *Storage `mapstructure:"storage"` } +func (s *Supervisor) Validate() error { + if s.Agent != nil { + return s.Agent.Validate() + } + + return nil +} + type Storage struct { // Directory is the directory where the Supervisor will store its data. Directory string `mapstructure:"directory"` @@ -40,5 +50,25 @@ type OpAMPServer struct { } type Agent struct { - Executable string + Executable string + Description AgentDescription `mapstructure:"description"` +} + +func (a *Agent) Validate() error { + return a.Description.Validate() +} + +type AgentDescription struct { + IdentifyingAttributes map[string]string `mapstructure:"identifying_attributes"` + NonIdentifyingAttributes map[string]string `mapstructure:"non_identifying_attributes"` +} + +func (a *AgentDescription) Validate() error { + for k := range a.IdentifyingAttributes { + // Don't allow overriding the instance ID attribute + if k == semconv.AttributeServiceInstanceID { + return fmt.Errorf("cannot override identifying attribute %q", semconv.AttributeServiceInstanceID) + } + } + return nil } diff --git a/cmd/opampsupervisor/supervisor/config/config_test.go b/cmd/opampsupervisor/supervisor/config/config_test.go new file mode 100644 index 000000000000..6bd8cdd5f4bf --- /dev/null +++ b/cmd/opampsupervisor/supervisor/config/config_test.go @@ -0,0 +1,84 @@ +package config + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config/configtls" + semconv "go.opentelemetry.io/collector/semconv/v1.21.0" +) + +func TestValidate(t *testing.T) { + testCases := []struct { + name string + config Supervisor + expectedError string + }{ + { + name: "Empty Config is valid", + config: Supervisor{}, + }, + { + name: "Valid filled out config", + config: Supervisor{ + Server: &OpAMPServer{ + Endpoint: "wss://localhost:9090/opamp", + Headers: http.Header{ + "Header1": []string{"HeaderValue"}, + }, + TLSSetting: configtls.ClientConfig{ + Insecure: true, + }, + }, + Agent: &Agent{ + Executable: "../../otelcol", + Description: AgentDescription{ + IdentifyingAttributes: map[string]string{ + "client.id": "some-client-id", + }, + NonIdentifyingAttributes: map[string]string{ + "env": "dev", + }, + }, + }, + Capabilities: &Capabilities{ + AcceptsRemoteConfig: asPtr(true), + }, + Storage: &Storage{ + Directory: "/etc/opamp-supervisor/storage", + }, + }, + }, + { + name: "Cannot override instance ID", + config: Supervisor{ + Agent: &Agent{ + Executable: "../../otelcol", + Description: AgentDescription{ + IdentifyingAttributes: map[string]string{ + semconv.AttributeServiceInstanceID: "instance-id", + }, + }, + }, + }, + expectedError: `cannot override identifying attribute "service.instance.id"`, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.config.Validate() + + if tc.expectedError == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedError) + } + }) + } +} + +func asPtr[T any](t T) *T { + return &t +} diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 339c05ecf2b2..c0923b6832a5 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -221,6 +221,10 @@ func (s *Supervisor) loadConfig(configFile string) error { return fmt.Errorf("cannot parse %v: %w", configFile, err) } + if err := s.config.Validate(); err != nil { + return fmt.Errorf("invalid config: %w", err) + } + return nil } @@ -256,7 +260,7 @@ func (s *Supervisor) getBootstrapInfo() (err error) { onMessageFunc: func(_ serverTypes.Connection, message *protobufs.AgentToServer) { if message.AgentDescription != nil { instanceIDSeen := false - s.agentDescription = message.AgentDescription + s.setAgentDescription(message.AgentDescription) identAttr := s.agentDescription.IdentifyingAttributes for _, attr := range identAttr { @@ -431,6 +435,51 @@ func (s *Supervisor) startOpAMP() error { return nil } +// setAgentDescription sets the agent description, merging in any user-specified attributes from the supervisor configuration. +func (s *Supervisor) setAgentDescription(ad *protobufs.AgentDescription) { + ad.IdentifyingAttributes = applyKeyValueOverrides(s.config.Agent.Description.IdentifyingAttributes, ad.IdentifyingAttributes) + ad.NonIdentifyingAttributes = applyKeyValueOverrides(s.config.Agent.Description.NonIdentifyingAttributes, ad.NonIdentifyingAttributes) + s.agentDescription = ad +} + +// applyKeyValueOverrides merges the overrides map into the array of key value pairs. +// If a key from overrides already exists in the array of key value pairs, it is overwritten by the value from the overrides map. +// An array of KeyValue pair is returned, with each key value pair having a distinct key. +func applyKeyValueOverrides(overrides map[string]string, orig []*protobufs.KeyValue) []*protobufs.KeyValue { + kvMap := make(map[string]*protobufs.KeyValue, len(orig)+len(overrides)) + + for _, kv := range orig { + kvMap[kv.Key] = kv + } + + for k, v := range overrides { + kvMap[k] = &protobufs.KeyValue{ + Key: k, + Value: &protobufs.AnyValue{ + Value: &protobufs.AnyValue_StringValue{ + StringValue: v, + }, + }, + } + } + + // Sort keys for stable output, makes it easier to test. + keys := make([]string, 0, len(kvMap)) + for k := range kvMap { + keys = append(keys, k) + } + + sort.Strings(keys) + + kvOut := make([]*protobufs.KeyValue, 0, len(kvMap)) + for _, k := range keys { + v := kvMap[k] + kvOut = append(kvOut, v) + } + + return kvOut +} + func (s *Supervisor) stopOpAMP() error { s.logger.Debug("Stopping OpAMP client...") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) diff --git a/cmd/opampsupervisor/testdata/supervisor/supervisor_agent_description.yaml b/cmd/opampsupervisor/testdata/supervisor/supervisor_agent_description.yaml new file mode 100644 index 000000000000..d6854d99469d --- /dev/null +++ b/cmd/opampsupervisor/testdata/supervisor/supervisor_agent_description.yaml @@ -0,0 +1,20 @@ +server: + endpoint: ws://{{.url}}/v1/opamp + tls: + insecure: true + +capabilities: + reports_effective_config: true + reports_own_metrics: true + reports_health: true + accepts_remote_config: true + reports_remote_config: true + accepts_restart_command: true + +agent: + executable: ../../bin/otelcontribcol_{{.goos}}_{{.goarch}}{{.extension}} + description: + identifying_attributes: + client.id: "my-client-id" + non_identifying_attributes: + env: "prod" From 02a5c4ac9804c50904adc3a619cc8ab9b69f8aa1 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Wed, 1 May 2024 12:33:51 -0400 Subject: [PATCH 2/9] add time.sleep (race condition prevents shutdown) --- cmd/opampsupervisor/e2e_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/opampsupervisor/e2e_test.go b/cmd/opampsupervisor/e2e_test.go index 8dfd6d35bacb..d5512a52f790 100644 --- a/cmd/opampsupervisor/e2e_test.go +++ b/cmd/opampsupervisor/e2e_test.go @@ -420,7 +420,7 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) { // Load the Supervisor config so we can get the location of // the Collector that will be run. var cfg config.Supervisor - cfgFile := getSupervisorConfig(t, "nocap", map[string]string{}) + cfgFile := getSupervisorConfig(t, "agent_description", map[string]string{}) k := koanf.New("::") err := k.Load(file.Provider(cfgFile.Name()), yaml.Parser()) require.NoError(t, err) @@ -492,6 +492,8 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) { } require.Equal(t, expectedDescription, ad.AgentDescription) + + time.Sleep(250 * time.Millisecond) } func stringKeyValue(key, val string) *protobufs.KeyValue { From 10cf48125daa07f35daf1e4e0e565b948badab22 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 2 May 2024 09:09:52 -0400 Subject: [PATCH 3/9] add chlog entry --- .chloggen/feat_supervisor-agent-description.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .chloggen/feat_supervisor-agent-description.yaml diff --git a/.chloggen/feat_supervisor-agent-description.yaml b/.chloggen/feat_supervisor-agent-description.yaml new file mode 100644 index 000000000000..c93c38dd523a --- /dev/null +++ b/.chloggen/feat_supervisor-agent-description.yaml @@ -0,0 +1,13 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: opampsupervisor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds the ability to configure the agent description + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [32644] From 49b1fe1cd8ae0f7bc82f0316bb965705557a8dc6 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 2 May 2024 10:02:54 -0400 Subject: [PATCH 4/9] add agent description config to spec --- cmd/opampsupervisor/specification/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/opampsupervisor/specification/README.md b/cmd/opampsupervisor/specification/README.md index 0fef754e446a..5e1bdb67c79b 100644 --- a/cmd/opampsupervisor/specification/README.md +++ b/cmd/opampsupervisor/specification/README.md @@ -119,7 +119,7 @@ storage: # and %ProgramData%/Otelcol/Supervisor on Windows. directory: /path/to/dir -collector: +agent: # Path to Collector executable. Required. executable: /opt/otelcol/bin/otelcol @@ -144,6 +144,18 @@ collector: deny: \[/var/log/secret_logs\] write: allow: \[/var/otelcol\] + + # Optional key-value pairs to add to either the identifying attributes or + # non-identifying attributes of the agent description sent to the OpAMP server. + # Values here override the values in the agent description retrieved from the collector's + # OpAMP extension. + # The service.instance.id identifying attribute may not be overridden. + description: + identifying_attributes: + client.id: "01HWWSK84BMT7J45663MBJMTPJ" + non_identifying_attributes: + custom.attribute: "custom-value" + ``` ### Executing Collector From a65064cae59edaa61747835f0d9c77e95fe45a2d Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 2 May 2024 10:12:39 -0400 Subject: [PATCH 5/9] remove zaptest logger --- cmd/opampsupervisor/e2e_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/opampsupervisor/e2e_test.go b/cmd/opampsupervisor/e2e_test.go index d5512a52f790..9e90c412405a 100644 --- a/cmd/opampsupervisor/e2e_test.go +++ b/cmd/opampsupervisor/e2e_test.go @@ -34,7 +34,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" semconv "go.opentelemetry.io/collector/semconv/v1.21.0" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor/config" @@ -139,7 +139,7 @@ func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, ca func newSupervisor(t *testing.T, configType string, extraConfigData map[string]string) *supervisor.Supervisor { cfgFile := getSupervisorConfig(t, configType, extraConfigData) - s, err := supervisor.NewSupervisor(zaptest.NewLogger(t), cfgFile.Name()) + s, err := supervisor.NewSupervisor(zap.NewNop(), cfgFile.Name()) require.NoError(t, err) return s From 4131185c27d710e34119b08b8156bbbf1bfadd65 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 2 May 2024 10:28:04 -0400 Subject: [PATCH 6/9] add license header --- cmd/opampsupervisor/supervisor/config/config_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/opampsupervisor/supervisor/config/config_test.go b/cmd/opampsupervisor/supervisor/config/config_test.go index 6bd8cdd5f4bf..d09228391242 100644 --- a/cmd/opampsupervisor/supervisor/config/config_test.go +++ b/cmd/opampsupervisor/supervisor/config/config_test.go @@ -1,3 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package config import ( From 67aa2f1602c11923fe146d6ec127cfc27d984127 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 2 May 2024 11:14:03 -0400 Subject: [PATCH 7/9] update issue number --- .chloggen/feat_supervisor-agent-description.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/feat_supervisor-agent-description.yaml b/.chloggen/feat_supervisor-agent-description.yaml index c93c38dd523a..eba148aad42c 100644 --- a/.chloggen/feat_supervisor-agent-description.yaml +++ b/.chloggen/feat_supervisor-agent-description.yaml @@ -10,4 +10,4 @@ component: opampsupervisor note: Adds the ability to configure the agent description # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [32644] +issues: [32824] From 8e831505099e7545d6d8a91cb0c45d18788f63cc Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Fri, 3 May 2024 10:34:14 -0400 Subject: [PATCH 8/9] Allow overriding instance id --- cmd/opampsupervisor/specification/README.md | 1 - .../supervisor/config/config.go | 24 ----- .../supervisor/config/config_test.go | 87 ------------------- cmd/opampsupervisor/supervisor/supervisor.go | 4 - 4 files changed, 116 deletions(-) delete mode 100644 cmd/opampsupervisor/supervisor/config/config_test.go diff --git a/cmd/opampsupervisor/specification/README.md b/cmd/opampsupervisor/specification/README.md index 5e1bdb67c79b..6a761959a672 100644 --- a/cmd/opampsupervisor/specification/README.md +++ b/cmd/opampsupervisor/specification/README.md @@ -149,7 +149,6 @@ agent: # non-identifying attributes of the agent description sent to the OpAMP server. # Values here override the values in the agent description retrieved from the collector's # OpAMP extension. - # The service.instance.id identifying attribute may not be overridden. description: identifying_attributes: client.id: "01HWWSK84BMT7J45663MBJMTPJ" diff --git a/cmd/opampsupervisor/supervisor/config/config.go b/cmd/opampsupervisor/supervisor/config/config.go index 9e1e6f0eb218..415a7e59fd6b 100644 --- a/cmd/opampsupervisor/supervisor/config/config.go +++ b/cmd/opampsupervisor/supervisor/config/config.go @@ -4,11 +4,9 @@ package config import ( - "fmt" "net/http" "go.opentelemetry.io/collector/config/configtls" - semconv "go.opentelemetry.io/collector/semconv/v1.21.0" ) // Supervisor is the Supervisor config file format. @@ -19,14 +17,6 @@ type Supervisor struct { Storage *Storage `mapstructure:"storage"` } -func (s *Supervisor) Validate() error { - if s.Agent != nil { - return s.Agent.Validate() - } - - return nil -} - type Storage struct { // Directory is the directory where the Supervisor will store its data. Directory string `mapstructure:"directory"` @@ -54,21 +44,7 @@ type Agent struct { Description AgentDescription `mapstructure:"description"` } -func (a *Agent) Validate() error { - return a.Description.Validate() -} - type AgentDescription struct { IdentifyingAttributes map[string]string `mapstructure:"identifying_attributes"` NonIdentifyingAttributes map[string]string `mapstructure:"non_identifying_attributes"` } - -func (a *AgentDescription) Validate() error { - for k := range a.IdentifyingAttributes { - // Don't allow overriding the instance ID attribute - if k == semconv.AttributeServiceInstanceID { - return fmt.Errorf("cannot override identifying attribute %q", semconv.AttributeServiceInstanceID) - } - } - return nil -} diff --git a/cmd/opampsupervisor/supervisor/config/config_test.go b/cmd/opampsupervisor/supervisor/config/config_test.go deleted file mode 100644 index d09228391242..000000000000 --- a/cmd/opampsupervisor/supervisor/config/config_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package config - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config/configtls" - semconv "go.opentelemetry.io/collector/semconv/v1.21.0" -) - -func TestValidate(t *testing.T) { - testCases := []struct { - name string - config Supervisor - expectedError string - }{ - { - name: "Empty Config is valid", - config: Supervisor{}, - }, - { - name: "Valid filled out config", - config: Supervisor{ - Server: &OpAMPServer{ - Endpoint: "wss://localhost:9090/opamp", - Headers: http.Header{ - "Header1": []string{"HeaderValue"}, - }, - TLSSetting: configtls.ClientConfig{ - Insecure: true, - }, - }, - Agent: &Agent{ - Executable: "../../otelcol", - Description: AgentDescription{ - IdentifyingAttributes: map[string]string{ - "client.id": "some-client-id", - }, - NonIdentifyingAttributes: map[string]string{ - "env": "dev", - }, - }, - }, - Capabilities: &Capabilities{ - AcceptsRemoteConfig: asPtr(true), - }, - Storage: &Storage{ - Directory: "/etc/opamp-supervisor/storage", - }, - }, - }, - { - name: "Cannot override instance ID", - config: Supervisor{ - Agent: &Agent{ - Executable: "../../otelcol", - Description: AgentDescription{ - IdentifyingAttributes: map[string]string{ - semconv.AttributeServiceInstanceID: "instance-id", - }, - }, - }, - }, - expectedError: `cannot override identifying attribute "service.instance.id"`, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := tc.config.Validate() - - if tc.expectedError == "" { - require.NoError(t, err) - } else { - require.ErrorContains(t, err, tc.expectedError) - } - }) - } -} - -func asPtr[T any](t T) *T { - return &t -} diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index c0923b6832a5..096557179951 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -221,10 +221,6 @@ func (s *Supervisor) loadConfig(configFile string) error { return fmt.Errorf("cannot parse %v: %w", configFile, err) } - if err := s.config.Validate(); err != nil { - return fmt.Errorf("invalid config: %w", err) - } - return nil } From cf57dfa9cb5c95d109d72a3de03e1d806e3d1280 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Wed, 15 May 2024 10:11:43 -0400 Subject: [PATCH 9/9] Update cmd/opampsupervisor/specification/README.md Co-authored-by: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com> --- cmd/opampsupervisor/specification/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/opampsupervisor/specification/README.md b/cmd/opampsupervisor/specification/README.md index 6a761959a672..82bd91c42a3f 100644 --- a/cmd/opampsupervisor/specification/README.md +++ b/cmd/opampsupervisor/specification/README.md @@ -148,7 +148,7 @@ agent: # Optional key-value pairs to add to either the identifying attributes or # non-identifying attributes of the agent description sent to the OpAMP server. # Values here override the values in the agent description retrieved from the collector's - # OpAMP extension. + # OpAMP extension (self-reported by the Collector). description: identifying_attributes: client.id: "01HWWSK84BMT7J45663MBJMTPJ"