From 7290d5b0bf1914fd05517990bbc997c596bf154b Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Tue, 4 Jul 2023 15:11:10 +0530 Subject: [PATCH 1/3] Add Capabilities support to Supervisor config --- .../supervisor/config/config.go | 22 ++++- cmd/opampsupervisor/supervisor/supervisor.go | 83 +++++++++++++++++-- .../testdata/supervisor_darwin.yaml | 5 ++ .../testdata/supervisor_linux.yaml | 4 + .../testdata/supervisor_windows.yaml | 4 + 5 files changed, 109 insertions(+), 9 deletions(-) diff --git a/cmd/opampsupervisor/supervisor/config/config.go b/cmd/opampsupervisor/supervisor/config/config.go index 31edfce10f2e..a7d5d6d4ffc8 100644 --- a/cmd/opampsupervisor/supervisor/config/config.go +++ b/cmd/opampsupervisor/supervisor/config/config.go @@ -5,8 +5,26 @@ package config // Supervisor is the Supervisor config file format. type Supervisor struct { - Server *OpAMPServer - Agent *Agent + Server *OpAMPServer + Agent *Agent + Capabilities *Capabilities `mapstructure:"capabilities"` +} + +// Capabilities is the set of capabilities that the Supervisor supports. +type Capabilities struct { + AcceptsRemoteConfig *bool `mapstructure:"accepts_remote_config"` + AcceptsPackages *bool `mapstructure:"accepts_packages"` + AcceptsOpAMPConnectionSettings *bool `mapstructure:"accepts_opamp_connection_settings"` + AcceptsOtherConnectionSettings *bool `mapstructure:"accepts_other_connection_settings"` + AcceptsRestartCommand *bool `mapstructure:"accepts_restart_command"` + ReportsStatus *bool `mapstructure:"reports_status"` + ReportsEffectiveConfig *bool `mapstructure:"reports_effective_config"` + ReportsPackageStatuses *bool `mapstructure:"reports_package_statuses"` + ReportsOwnTraces *bool `mapstructure:"reports_own_traces"` + ReportsOwnMetrics *bool `mapstructure:"reports_own_metrics"` + ReportsOwnLogs *bool `mapstructure:"reports_own_logs"` + ReportsHealth *bool `mapstructure:"reports_health"` + ReportsRemoteConfig *bool `mapstructure:"reports_remote_config"` } type OpAMPServer struct { diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 4287e2c88c23..85b1fcfe2c4d 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -155,7 +155,11 @@ func (s *Supervisor) loadConfig(configFile string) error { return err } - if err := k.Unmarshal("", &s.config); err != nil { + decodeConf := koanf.UnmarshalConf{ + Tag: "mapstructure", + } + + if err := k.UnmarshalWithConf("", &s.config, decodeConf); err != nil { return fmt.Errorf("cannot parse %v: %w", configFile, err) } @@ -170,6 +174,75 @@ func (s *Supervisor) getBootstrapInfo() (err error) { return nil } +func (s *Supervisor) Capabilities() protobufs.AgentCapabilities { + var supportedCapabilities protobufs.AgentCapabilities + + if c := s.config.Capabilities; c != nil { + if c.AcceptsOpAMPConnectionSettings != nil && *c.AcceptsOpAMPConnectionSettings { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsOpAMPConnectionSettings + } + if c.AcceptsOtherConnectionSettings != nil && *c.AcceptsOtherConnectionSettings { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsOtherConnectionSettings + } + if c.AcceptsPackages != nil && *c.AcceptsPackages { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages + } + if c.AcceptsRemoteConfig != nil && *c.AcceptsRemoteConfig { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig + } + + // AcceptsRestartCommand is set if unspecified or explicitly set to true. + if c.AcceptsRestartCommand != nil && *c.AcceptsRestartCommand { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsRestartCommand + } else if c.AcceptsRestartCommand == nil { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsRestartCommand + } + + // ReportsEffectiveConfig is set if unspecified or explicitly set to true. + if c.ReportsEffectiveConfig != nil && *c.ReportsEffectiveConfig { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig + } else if c.ReportsEffectiveConfig == nil { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig + } + + // ReportsHealth is set if unspecified or explicitly set to true. + if c.ReportsHealth != nil && *c.ReportsHealth { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth + } else if c.ReportsHealth == nil { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth + } + + // ReportsOwnLogs is set if unspecified or explicitly set to true. + if c.ReportsOwnLogs != nil && *c.ReportsOwnLogs { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs + } else if c.ReportsOwnLogs == nil { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs + } + + // ReportsOwnMetrics is set if unspecified or explicitly set to true. + if c.ReportsOwnMetrics != nil && *c.ReportsOwnMetrics { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics + } else if c.ReportsOwnMetrics == nil { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics + } + + if c.ReportsOwnTraces != nil && *c.ReportsOwnTraces { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnTraces + } + if c.ReportsPackageStatuses != nil && *c.ReportsPackageStatuses { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses + } + if c.ReportsRemoteConfig != nil && *c.ReportsRemoteConfig { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig + } + if c.ReportsStatus != nil && *c.ReportsStatus { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus + } + } + + return supportedCapabilities +} + func (s *Supervisor) startOpAMP() error { s.opampClient = client.NewWebSocket(s.logger.Sugar()) @@ -211,13 +284,9 @@ func (s *Supervisor) startOpAMP() error { return s.createEffectiveConfigMsg(), nil }, }, - // TODO: Make capabilities configurable - Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig | - protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig | - protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig | - protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics | - protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth, + Capabilities: s.Capabilities(), } + s.logger.Debug("Using capabilities", zap.String("capabilities", s.Capabilities().String())) err := s.opampClient.SetAgentDescription(s.createAgentDescription()) if err != nil { return err diff --git a/cmd/opampsupervisor/testdata/supervisor_darwin.yaml b/cmd/opampsupervisor/testdata/supervisor_darwin.yaml index 9b278fedbcd8..fa129319048c 100644 --- a/cmd/opampsupervisor/testdata/supervisor_darwin.yaml +++ b/cmd/opampsupervisor/testdata/supervisor_darwin.yaml @@ -1,5 +1,10 @@ server: endpoint: ws://127.0.0.1:4320/v1/opamp +capabilities: + reports_effective_config: true + reports_own_metrics: true + reports_health: true + agent: executable: ../../bin/otelcontribcol_darwin_amd64 diff --git a/cmd/opampsupervisor/testdata/supervisor_linux.yaml b/cmd/opampsupervisor/testdata/supervisor_linux.yaml index 9cb491ff2436..ed1d67cea5e0 100644 --- a/cmd/opampsupervisor/testdata/supervisor_linux.yaml +++ b/cmd/opampsupervisor/testdata/supervisor_linux.yaml @@ -1,5 +1,9 @@ server: endpoint: ws://127.0.0.1:4320/v1/opamp +capabilities: + reports_effective_config: true + reports_own_metrics: true + reports_health: true agent: executable: ../../bin/otelcontribcol_linux_amd64 diff --git a/cmd/opampsupervisor/testdata/supervisor_windows.yaml b/cmd/opampsupervisor/testdata/supervisor_windows.yaml index 0aefc0c2b727..eb7c58e133cc 100644 --- a/cmd/opampsupervisor/testdata/supervisor_windows.yaml +++ b/cmd/opampsupervisor/testdata/supervisor_windows.yaml @@ -1,5 +1,9 @@ server: endpoint: ws://127.0.0.1:4320/v1/opamp +capabilities: + reports_effective_config: true + reports_own_metrics: true + reports_health: true agent: executable: ../../bin/otelcontribcol_windows_amd64.exe From 0dcffafc7e0e30a7e3292561093f1221abe37982 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Wed, 5 Jul 2023 13:46:04 +0530 Subject: [PATCH 2/3] Remove Capabilities yet to be supported --- .../supervisor/config/config.go | 6 +----- cmd/opampsupervisor/supervisor/supervisor.go | 19 ------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/cmd/opampsupervisor/supervisor/config/config.go b/cmd/opampsupervisor/supervisor/config/config.go index a7d5d6d4ffc8..4f7c2c1bb5bf 100644 --- a/cmd/opampsupervisor/supervisor/config/config.go +++ b/cmd/opampsupervisor/supervisor/config/config.go @@ -11,18 +11,14 @@ type Supervisor struct { } // Capabilities is the set of capabilities that the Supervisor supports. +// TODO: Support more capabilities type Capabilities struct { AcceptsRemoteConfig *bool `mapstructure:"accepts_remote_config"` - AcceptsPackages *bool `mapstructure:"accepts_packages"` AcceptsOpAMPConnectionSettings *bool `mapstructure:"accepts_opamp_connection_settings"` - AcceptsOtherConnectionSettings *bool `mapstructure:"accepts_other_connection_settings"` AcceptsRestartCommand *bool `mapstructure:"accepts_restart_command"` ReportsStatus *bool `mapstructure:"reports_status"` ReportsEffectiveConfig *bool `mapstructure:"reports_effective_config"` - ReportsPackageStatuses *bool `mapstructure:"reports_package_statuses"` - ReportsOwnTraces *bool `mapstructure:"reports_own_traces"` ReportsOwnMetrics *bool `mapstructure:"reports_own_metrics"` - ReportsOwnLogs *bool `mapstructure:"reports_own_logs"` ReportsHealth *bool `mapstructure:"reports_health"` ReportsRemoteConfig *bool `mapstructure:"reports_remote_config"` } diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 85b1fcfe2c4d..057b8cd434a2 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -181,12 +181,6 @@ func (s *Supervisor) Capabilities() protobufs.AgentCapabilities { if c.AcceptsOpAMPConnectionSettings != nil && *c.AcceptsOpAMPConnectionSettings { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsOpAMPConnectionSettings } - if c.AcceptsOtherConnectionSettings != nil && *c.AcceptsOtherConnectionSettings { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsOtherConnectionSettings - } - if c.AcceptsPackages != nil && *c.AcceptsPackages { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages - } if c.AcceptsRemoteConfig != nil && *c.AcceptsRemoteConfig { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig } @@ -212,13 +206,6 @@ func (s *Supervisor) Capabilities() protobufs.AgentCapabilities { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth } - // ReportsOwnLogs is set if unspecified or explicitly set to true. - if c.ReportsOwnLogs != nil && *c.ReportsOwnLogs { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs - } else if c.ReportsOwnLogs == nil { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs - } - // ReportsOwnMetrics is set if unspecified or explicitly set to true. if c.ReportsOwnMetrics != nil && *c.ReportsOwnMetrics { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics @@ -226,12 +213,6 @@ func (s *Supervisor) Capabilities() protobufs.AgentCapabilities { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics } - if c.ReportsOwnTraces != nil && *c.ReportsOwnTraces { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnTraces - } - if c.ReportsPackageStatuses != nil && *c.ReportsPackageStatuses { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses - } if c.ReportsRemoteConfig != nil && *c.ReportsRemoteConfig { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig } From d1fef78fdb7ef37a38e4cc9df6057a700ffcbc83 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 13 Jul 2023 14:50:24 +0530 Subject: [PATCH 3/3] Add changelog and update if-else logic --- ...-opamp-supervisor-capabilities-config.yaml | 20 +++++++++++++++++++ cmd/opampsupervisor/supervisor/supervisor.go | 19 +++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 .chloggen/add-opamp-supervisor-capabilities-config.yaml diff --git a/.chloggen/add-opamp-supervisor-capabilities-config.yaml b/.chloggen/add-opamp-supervisor-capabilities-config.yaml new file mode 100644 index 000000000000..ba0661b59046 --- /dev/null +++ b/.chloggen/add-opamp-supervisor-capabilities-config.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# 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: opamp supervisor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add Capabilities support to Supervisor config. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [21044] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: \ No newline at end of file diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 107386f93a04..107c44db3b9a 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -176,35 +176,30 @@ func (s *Supervisor) getBootstrapInfo() (err error) { func (s *Supervisor) Capabilities() protobufs.AgentCapabilities { var supportedCapabilities protobufs.AgentCapabilities - if c := s.config.Capabilities; c != nil { - // ReportsEffectiveConfig is set if unspecified or explicitly set to true. - if c.ReportsEffectiveConfig != nil && *c.ReportsEffectiveConfig { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig - } else if c.ReportsEffectiveConfig == nil { + if (c.ReportsEffectiveConfig != nil && *c.ReportsEffectiveConfig) || c.ReportsEffectiveConfig == nil { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig } // ReportsHealth is set if unspecified or explicitly set to true. - if c.ReportsHealth != nil && *c.ReportsHealth { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth - } else if c.ReportsHealth == nil { + if (c.ReportsHealth != nil && *c.ReportsHealth) || c.ReportsHealth == nil { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth } // ReportsOwnMetrics is set if unspecified or explicitly set to true. - if c.ReportsOwnMetrics != nil && *c.ReportsOwnMetrics { - supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics - } else if c.ReportsOwnMetrics == nil { + if (c.ReportsOwnMetrics != nil && *c.ReportsOwnMetrics) || c.ReportsOwnMetrics == nil { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics } + if c.AcceptsRemoteConfig != nil && *c.AcceptsRemoteConfig { + supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig + } + if c.ReportsRemoteConfig != nil && *c.ReportsRemoteConfig { supportedCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig } } - return supportedCapabilities }