Skip to content

Commit

Permalink
Correctly handle status compression on the server side
Browse files Browse the repository at this point in the history
This is an alternate draft PR to demonstrate how open-telemetry/opamp-spec#109
can be resolved without adding a new "compressed/full" flag, suggested by @andykellr
  • Loading branch information
tigrannajaryan committed Jul 15, 2022
1 parent 5911ef2 commit 6325ee9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
27 changes: 21 additions & 6 deletions internal/examples/server/data/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,27 @@ func (agent *Agent) processStatusUpdate(
newStatus *protobufs.AgentToServer,
response *protobufs.ServerToAgent,
) {
if agent.Status != nil && agent.Status.SequenceNum+1 != newStatus.SequenceNum {
// We lost the previous status update. Request full status update from the agent.
response.Flags |= protobufs.ServerToAgent_ReportFullState
}
// We don't have any status for this Agent, or we lost the previous status update from the Agent, so our
// current status is not up-to-date.
lostPreviousUpdate := (agent.Status == nil) || (agent.Status != nil && agent.Status.SequenceNum+1 != newStatus.SequenceNum)

agentDescrChanged := agent.updateStatusField(newStatus)

// Check if any fields were omitted in the status report.
effectiveConfigOmitted := agent.Status.Capabilities&protobufs.AgentCapabilities_ReportsEffectiveConfig != 0 && newStatus.EffectiveConfig == nil
packageStatusesOmitted := agent.Status.Capabilities&protobufs.AgentCapabilities_ReportsPackageStatuses != 0 && newStatus.PackageStatuses == nil
remoteConfigStatusOmitted := agent.Status.Capabilities&protobufs.AgentCapabilities_AcceptsRemoteConfig != 0 && newStatus.RemoteConfigStatus == nil
healthOmitted := agent.Status.Capabilities&protobufs.AgentCapabilities_ReportsHealth != 0 && newStatus.Health == nil

// True if the status was not fully reported.
statusIsCompressed := effectiveConfigOmitted || packageStatusesOmitted || remoteConfigStatusOmitted || healthOmitted

if statusIsCompressed && lostPreviousUpdate {
// The status message is not fully set in the message that we received, but we lost the previous
// status update. Request full status update from the agent.
response.Flags |= protobufs.ServerToAgent_ReportFullState
}

configChanged := false
if agentDescrChanged {
// Agent description is changed.
Expand All @@ -219,14 +233,15 @@ func (agent *Agent) processStatusUpdate(
// If remote config is changed and different from what the Agent has then
// send the new remote config to the Agent.
if configChanged ||
(newStatus.RemoteConfigStatus != nil &&
bytes.Compare(newStatus.RemoteConfigStatus.LastRemoteConfigHash, agent.remoteConfig.ConfigHash) != 0) {
(agent.Status.RemoteConfigStatus != nil &&
bytes.Compare(agent.Status.RemoteConfigStatus.LastRemoteConfigHash, agent.remoteConfig.ConfigHash) != 0) {
// The new status resulted in a change in the config of the Agent or the Agent
// does not have this config (hash is different). Send the new config the Agent.
response.RemoteConfig = agent.remoteConfig
}

agent.updateEffectiveConfig(newStatus, response)

}

// SetCustomConfig sets a custom config for this Agent.
Expand Down
4 changes: 4 additions & 0 deletions internal/proto/opamp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ enum AgentCapabilities {
AcceptsOtherConnectionSettings = 0x00000200;
// The Agent can accept restart requests.
AcceptsRestartCommand = 0x00000400;
// The Agent reports Health
ReportsHealth = 0x00000800;
// // The Agent will report RemoteConfig in AgentToServer.
// ReportsRemoteConfig = 0x00001000;

// Add new capabilities here, continuing with the least significant unused bit.
}
Expand Down
17 changes: 11 additions & 6 deletions protobufs/opamp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6325ee9

Please sign in to comment.