Skip to content

Commit

Permalink
Eliminate DataForAgent message (#22)
Browse files Browse the repository at this point in the history
The DataForAgent message is unnecessary. Moved all fields from DataForAgent
to ServertoAgent and deleted DataForAgent.

Implements spec change open-telemetry/opamp-spec#42
  • Loading branch information
tigrannajaryan authored Nov 30, 2021
1 parent 8478dbd commit af695f2
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 652 deletions.
28 changes: 10 additions & 18 deletions client/clientimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,8 @@ func TestFirstStatusReport(t *testing.T) {
srv := internal.StartMockServer(t)
srv.OnMessage = func(msg *protobufs.AgentToServer) *protobufs.ServerToAgent {
return &protobufs.ServerToAgent{
InstanceUid: msg.InstanceUid,
Body: &protobufs.ServerToAgent_DataForAgent{
DataForAgent: &protobufs.DataForAgent{
RemoteConfig: remoteConfig,
},
},
InstanceUid: msg.InstanceUid,
RemoteConfig: remoteConfig,
}
}

Expand Down Expand Up @@ -365,18 +361,14 @@ func TestConnectionSettings(t *testing.T) {
atomic.AddInt64(&rcvStatus, 1)

return &protobufs.ServerToAgent{
Body: &protobufs.ServerToAgent_DataForAgent{
DataForAgent: &protobufs.DataForAgent{
ConnectionSettings: &protobufs.ConnectionSettingsOffers{
Hash: hash,
Opamp: opampSettings,
OwnMetrics: metricsSettings,
OwnTraces: tracesSettings,
OwnLogs: logsSettings,
OtherConnections: map[string]*protobufs.ConnectionSettings{
"other": otherSettings,
},
},
ConnectionSettings: &protobufs.ConnectionSettingsOffers{
Hash: hash,
Opamp: opampSettings,
OwnMetrics: metricsSettings,
OwnTraces: tracesSettings,
OwnLogs: logsSettings,
OtherConnections: map[string]*protobufs.ConnectionSettings{
"other": otherSettings,
},
},
}
Expand Down
26 changes: 9 additions & 17 deletions client/internal/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,22 @@ func (r *Receiver) receiveMessage(msg *protobufs.ServerToAgent) error {
return err
}

func (r *Receiver) processReceivedMessage(ctx context.Context, p *protobufs.ServerToAgent) {
data := p.GetDataForAgent()
if data != nil {
r.rcvDataForAgent(ctx, data)
return
}

err := p.GetErrorResponse()
if err != nil {
r.processErrorResponse(err)
}
}

func (r *Receiver) rcvDataForAgent(ctx context.Context, data *protobufs.DataForAgent) {
func (r *Receiver) processReceivedMessage(ctx context.Context, msg *protobufs.ServerToAgent) {
if r.callbacks != nil {
reportStatus := r.rcvRemoteConfig(ctx, data.RemoteConfig)
reportStatus := r.rcvRemoteConfig(ctx, msg.RemoteConfig)

r.rcvConnectionSettings(ctx, data.ConnectionSettings)
r.rcvAddonsAvailable(data.AddonsAvailable)
r.rcvConnectionSettings(ctx, msg.ConnectionSettings)
r.rcvAddonsAvailable(msg.AddonsAvailable)

if reportStatus {
r.sender.ScheduleSend()
}
}

err := msg.GetErrorResponse()
if err != nil {
r.processErrorResponse(err)
}
}

func (r *Receiver) rcvRemoteConfig(ctx context.Context, config *protobufs.AgentRemoteConfig) (reportStatus bool) {
Expand Down
44 changes: 11 additions & 33 deletions internal/proto/opamp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,52 +73,30 @@ message ServerToAgent {
// Used for multiplexing messages from/to multiple agents using one message stream.
string instance_uid = 1;

// There are two types of ServerToAgent messages: responses to an AgentToServer
// message and non-response messages, which are initiated by the server.
//
// If this message is a response to an AgentToServer message then sequence_num field
// here MUST be equal to the AgentToServer.sequence_num field. The sequential number
// allows to correctly match responses to requests even when the responses arrive
// re-ordered.
//
// If this message is non-response then the sequence_num field MUST be assigned
// by the server. The server SHOULD start with sequence_num=1 and increment it by 2
// for every new message that is not a response to an agent request (thus only
// odd numbers should appear in the non-response type messages from server to agent).
//fixed64 sequence_num = 2;

oneof Body {
DataForAgent data_for_agent = 2;
ServerErrorResponse error_response = 3;
}
}
// error_response is set if the Server wants to indicate that something went wrong
// during processing of an AgentToServer message. If error_response is set then
// all other fields below must be unset and vice versa, if any of the fields below is
// set then error_response must be unset.
ServerErrorResponse error_response = 2;

// DataForAgent message is sent from the server to the agent either in response to the
// AgentToServer message or when the server has data to deliver to the agent.
//
// If the server receives an AgentToServer message and the server has nothing to
// send back to the agent then DataForAgent message will still be sent, but all
// fields will be unset (in that case DataForAgent serves simply as an acknowledgement
// of receipt).
message DataForAgent {
// remote_config field is set when the server has a remote config offer for the agent.
AgentRemoteConfig remote_config = 1;
AgentRemoteConfig remote_config = 3;

// This field is set when the Server wants the Agent to change one or more
// of its client connection settings (destination, headers, certificate, etc).
ConnectionSettingsOffers connection_settings = 2;
ConnectionSettingsOffers connection_settings = 4;

// addons_available field is set when the server has addons to offer to the agent.
AddonsAvailable addons_available = 3;
AddonsAvailable addons_available = 5;

// agent_package_available field is set when the server has a different version
// of an agent package available for download.
AgentPackageAvailable agent_package_available = 4;
AgentPackageAvailable agent_package_available = 6;

enum Flags {
FlagsUnspecified = 0;

// DataForAgentFlags is a bit mask. Values below define individual bits.
// Flags is a bit mask. Values below define individual bits.

// Report* flags an be used by the server if the agent did not include the
// particular bit of information in the last status report (which is an allowed
Expand All @@ -131,7 +109,7 @@ message DataForAgent {
ReportAddonStatus = 0x00000002;
}
// Bit flags as defined by Flags bit masks.
Flags flags = 5;
Flags flags = 7;
}

// The ConnectionSettings message is a collection of fields which comprise an
Expand Down
Loading

0 comments on commit af695f2

Please sign in to comment.