Skip to content

Commit

Permalink
add management mode to client-side AgentInfo (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry authored Jun 3, 2024
1 parent 2c7ee2d commit 4d41e73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 6 additions & 3 deletions pkg/client/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type AgentInfo struct {
Version string
// Snapshot is true when the running version of the Elastic Agent is a snapshot.
Snapshot bool
// IsStandalone reports if the agent is running in standalone or managed mode
ManagedMode proto.AgentManagedMode
}

// VersionInfo is the version information for the connecting client.
Expand Down Expand Up @@ -573,9 +575,10 @@ func (c *clientV2) applyExpected(expected *proto.CheckinExpected) {
if expected.AgentInfo != nil {
c.agentInfoMu.Lock()
c.agentInfo = &AgentInfo{
ID: expected.AgentInfo.Id,
Version: expected.AgentInfo.Version,
Snapshot: expected.AgentInfo.Snapshot,
ID: expected.AgentInfo.Id,
Version: expected.AgentInfo.Version,
Snapshot: expected.AgentInfo.Snapshot,
ManagedMode: expected.AgentInfo.Mode,
}
c.agentInfoMu.Unlock()
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/client/client_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie
packageVersion := "8.13.0+build20060102"
wantBuildHash := "build_hash"
wantAgentInfo := AgentInfo{
ID: "elastic-agent-id",
Version: packageVersion,
Snapshot: true,
ID: "elastic-agent-id",
Version: packageVersion,
Snapshot: true,
ManagedMode: proto.AgentManagedMode_STANDALONE,
}
vInfo := VersionInfo{
Name: "program",
Expand All @@ -185,6 +186,7 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie
Id: wantAgentInfo.ID,
Version: wantAgentInfo.Version,
Snapshot: wantAgentInfo.Snapshot,
Mode: wantAgentInfo.ManagedMode,
},
Features: &proto.Features{
Fqdn: &proto.FQDNFeature{Enabled: wantFQDN},
Expand Down Expand Up @@ -303,8 +305,9 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie
assert.Equal(t, wantAgentInfo.ID, agentInfo.ID)
assert.Equal(t, wantAgentInfo.Version, agentInfo.Version)
assert.True(t, wantAgentInfo.Snapshot, agentInfo.Snapshot)
assert.Equal(t, wantAgentInfo.ManagedMode, agentInfo.ManagedMode)
}

assert.Truef(t, gotFQDN, "FQND should be true")

if assert.Lenf(t, units, 2, "should have received 2 units") {
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ func NewV2FromReader(reader io.Reader, ver VersionInfo, opts ...V2ClientOption)

if info.AgentInfo != nil {
opts = append(opts, WithAgentInfo(AgentInfo{
ID: info.AgentInfo.Id,
Version: info.AgentInfo.Version,
Snapshot: info.AgentInfo.Snapshot,
ID: info.AgentInfo.Id,
Version: info.AgentInfo.Version,
Snapshot: info.AgentInfo.Snapshot,
ManagedMode: info.AgentInfo.Mode,
}))
}

Expand Down

0 comments on commit 4d41e73

Please sign in to comment.