diff --git a/cmd/opampsupervisor/e2e_test.go b/cmd/opampsupervisor/e2e_test.go index 96935b4bd0d0..b4f80e9624c8 100644 --- a/cmd/opampsupervisor/e2e_test.go +++ b/cmd/opampsupervisor/e2e_test.go @@ -64,7 +64,7 @@ func (tl testLogger) Errorf(_ context.Context, format string, args ...any) { tl.t.Logf(format, args...) } -func defaultConnectingHandler(connectionCallbacks server.ConnectionCallbacksStruct) func(request *http.Request) types.ConnectionResponse { +func defaultConnectingHandler(connectionCallbacks types.ConnectionCallbacks) func(request *http.Request) types.ConnectionResponse { return func(_ *http.Request) types.ConnectionResponse { return types.ConnectionResponse{ Accept: true, @@ -73,11 +73,11 @@ func defaultConnectingHandler(connectionCallbacks server.ConnectionCallbacksStru } } -// onConnectingFuncFactory is a function that will be given to server.CallbacksStruct as +// onConnectingFuncFactory is a function that will be given to types.ConnectionCallbacks as // OnConnectingFunc. This allows changing the ConnectionCallbacks both from the newOpAMPServer // caller and inside of newOpAMP Server, and for custom implementations of the value for `Accept` // in types.ConnectionResponse. -type onConnectingFuncFactory func(connectionCallbacks server.ConnectionCallbacksStruct) func(request *http.Request) types.ConnectionResponse +type onConnectingFuncFactory func(connectionCallbacks types.ConnectionCallbacks) func(request *http.Request) types.ConnectionResponse type testingOpAMPServer struct { addr string @@ -87,20 +87,20 @@ type testingOpAMPServer struct { shutdown func() } -func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, callbacks server.ConnectionCallbacksStruct) *testingOpAMPServer { +func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, callbacks types.ConnectionCallbacks) *testingOpAMPServer { s := newUnstartedOpAMPServer(t, connectingCallback, callbacks) s.start() return s } -func newUnstartedOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, callbacks server.ConnectionCallbacksStruct) *testingOpAMPServer { +func newUnstartedOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, callbacks types.ConnectionCallbacks) *testingOpAMPServer { var agentConn atomic.Value var isAgentConnected atomic.Bool var didShutdown atomic.Bool connectedChan := make(chan bool) s := server.New(testLogger{t: t}) - onConnectedFunc := callbacks.OnConnectedFunc - callbacks.OnConnectedFunc = func(ctx context.Context, conn types.Connection) { + onConnectedFunc := callbacks.OnConnected + callbacks.OnConnected = func(ctx context.Context, conn types.Connection) { if onConnectedFunc != nil { onConnectedFunc(ctx, conn) } @@ -108,8 +108,8 @@ func newUnstartedOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFa isAgentConnected.Store(true) connectedChan <- true } - onConnectionCloseFunc := callbacks.OnConnectionCloseFunc - callbacks.OnConnectionCloseFunc = func(conn types.Connection) { + onConnectionCloseFunc := callbacks.OnConnectionClose + callbacks.OnConnectionClose = func(conn types.Connection) { isAgentConnected.Store(false) connectedChan <- false if onConnectionCloseFunc != nil { @@ -117,8 +117,8 @@ func newUnstartedOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFa } } handler, _, err := s.Attach(server.Settings{ - Callbacks: server.CallbacksStruct{ - OnConnectingFunc: connectingCallback(callbacks), + Callbacks: types.Callbacks{ + OnConnecting: connectingCallback(callbacks), }, }) require.NoError(t, err) @@ -211,8 +211,8 @@ func TestSupervisorStartsCollectorWithRemoteConfig(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -287,8 +287,8 @@ func TestSupervisorStartsCollectorWithNoOpAMPServer(t *testing.T) { require.NoError(t, os.WriteFile(remoteConfigFilePath, marshalledRemoteConfig, 0o600)) connected := atomic.Bool{} - server := newUnstartedOpAMPServer(t, defaultConnectingHandler, server.ConnectionCallbacksStruct{ - OnConnectedFunc: func(ctx context.Context, conn types.Connection) { + server := newUnstartedOpAMPServer(t, defaultConnectingHandler, types.ConnectionCallbacks{ + OnConnected: func(ctx context.Context, conn types.Connection) { connected.Store(true) }, }) @@ -331,19 +331,20 @@ func TestSupervisorStartsWithNoOpAMPServer(t *testing.T) { configuredChan := make(chan struct{}) connected := atomic.Bool{} - server := newUnstartedOpAMPServer(t, defaultConnectingHandler, server.ConnectionCallbacksStruct{ - OnConnectedFunc: func(ctx context.Context, conn types.Connection) { - connected.Store(true) - }, - OnMessageFunc: func(ctx context.Context, conn types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { - lastCfgHash := message.GetRemoteConfigStatus().GetLastRemoteConfigHash() - if bytes.Equal(lastCfgHash, hash) { - close(configuredChan) - } + server := newUnstartedOpAMPServer(t, defaultConnectingHandler, + types.ConnectionCallbacks{ + OnConnected: func(ctx context.Context, conn types.Connection) { + connected.Store(true) + }, + OnMessage: func(ctx context.Context, conn types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + lastCfgHash := message.GetRemoteConfigStatus().GetLastRemoteConfigHash() + if bytes.Equal(lastCfgHash, hash) { + close(configuredChan) + } - return &protobufs.ServerToAgent{} - }, - }) + return &protobufs.ServerToAgent{} + }, + }) defer server.shutdown() // The supervisor is started without a running OpAMP server. @@ -415,8 +416,8 @@ func TestSupervisorRestartsCollectorAfterBadConfig(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.Health != nil { healthReport.Store(message.Health) } @@ -501,8 +502,8 @@ func TestSupervisorConfiguresCapabilities(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { capabilities.Store(message.Capabilities) return &protobufs.ServerToAgent{} @@ -556,8 +557,8 @@ func TestSupervisorBootstrapsCollector(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.AgentDescription != nil { agentDescription.Store(message.AgentDescription) } @@ -602,8 +603,8 @@ func TestSupervisorReportsEffectiveConfig(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -713,8 +714,8 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.AgentDescription != nil { select { case agentDescMessageChan <- message: @@ -866,8 +867,8 @@ func TestSupervisorRestartCommand(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.Health != nil { healthReport.Store(message.Health) } @@ -948,7 +949,7 @@ func TestSupervisorOpAMPConnectionSettings(t *testing.T) { initialServer := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{}) + types.ConnectionCallbacks{}) s := newSupervisor(t, "accepts_conn", map[string]string{"url": initialServer.addr}) @@ -960,11 +961,11 @@ func TestSupervisorOpAMPConnectionSettings(t *testing.T) { newServer := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnConnectedFunc: func(_ context.Context, _ types.Connection) { + types.ConnectionCallbacks{ + OnConnected: func(_ context.Context, _ types.Connection) { connectedToNewServer.Store(true) }, - OnMessageFunc: func(_ context.Context, _ types.Connection, _ *protobufs.AgentToServer) *protobufs.ServerToAgent { + OnMessage: func(_ context.Context, _ types.Connection, _ *protobufs.AgentToServer) *protobufs.ServerToAgent { return &protobufs.ServerToAgent{} }, }) @@ -999,8 +1000,8 @@ func TestSupervisorRestartsWithLastReceivedConfig(t *testing.T) { initialServer := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -1043,8 +1044,8 @@ func TestSupervisorRestartsWithLastReceivedConfig(t *testing.T) { newServer := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -1087,8 +1088,8 @@ func TestSupervisorPersistsInstanceID(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { select { case agentIDChan <- message.InstanceUid: default: @@ -1163,8 +1164,8 @@ func TestSupervisorPersistsNewInstanceID(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { select { case agentIDChan <- message.InstanceUid: default: @@ -1242,7 +1243,7 @@ func TestSupervisorWritesAgentFilesToStorageDir(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{}, + types.ConnectionCallbacks{}, ) s := newSupervisor(t, "basic", map[string]string{ @@ -1270,8 +1271,8 @@ func TestSupervisorStopsAgentProcessWithEmptyConfigMap(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -1386,8 +1387,8 @@ func TestSupervisorLogging(t *testing.T) { require.NoError(t, os.WriteFile(remoteCfgFilePath, marshalledRemoteCfg, 0o600)) connected := atomic.Bool{} - server := newUnstartedOpAMPServer(t, defaultConnectingHandler, server.ConnectionCallbacksStruct{ - OnConnectedFunc: func(ctx context.Context, conn types.Connection) { + server := newUnstartedOpAMPServer(t, defaultConnectingHandler, types.ConnectionCallbacks{ + OnConnected: func(ctx context.Context, conn types.Connection) { connected.Store(true) }, }) @@ -1449,8 +1450,8 @@ func TestSupervisorRemoteConfigApplyStatus(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { @@ -1586,8 +1587,8 @@ func TestSupervisorOpAmpServerPort(t *testing.T) { server := newOpAMPServer( t, defaultConnectingHandler, - server.ConnectionCallbacksStruct{ - OnMessageFunc: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { + types.ConnectionCallbacks{ + OnMessage: func(_ context.Context, _ types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { if message.EffectiveConfig != nil { config := message.EffectiveConfig.ConfigMap.ConfigMap[""] if config != nil { diff --git a/cmd/opampsupervisor/go.mod b/cmd/opampsupervisor/go.mod index f81caa637fb0..01f95769086e 100644 --- a/cmd/opampsupervisor/go.mod +++ b/cmd/opampsupervisor/go.mod @@ -10,7 +10,7 @@ require ( github.com/knadh/koanf/providers/file v1.1.2 github.com/knadh/koanf/providers/rawbytes v0.1.0 github.com/knadh/koanf/v2 v2.1.2 - github.com/open-telemetry/opamp-go v0.17.0 + github.com/open-telemetry/opamp-go v0.18.0 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/collector/config/configopaque v1.23.0 go.opentelemetry.io/collector/config/configtls v1.23.0 @@ -29,7 +29,6 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect - github.com/google/go-cmp v0.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/knadh/koanf/providers/confmap v0.1.0 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect diff --git a/cmd/opampsupervisor/go.sum b/cmd/opampsupervisor/go.sum index 11ed3daec6fe..df86d5e3bebd 100644 --- a/cmd/opampsupervisor/go.sum +++ b/cmd/opampsupervisor/go.sum @@ -32,12 +32,14 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/open-telemetry/opamp-go v0.17.0 h1:3R4+B/6Sy8mknLBbzO3gqloqwTT02rCSRcr4ac2B124= -github.com/open-telemetry/opamp-go v0.17.0/go.mod h1:SGDhUoAx7uGutO4ENNMQla/tiSujxgZmMPJXIOPGBdk= +github.com/open-telemetry/opamp-go v0.18.0 h1:sNHsrBvGU2CMxCB1TRJXncDARrmxDEebx8dsEIawqA4= +github.com/open-telemetry/opamp-go v0.18.0/go.mod h1:9/1G6T5dnJz4cJtoYSr6AX18kHdOxnxxETJPZSHyEUg= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.opentelemetry.io/collector/config/configopaque v1.23.0 h1:SEnEzOHufGc4KGOjQq8zKIQuDBmRFl9ncZ3qs1SRpJk= diff --git a/cmd/opampsupervisor/supervisor/server.go b/cmd/opampsupervisor/supervisor/server.go index cd54f96336eb..4ecfd9afa617 100644 --- a/cmd/opampsupervisor/supervisor/server.go +++ b/cmd/opampsupervisor/supervisor/server.go @@ -13,24 +13,26 @@ import ( ) type flattenedSettings struct { - onMessageFunc func(conn serverTypes.Connection, message *protobufs.AgentToServer) - onConnectingFunc func(request *http.Request) (shouldConnect bool, rejectStatusCode int) - onConnectionCloseFunc func(conn serverTypes.Connection) - endpoint string + onMessage func(conn serverTypes.Connection, message *protobufs.AgentToServer) + onConnecting func(request *http.Request) (shouldConnect bool, rejectStatusCode int) + onConnectionClose func(conn serverTypes.Connection) + endpoint string } func (fs flattenedSettings) toServerSettings() server.StartSettings { return server.StartSettings{ Settings: server.Settings{ - Callbacks: fs, + Callbacks: serverTypes.Callbacks{ + OnConnecting: fs.OnConnecting, + }, }, ListenEndpoint: fs.endpoint, } } func (fs flattenedSettings) OnConnecting(request *http.Request) serverTypes.ConnectionResponse { - if fs.onConnectingFunc != nil { - shouldConnect, rejectStatusCode := fs.onConnectingFunc(request) + if fs.onConnecting != nil { + shouldConnect, rejectStatusCode := fs.onConnecting(request) if !shouldConnect { return serverTypes.ConnectionResponse{ Accept: false, @@ -40,23 +42,25 @@ func (fs flattenedSettings) OnConnecting(request *http.Request) serverTypes.Conn } return serverTypes.ConnectionResponse{ - Accept: true, - ConnectionCallbacks: fs, + Accept: true, + ConnectionCallbacks: serverTypes.ConnectionCallbacks{ + OnMessage: fs.OnMessage, + }, } } func (fs flattenedSettings) OnConnected(_ context.Context, _ serverTypes.Connection) {} func (fs flattenedSettings) OnMessage(_ context.Context, conn serverTypes.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent { - if fs.onMessageFunc != nil { - fs.onMessageFunc(conn, message) + if fs.onMessage != nil { + fs.onMessage(conn, message) } return &protobufs.ServerToAgent{} } func (fs flattenedSettings) OnConnectionClose(conn serverTypes.Connection) { - if fs.onConnectionCloseFunc != nil { - fs.onConnectionCloseFunc(conn) + if fs.onConnectionClose != nil { + fs.onConnectionClose(conn) } } diff --git a/cmd/opampsupervisor/supervisor/server_test.go b/cmd/opampsupervisor/supervisor/server_test.go index e35c11ab186e..e4272270300a 100644 --- a/cmd/opampsupervisor/supervisor/server_test.go +++ b/cmd/opampsupervisor/supervisor/server_test.go @@ -28,7 +28,7 @@ func Test_flattenedSettings_OnConnecting(t *testing.T) { t.Run("accept connection", func(t *testing.T) { onConnectingFuncCalled := false fs := flattenedSettings{ - onConnectingFunc: func(_ *http.Request) (shouldConnect bool, rejectStatusCode int) { + onConnecting: func(_ *http.Request) (shouldConnect bool, rejectStatusCode int) { onConnectingFuncCalled = true return true, 0 }, @@ -43,7 +43,7 @@ func Test_flattenedSettings_OnConnecting(t *testing.T) { t.Run("do not accept connection", func(t *testing.T) { onConnectingFuncCalled := false fs := flattenedSettings{ - onConnectingFunc: func(_ *http.Request) (shouldConnect bool, rejectStatusCode int) { + onConnecting: func(_ *http.Request) (shouldConnect bool, rejectStatusCode int) { onConnectingFuncCalled = true return false, 500 }, @@ -60,7 +60,7 @@ func Test_flattenedSettings_OnConnecting(t *testing.T) { func Test_flattenedSettings_OnMessage(t *testing.T) { onMessageFuncCalled := false fs := flattenedSettings{ - onMessageFunc: func(_ serverTypes.Connection, _ *protobufs.AgentToServer) { + onMessage: func(_ serverTypes.Connection, _ *protobufs.AgentToServer) { onMessageFuncCalled = true }, } @@ -74,7 +74,7 @@ func Test_flattenedSettings_OnMessage(t *testing.T) { func Test_flattenedSettings_OnConnectionClose(t *testing.T) { onConnectionCloseFuncCalled := false fs := flattenedSettings{ - onConnectionCloseFunc: func(_ serverTypes.Connection) { + onConnectionClose: func(_ serverTypes.Connection) { onConnectionCloseFuncCalled = true }, } diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 4607aa6d5958..894854273c6a 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -305,11 +305,11 @@ func (s *Supervisor) getBootstrapInfo() (err error) { // using the Collector's OpAMP extension. err = srv.Start(flattenedSettings{ endpoint: fmt.Sprintf("localhost:%d", s.opampServerPort), - onConnectingFunc: func(_ *http.Request) (bool, int) { + onConnecting: func(_ *http.Request) (bool, int) { connected.Store(true) return true, http.StatusOK }, - onMessageFunc: func(_ serverTypes.Connection, message *protobufs.AgentToServer) { + onMessage: func(_ serverTypes.Connection, message *protobufs.AgentToServer) { if message.AgentDescription != nil { instanceIDSeen := false s.setAgentDescription(message.AgentDescription) @@ -415,33 +415,33 @@ func (s *Supervisor) startOpAMPClient() error { Header: s.config.Server.Headers, TLSConfig: tlsConfig, InstanceUid: types.InstanceUid(s.persistentState.InstanceID), - Callbacks: types.CallbacksStruct{ - OnConnectFunc: func(_ context.Context) { + Callbacks: types.Callbacks{ + OnConnect: func(_ context.Context) { s.logger.Debug("Connected to the server.") }, - OnConnectFailedFunc: func(_ context.Context, err error) { + OnConnectFailed: func(_ context.Context, err error) { s.logger.Error("Failed to connect to the server", zap.Error(err)) }, - OnErrorFunc: func(_ context.Context, err *protobufs.ServerErrorResponse) { + OnError: func(_ context.Context, 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 { + OnMessage: s.onMessage, + OnOpampConnectionSettings: func(ctx context.Context, settings *protobufs.OpAMPConnectionSettings) error { //nolint:errcheck go s.onOpampConnectionSettings(ctx, settings) return nil }, - OnCommandFunc: func(_ context.Context, command *protobufs.ServerToAgentCommand) error { + OnCommand: func(_ context.Context, command *protobufs.ServerToAgentCommand) error { cmdType := command.GetType() if *cmdType.Enum() == protobufs.CommandType_CommandType_Restart { return s.handleRestartCommand() } return nil }, - SaveRemoteConfigStatusFunc: func(_ context.Context, _ *protobufs.RemoteConfigStatus) { + SaveRemoteConfigStatus: func(_ context.Context, _ *protobufs.RemoteConfigStatus) { // TODO: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21079 }, - GetEffectiveConfigFunc: func(_ context.Context) (*protobufs.EffectiveConfig, error) { + GetEffectiveConfig: func(_ context.Context) (*protobufs.EffectiveConfig, error) { return s.createEffectiveConfigMsg(), nil }, }, @@ -486,13 +486,13 @@ func (s *Supervisor) startOpAMPServer() error { err = s.opampServer.Start(flattenedSettings{ endpoint: fmt.Sprintf("localhost:%d", s.opampServerPort), - onConnectingFunc: func(_ *http.Request) (bool, int) { + onConnecting: func(_ *http.Request) (bool, int) { // Only allow one agent to be connected the this server at a time. alreadyConnected := connected.Swap(true) return !alreadyConnected, http.StatusConflict }, - onMessageFunc: s.handleAgentOpAMPMessage, - onConnectionCloseFunc: func(_ serverTypes.Connection) { + onMessage: s.handleAgentOpAMPMessage, + onConnectionClose: func(_ serverTypes.Connection) { connected.Store(false) }, }.toServerSettings()) diff --git a/extension/opampcustommessages/go.mod b/extension/opampcustommessages/go.mod index ae570bbaf804..061532dd4151 100644 --- a/extension/opampcustommessages/go.mod +++ b/extension/opampcustommessages/go.mod @@ -2,6 +2,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/extension/opamp go 1.22.0 -require github.com/open-telemetry/opamp-go v0.17.0 +require github.com/open-telemetry/opamp-go v0.18.0 -require google.golang.org/protobuf v1.34.2 // indirect +require google.golang.org/protobuf v1.36.2 // indirect diff --git a/extension/opampcustommessages/go.sum b/extension/opampcustommessages/go.sum index 856df9d69ae9..f4989ff2145b 100644 --- a/extension/opampcustommessages/go.sum +++ b/extension/opampcustommessages/go.sum @@ -1,8 +1,6 @@ -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/open-telemetry/opamp-go v0.17.0 h1:3R4+B/6Sy8mknLBbzO3gqloqwTT02rCSRcr4ac2B124= -github.com/open-telemetry/opamp-go v0.17.0/go.mod h1:SGDhUoAx7uGutO4ENNMQla/tiSujxgZmMPJXIOPGBdk= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/open-telemetry/opamp-go v0.18.0 h1:sNHsrBvGU2CMxCB1TRJXncDARrmxDEebx8dsEIawqA4= +github.com/open-telemetry/opamp-go v0.18.0/go.mod h1:9/1G6T5dnJz4cJtoYSr6AX18kHdOxnxxETJPZSHyEUg= +google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= +google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= diff --git a/extension/opampextension/go.mod b/extension/opampextension/go.mod index 60dfa59f529c..4e3dc9bcba93 100644 --- a/extension/opampextension/go.mod +++ b/extension/opampextension/go.mod @@ -5,7 +5,7 @@ go 1.22.0 require ( github.com/google/uuid v1.6.0 github.com/oklog/ulid/v2 v2.1.0 - github.com/open-telemetry/opamp-go v0.17.0 + github.com/open-telemetry/opamp-go v0.18.0 github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages v0.117.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status v0.117.0 github.com/shirou/gopsutil/v4 v4.24.12 diff --git a/extension/opampextension/go.sum b/extension/opampextension/go.sum index c5f0f975dfb9..ef065ce48345 100644 --- a/extension/opampextension/go.sum +++ b/extension/opampextension/go.sum @@ -46,8 +46,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU= github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ= -github.com/open-telemetry/opamp-go v0.17.0 h1:3R4+B/6Sy8mknLBbzO3gqloqwTT02rCSRcr4ac2B124= -github.com/open-telemetry/opamp-go v0.17.0/go.mod h1:SGDhUoAx7uGutO4ENNMQla/tiSujxgZmMPJXIOPGBdk= +github.com/open-telemetry/opamp-go v0.18.0 h1:sNHsrBvGU2CMxCB1TRJXncDARrmxDEebx8dsEIawqA4= +github.com/open-telemetry/opamp-go v0.18.0/go.mod h1:9/1G6T5dnJz4cJtoYSr6AX18kHdOxnxxETJPZSHyEUg= github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -57,6 +57,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/shirou/gopsutil/v4 v4.24.12 h1:qvePBOk20e0IKA1QXrIIU+jmk+zEiYVVx06WjBRlZo4= github.com/shirou/gopsutil/v4 v4.24.12/go.mod h1:DCtMPAad2XceTeIAbGyVfycbYQNBGk2P8cvDi7/VN9o= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index 3e26d407fd80..cca5f762ebe3 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -118,20 +118,20 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { TLSConfig: tls, OpAMPServerURL: o.cfg.Server.GetEndpoint(), InstanceUid: types.InstanceUid(o.instanceID), - Callbacks: types.CallbacksStruct{ - OnConnectFunc: func(_ context.Context) { + Callbacks: types.Callbacks{ + OnConnect: func(_ context.Context) { o.logger.Debug("Connected to the OpAMP server") }, - OnConnectFailedFunc: func(_ context.Context, err error) { + OnConnectFailed: func(_ context.Context, err error) { o.logger.Error("Failed to connect to the OpAMP server", zap.Error(err)) }, - OnErrorFunc: func(_ context.Context, err *protobufs.ServerErrorResponse) { + OnError: func(_ context.Context, err *protobufs.ServerErrorResponse) { o.logger.Error("OpAMP server returned an error response", zap.String("message", err.ErrorMessage)) }, - GetEffectiveConfigFunc: func(_ context.Context) (*protobufs.EffectiveConfig, error) { + GetEffectiveConfig: func(_ context.Context) (*protobufs.EffectiveConfig, error) { return o.composeEffectiveConfig(), nil }, - OnMessageFunc: o.onMessage, + OnMessage: o.onMessage, }, Capabilities: o.capabilities.toAgentCapabilities(), } diff --git a/receiver/awss3receiver/go.mod b/receiver/awss3receiver/go.mod index fc101b5607cc..91d9e27f21df 100644 --- a/receiver/awss3receiver/go.mod +++ b/receiver/awss3receiver/go.mod @@ -7,7 +7,7 @@ require ( github.com/aws/aws-sdk-go-v2/config v1.28.7 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.45 github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0 - github.com/open-telemetry/opamp-go v0.17.0 + github.com/open-telemetry/opamp-go v0.18.0 github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages v0.117.0 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/collector/component v0.117.0 diff --git a/receiver/awss3receiver/go.sum b/receiver/awss3receiver/go.sum index f27b906fe21f..ff44222ee522 100644 --- a/receiver/awss3receiver/go.sum +++ b/receiver/awss3receiver/go.sum @@ -79,8 +79,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/open-telemetry/opamp-go v0.17.0 h1:3R4+B/6Sy8mknLBbzO3gqloqwTT02rCSRcr4ac2B124= -github.com/open-telemetry/opamp-go v0.17.0/go.mod h1:SGDhUoAx7uGutO4ENNMQla/tiSujxgZmMPJXIOPGBdk= +github.com/open-telemetry/opamp-go v0.18.0 h1:sNHsrBvGU2CMxCB1TRJXncDARrmxDEebx8dsEIawqA4= +github.com/open-telemetry/opamp-go v0.18.0/go.mod h1:9/1G6T5dnJz4cJtoYSr6AX18kHdOxnxxETJPZSHyEUg= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=