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

Add Capabilities support to Supervisor config #23948

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions cmd/opampsupervisor/supervisor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
AcceptsRemoteConfig *bool `mapstructure:"accepts_remote_config"`
AcceptsPackages *bool `mapstructure:"accepts_packages"`
AcceptsOpAMPConnectionSettings *bool `mapstructure:"accepts_opamp_connection_settings"`
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
AcceptsOtherConnectionSettings *bool `mapstructure:"accepts_other_connection_settings"`
AcceptsRestartCommand *bool `mapstructure:"accepts_restart_command"`
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
83 changes: 76 additions & 7 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
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())

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/opampsupervisor/testdata/supervisor_darwin.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions cmd/opampsupervisor/testdata/supervisor_linux.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions cmd/opampsupervisor/testdata/supervisor_windows.yaml
Original file line number Diff line number Diff line change
@@ -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