Skip to content

Commit

Permalink
AgentIdentification protobuf and callback
Browse files Browse the repository at this point in the history
Implements OpAMP Spec change open-telemetry/opamp-spec#63
  • Loading branch information
pmm-sumo committed Mar 22, 2022
1 parent 3c62aca commit b8939fd
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 443 deletions.
11 changes: 11 additions & 0 deletions client/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type CallbacksStruct struct {

OnAddonsAvailableFunc func(ctx context.Context, addons *protobufs.AddonsAvailable, syncer types.AddonSyncer) error
OnAgentPackageAvailableFunc func(addons *protobufs.AgentPackageAvailable, syncer types.AgentPackageSyncer) error
OnAgentIdentificationFunc func(ctx context.Context, agentId *protobufs.AgentIdentification) error
}

var _ types.Callbacks = (*CallbacksStruct)(nil)
Expand Down Expand Up @@ -124,3 +125,13 @@ func (c CallbacksStruct) OnAgentPackageAvailable(
}
return nil
}

func (c CallbacksStruct) OnAgentIdentification(
ctx context.Context,
agentId *protobufs.AgentIdentification,
) error {
if c.OnAgentIdentificationFunc != nil {
return c.OnAgentIdentificationFunc(ctx, agentId)
}
return nil
}
12 changes: 12 additions & 0 deletions client/internal/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (r *Receiver) processReceivedMessage(ctx context.Context, msg *protobufs.Se

r.rcvConnectionSettings(ctx, msg.ConnectionSettings)
r.rcvAddonsAvailable(msg.AddonsAvailable)
r.rcvAgentIdentification(ctx, msg.AgentIdentification)

if reportStatus {
r.sender.ScheduleSend()
Expand Down Expand Up @@ -168,3 +169,14 @@ func (r *Receiver) processErrorResponse(body *protobufs.ServerErrorResponse) {
func (r *Receiver) rcvAddonsAvailable(addons *protobufs.AddonsAvailable) {
// TODO: implement this.
}

func (r *Receiver) rcvAgentIdentification(ctx context.Context, agentId *protobufs.AgentIdentification) {
if agentId == nil {
return
}

err := r.callbacks.OnAgentIdentification(ctx, agentId)
if err != nil {
// TODO: minimally log the error
}
}
4 changes: 4 additions & 0 deletions client/types/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type Callbacks interface {
// syncer can be used to initiate syncing the package from the server.
OnAgentPackageAvailable(addons *protobufs.AgentPackageAvailable, syncer AgentPackageSyncer) error

// OnAgentIdentification is called when the server requests changing identification of the agent.
// Agent should be updated with new id and use it for all further communication
OnAgentIdentification(ctx context.Context, agentId *protobufs.AgentIdentification) error

// For all methods that accept a context parameter the caller may cancel the
// context if processing takes too long. In that case the method should return
// as soon as possible with an error.
Expand Down
23 changes: 23 additions & 0 deletions internal/proto/opamp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ message AgentToServer {
// AgentDisconnect MUST be set in the last AgentToServer message sent from the
// agent to the server.
AgentDisconnect agent_disconnect = 5;

enum AgentToServerFlags {
FlagsUnspecified = 0;
// AgentToServerFlags is a bit mask. Values below define individual bits.

// The agent requests server go generate a new instance_uid, which will
// be sent back in ServerToAgent message
RequestInstanceUid = 0x00000001;
}
// Bit flags as defined by AgentToServerFlags bit masks.
AgentToServerFlags flags = 6;
}

// AgentDisconnect is the last message sent from the agent to the server. The server
Expand Down Expand Up @@ -111,6 +122,10 @@ message ServerToAgent {
// be omitted in subsequent ServerToAgent messages by setting it to
// UnspecifiedServerCapability value.
ServerCapabilities capabilities = 8;

// Properties related to identification of the agent, which can be overridden
// by the server if needed.
AgentIdentification agent_identification = 9;
}

enum ServerCapabilities {
Expand Down Expand Up @@ -663,6 +678,14 @@ message AgentInstallStatus {
string error_message = 4;
}

// Properties related to identification of the agent, which can be overridden
// by the server if needed
message AgentIdentification {
// When new_instance_uid is set, Agent MUST update instance_uid
// to the value provided and use it for all further communication.
string new_instance_uid = 1;
}

/////////////////////////////////////////////////////////////////////////////////////
// Config messages
/////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit b8939fd

Please sign in to comment.