opamp-go icon indicating copy to clipboard operation
opamp-go copied to clipboard

Add support for CustomCapabilities and CustomMessage

Open andykellr opened this issue 1 year ago • 2 comments

Implements the recent additions to the spec described in https://github.com/open-telemetry/opamp-spec/pull/132

Client

CustomCapabilities are added to types.StartSettings and these are sent to the server with ReportFullState or when SetCustomCapabilities is called which will update them. There is currently no separate flag for the server to request them.

SetCustomMessage is added to the OpAMPClient interface and will add the CustomMessage to the next message and schedule a send. It reports ErrCustomCapabilityNotSupported if the Capability in the CustomMessage is not supported. This is to ensure that the client sets CustomCapabilities appropriately.

Server

The server implementation is more basic. CustomCapabilities are added to server.Settings and are sent on the first ServerToAgent message (websocket) or on every response (http). I considered adding a flag to allow the client to request them and to avoid returning them on every http response, but I decided to wait for feedback.

CustomMessage is available on the ServerToAgent message but it is up to the server implementation to set it on the message before returning from OnMessage or when calling Send.

Usage

I am using this implementation on a branch of BindPlane OP and bindplane-agent and it is working well.

andykellr avatar Oct 25 '23 03:10 andykellr

Codecov Report

Attention: Patch coverage is 97.46835% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 74.95%. Comparing base (ce8a8dd) to head (3ba787b). Report is 1 commits behind head on main.

Files Patch % Lines
client/internal/receivedprocessor.go 75.00% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #209      +/-   ##
==========================================
+ Coverage   73.45%   74.95%   +1.49%     
==========================================
  Files          25       25              
  Lines        1537     1625      +88     
==========================================
+ Hits         1129     1218      +89     
+ Misses        298      296       -2     
- Partials      110      111       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Oct 25 '23 03:10 codecov[bot]

I updated the Client SetCustomMessage to return an ErrCustomMessagePending error and a channel that can be used to wait for the message to be sent if there is already a custom message on the AgentToServer message.

	// SetCustomMessage sets the custom message that will be sent to the Server. May be
	// called anytime after Start(), including from OnMessage handler.
	//
	// If the CustomMessage is nil, ErrCustomMessageMissing will be returned. If the message
	// specifies a capability that is not listed in the CustomCapabilities provided in the
	// StartSettings for the client, ErrCustomCapabilityNotSupported will be returned.
	//
	// Only one message can be set at a time. If a message has already been set, it will
	// return ErrCustomMessagePending. To ensure that it is safe to set another
	// CustomMessage, the caller should wait for the channel to be closed before attempting
	// to set another custom message.
	SetCustomMessage(message *protobufs.CustomMessage) (messageSendingChannel chan struct{}, err error)

andykellr avatar Feb 06 '24 15:02 andykellr

SetCustomMessage and the use of channel looks good to me.

tigrannajaryan avatar Feb 14 '24 17:02 tigrannajaryan