diff --git a/client/client.go b/client/client.go index c3d2ca3..afc0831 100644 --- a/client/client.go +++ b/client/client.go @@ -134,18 +134,4 @@ type OpAMPClient interface { // If no error is returned, the channel returned will be closed after the specified // message is sent. SendCustomMessage(message *protobufs.CustomMessage) (messageSendingChannel chan struct{}, err error) - - // SetAvailableComponents modifies the set of components that are available for configuration - // on the agent. - // May be called any time after Start(), including from the OnMessage handler. - // The new components will be sent with the next message to the server. - // - // If components is nil, types.ErrAvailableComponentsMissing will be returned. - // If components.Hash is nil or an empty []byte, types.ErrNoAvailableComponentHash will be returned. - // If the ReportsAvailableComponents capability is not set in StartSettings.Capabilities during Start(), - // types.ErrReportsAvailableComponentsNotSet will be returned. - // - // This method is subject to agent status compression - if components is not - // different from the cached agent state, this method is a no-op. - SetAvailableComponents(components *protobufs.AvailableComponents) error } diff --git a/client/clientimpl_test.go b/client/clientimpl_test.go index bf2ce7b..2bab9b5 100644 --- a/client/clientimpl_test.go +++ b/client/clientimpl_test.go @@ -2306,109 +2306,6 @@ func TestSetFlagsBeforeStart(t *testing.T) { }) } -func TestSetAvailableComponents(t *testing.T) { - testCases := []struct { - desc string - capabilities protobufs.AgentCapabilities - testFunc func(t *testing.T, client OpAMPClient, srv *internal.MockServer) - }{ - { - desc: "apply nil AvailableComponents", - capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents, - testFunc: func(t *testing.T, client OpAMPClient, _ *internal.MockServer) { - require.ErrorIs(t, client.SetAvailableComponents(nil), types.ErrAvailableComponentsMissing) - }, - }, - { - desc: "apply AvailableComponents with empty hash", - capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents, - testFunc: func(t *testing.T, client OpAMPClient, _ *internal.MockServer) { - require.ErrorIs(t, client.SetAvailableComponents(&protobufs.AvailableComponents{}), types.ErrNoAvailableComponentHash) - }, - }, - { - desc: "apply AvailableComponents without required capability", - testFunc: func(t *testing.T, client OpAMPClient, _ *internal.MockServer) { - require.ErrorIs(t, client.SetAvailableComponents(generateTestAvailableComponents()), types.ErrReportsAvailableComponentsNotSet) - }, - }, - { - desc: "apply AvailableComponents with cached AvailableComponents", - capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents, - testFunc: func(t *testing.T, client OpAMPClient, _ *internal.MockServer) { - require.NoError(t, client.SetAvailableComponents(generateTestAvailableComponents())) - }, - }, - { - desc: "apply AvailableComponents with new AvailableComponents", - capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents, - testFunc: func(t *testing.T, client OpAMPClient, srv *internal.MockServer) { - availableComponents := generateTestAvailableComponents() - availableComponents.Hash = []byte("different") - require.NoError(t, client.SetAvailableComponents(availableComponents)) - srv.Expect(func(msg *protobufs.AgentToServer) *protobufs.ServerToAgent { - assert.EqualValues(t, 1, msg.SequenceNum) - msgAvailableComponents := msg.GetAvailableComponents() - require.NotNil(t, msgAvailableComponents) - require.Equal(t, msgAvailableComponents.GetHash(), availableComponents.GetHash()) - require.Nil(t, msgAvailableComponents.GetComponents()) - return nil - }) - }, - }, - } - - for _, tc := range testCases { - t.Run(tc.desc, func(t *testing.T) { - testClients(t, func(t *testing.T, client OpAMPClient) { - - // Start a Server. - srv := internal.StartMockServer(t) - srv.EnableExpectMode() - - availableComponents := generateTestAvailableComponents() - - // Start a client. - settings := types.StartSettings{ - OpAMPServerURL: "ws://" + srv.Endpoint, - Callbacks: types.Callbacks{ - OnMessage: func(ctx context.Context, msg *types.MessageData) {}, - }, - Capabilities: tc.capabilities, - AvailableComponents: availableComponents, - } - prepareClient(t, &settings, client) - - // Client ---> - assert.NoError(t, client.Start(context.Background(), settings)) - - // ---> Server - srv.Expect(func(msg *protobufs.AgentToServer) *protobufs.ServerToAgent { - assert.EqualValues(t, 0, msg.SequenceNum) - msgAvailableComponents := msg.GetAvailableComponents() - if tc.capabilities&protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents != 0 { - require.NotNil(t, msgAvailableComponents) - require.Equal(t, msgAvailableComponents.GetHash(), availableComponents.GetHash()) - require.Nil(t, msgAvailableComponents.GetComponents()) - } else { - require.Nil(t, msgAvailableComponents) - } - return nil - }) - - tc.testFunc(t, client, srv) - - // Shutdown the Server. - srv.Close() - - // Shutdown the client. - err := client.Stop(context.Background()) - assert.NoError(t, err) - }) - }) - } -} - func generateTestAvailableComponents() *protobufs.AvailableComponents { return &protobufs.AvailableComponents{ Hash: []byte("fake-hash"), diff --git a/client/httpclient.go b/client/httpclient.go index 8d32797..92259d5 100644 --- a/client/httpclient.go +++ b/client/httpclient.go @@ -120,11 +120,6 @@ func (c *httpClient) SendCustomMessage(message *protobufs.CustomMessage) (messag return c.common.SendCustomMessage(message) } -// SetAvailableComponents implements OpAMPClient.SetAvailableComponents -func (c *httpClient) SetAvailableComponents(components *protobufs.AvailableComponents) error { - return c.common.SetAvailableComponents(components) -} - func (c *httpClient) runUntilStopped(ctx context.Context) { // Start the HTTP sender. This will make request/responses with retries for // failures and will wait with configured polling interval if there is nothing diff --git a/client/internal/clientcommon.go b/client/internal/clientcommon.go index 2a2e914..1fd2b96 100644 --- a/client/internal/clientcommon.go +++ b/client/internal/clientcommon.go @@ -454,43 +454,3 @@ func (c *ClientCommon) SendCustomMessage(message *protobufs.CustomMessage) (mess return sendingChan, nil } - -// SetAvailableComponents sends a message to the server with the available components for the agent -func (c *ClientCommon) SetAvailableComponents(components *protobufs.AvailableComponents) error { - if c.Capabilities&protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents == 0 { - return types.ErrReportsAvailableComponentsNotSet - } - - if components == nil { - return types.ErrAvailableComponentsMissing - } - - if len(components.Hash) == 0 { - return types.ErrNoAvailableComponentHash - } - - // implement agent status compression, don't send the message if it hasn't changed from the previous message - availableComponentsChanged := !proto.Equal(c.ClientSyncedState.AvailableComponents(), components) - - if availableComponentsChanged { - if err := c.ClientSyncedState.SetAvailableComponents(components); err != nil { - return err - } - - // initially, do not send the full component state - just send the hash. - // full state is available on request from the server using the corresponding ServerToAgent flag - availableComponents := &protobufs.AvailableComponents{ - Hash: c.ClientSyncedState.AvailableComponents().GetHash(), - } - - c.sender.NextMessage().Update( - func(msg *protobufs.AgentToServer) { - msg.AvailableComponents = availableComponents - }, - ) - - c.sender.ScheduleSend() - } - - return nil -} diff --git a/client/internal/receivedprocessor.go b/client/internal/receivedprocessor.go index 7a5474c..55f2ee5 100644 --- a/client/internal/receivedprocessor.go +++ b/client/internal/receivedprocessor.go @@ -75,9 +75,7 @@ func (r *receivedProcessor) ProcessReceivedMessage(ctx context.Context, msg *pro r.logger.Errorf(ctx, "cannot processed received flags:%v", err) } - msgData := &types.MessageData{ - Flags: protobufs.ServerToAgentFlags(msg.Flags), - } + msgData := &types.MessageData{} if msg.RemoteConfig != nil { if r.hasCapability(protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig) { diff --git a/client/types/callbacks.go b/client/types/callbacks.go index 0b1a9a2..48d5f83 100644 --- a/client/types/callbacks.go +++ b/client/types/callbacks.go @@ -45,9 +45,6 @@ type MessageData struct { // CustomMessage contains a custom message sent by the server. CustomMessage *protobufs.CustomMessage - - // Flags contains any flags sent by the server. - Flags protobufs.ServerToAgentFlags } // Callbacks contains functions that are executed when the client encounters diff --git a/client/types/errors.go b/client/types/errors.go index a1d1389..aab6692 100644 --- a/client/types/errors.go +++ b/client/types/errors.go @@ -13,13 +13,4 @@ var ( // ErrCustomMessagePending is returned by SendCustomMessage when called before the previous // message has been sent. ErrCustomMessagePending = errors.New("custom message already set") - - // ErrReportsAvailableComponentsNotSet is returned by SetAvailableComponents without the ReportsAvailableComponents capability set - ErrReportsAvailableComponentsNotSet = errors.New("ReportsAvailableComponents capability is not set") - - // ErrAvailableComponentsMissing is returned by SetAvailableComponents when called with a nil message - ErrAvailableComponentsMissing = errors.New("AvailableComponents is nil") - - // ErrNoAvailableComponentHash is returned by SetAvailableComponents when called with a message with an empty hash - ErrNoAvailableComponentHash = errors.New("AvailableComponents.Hash is empty") ) diff --git a/client/wsclient.go b/client/wsclient.go index fdacdd4..f19d8ab 100644 --- a/client/wsclient.go +++ b/client/wsclient.go @@ -157,11 +157,6 @@ func (c *wsClient) SendCustomMessage(message *protobufs.CustomMessage) (messageS return c.common.SendCustomMessage(message) } -// SetAvailableComponents implements OpAMPClient.SetAvailableComponents -func (c *wsClient) SetAvailableComponents(components *protobufs.AvailableComponents) error { - return c.common.SetAvailableComponents(components) -} - func viaReq(resps []*http.Response) []*http.Request { reqs := make([]*http.Request, 0, len(resps)) for _, resp := range resps {