Skip to content

Commit

Permalink
Add support for CustomCapabilities and CustomMessage (#209)
Browse files Browse the repository at this point in the history
Implements the recent additions to the spec described in open-telemetry/opamp-spec#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.
  • Loading branch information
andykellr authored Mar 14, 2024
1 parent 7e92da0 commit ba70a24
Show file tree
Hide file tree
Showing 16 changed files with 1,425 additions and 511 deletions.
35 changes: 35 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,39 @@ type OpAMPClient interface {
// May be called before or after Start().
// May be also called from OnMessage handler.
RequestConnectionSettings(request *protobufs.ConnectionSettingsRequest) error

// SetCustomCapabilities modifies the set of customCapabilities supported by the client.
// The new customCapabilities will be sent with the next message to the server. If
// custom capabilities are used SHOULD be called before Start(). If not called before
// Start(), the set of supported custom capabilities will be empty. May also be called
// anytime after Start(), including from OnMessage handler, to modify the set of
// supported custom capabilities. nil values are not allowed and will return an error.
//
// Each capability is a reverse FQDN with optional version information that uniquely
// identifies the custom capability and should match a capability specified in a
// supported CustomMessage. The client will automatically ignore any CustomMessage that
// contains a custom capability that is not specified in this field.
//
// See
// https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#customcapabilities
// for more details.
SetCustomCapabilities(customCapabilities *protobufs.CustomCapabilities) error

// SendCustomMessage sends the custom message 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 sent at a time. If SendCustomMessage has been already called
// and the message is still pending (in progress) then subsequent calls to
// SendCustomMessage will return ErrCustomMessagePending and a channel that will be
// closed when the pending message is sent. To ensure that the previous send is complete
// and it is safe to send another CustomMessage, the caller should wait for the returned
// channel to be closed before attempting to send another custom message.
//
// 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)
}
Loading

0 comments on commit ba70a24

Please sign in to comment.