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

[cmd/opampsupervisor] Add OpAMP supervisor skeleton #19143

Merged
merged 17 commits into from
Jun 14, 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
Prev Previous commit
Next Next commit
Address PR feedback and add issues
  • Loading branch information
evan-bradley committed Jun 13, 2023
commit 61ef95c21086b260bae2f6779a2bda124d094f9d
1 change: 0 additions & 1 deletion cmd/opampsupervisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/knadh/koanf v1.5.0
github.com/oklog/ulid/v2 v2.1.0
github.com/open-telemetry/opamp-go v0.6.0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13
go.uber.org/atomic v1.7.0
go.uber.org/zap v1.17.0
)
Expand Down
2 changes: 0 additions & 2 deletions cmd/opampsupervisor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/opampsupervisor/supervisor/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (c *Commander) Start(ctx context.Context) error {
c.cmd = exec.CommandContext(ctx, c.cfg.Executable, c.args...) // #nosec G204

// Capture standard output and standard error.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21072
c.cmd.Stdout = logFile
c.cmd.Stderr = logFile

Expand Down
30 changes: 26 additions & 4 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Supervisor struct {
// A config section to be added to the Collector's config to fetch its own metrics.
// TODO: store this persistently so that when starting we can compose the effective
// config correctly.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21078
agentConfigOwnMetricsSection atomic.Value

// agentHealthCheckEndpoint is the endpoint the Collector's health check extension
Expand Down Expand Up @@ -158,6 +159,7 @@ func (s *Supervisor) loadConfig(configFile string) error {
return nil
}

// TODO: Implement bootstrapping https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21071
func (s *Supervisor) getBootstrapInfo() (err error) {
s.agentVersion = "1.0.0"

Expand All @@ -180,10 +182,30 @@ func (s *Supervisor) startOpAMP() error {
OnErrorFunc: func(err *protobufs.ServerErrorResponse) {
s.logger.Error("Server returned an error response", zap.String("message", err.ErrorMessage))
},
OnMessageFunc: s.onMessage,
OnOpampConnectionSettingsFunc: func(ctx context.Context, settings *protobufs.OpAMPConnectionSettings) error {
// TODO: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21043
s.logger.Debug("Received ConnectionSettings request")
return nil
},
OnOpampConnectionSettingsAcceptedFunc: func(settings *protobufs.OpAMPConnectionSettings) {
// TODO: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21043
s.logger.Debug("ConnectionSettings accepted")
},
OnCommandFunc: func(command *protobufs.ServerToAgentCommand) error {
cmdType := command.GetType()
if *cmdType.Enum() == protobufs.CommandType_CommandType_Restart {
// TODO: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21077
s.logger.Debug("Received restart command")
}
return nil
},
SaveRemoteConfigStatusFunc: func(ctx context.Context, status *protobufs.RemoteConfigStatus) {
// TODO: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21079
},
GetEffectiveConfigFunc: func(ctx context.Context) (*protobufs.EffectiveConfig, error) {
return s.createEffectiveConfigMsg(), nil
},
OnMessageFunc: s.onMessage,
},
// TODO: Make capabilities configurable
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig |
Expand Down Expand Up @@ -215,11 +237,10 @@ func (s *Supervisor) startOpAMP() error {
}

func (s *Supervisor) createInstanceID() {
// Generate instance id.
entropy := ulid.Monotonic(rand.New(rand.NewSource(0)), 0)
s.instanceID = ulid.MustNew(ulid.Timestamp(time.Now()), entropy)

// TODO: Persist instance ID.
// TODO: Persist instance ID. https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21073
}

func keyVal(key, val string) *protobufs.KeyValue {
Expand All @@ -234,11 +255,11 @@ func keyVal(key, val string) *protobufs.KeyValue {
func (s *Supervisor) createAgentDescription() *protobufs.AgentDescription {
hostname, _ := os.Hostname()

// Create Agent description.
return &protobufs.AgentDescription{
IdentifyingAttributes: []*protobufs.KeyValue{
keyVal("service.name", agentType),
keyVal("service.version", s.agentVersion),
keyVal("service.instance.id", s.instanceID.String()),
},
NonIdentifyingAttributes: []*protobufs.KeyValue{
keyVal("os.family", runtime.GOOS),
Expand Down Expand Up @@ -546,6 +567,7 @@ func (s *Supervisor) runAgentProcess() {
}

// TODO: decide why the agent stopped. If it was due to bad config, report it to server.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21079

// Wait 5 seconds before starting again.
restartTimer.Stop()
Expand Down