Skip to content

Commit 4973844

Browse files
committed
add asserts on metadata.Elastic.Agent
1 parent be2533d commit 4973844

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

internal/pkg/agent/application/gateway/fleet/fleet_gateway.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,9 @@ func (f *FleetGateway) execute(ctx context.Context) (*fleetapi.CheckinResponse,
329329
// convert components into checkin components structure
330330
components := f.convertToCheckinComponents(state.Components)
331331

332-
if ecsMeta.Elastic == nil || ecsMeta.Elastic.Agent == nil {
333-
// escMeta struct is incomplete: log a warning
334-
f.log.Warnw("Agent ECSMetadata struct is missing/incomplete", "elastic_ecs_metadata", ecsMeta.Elastic)
335-
} else {
336-
f.log.Debugf("correcting agent loglevel from %s to %s using coordinator state", ecsMeta.Elastic.Agent.LogLevel, state.LogLevel.String())
337-
// Fix loglevel with the current log level used by coordinator
338-
ecsMeta.Elastic.Agent.LogLevel = state.LogLevel.String()
339-
}
332+
f.log.Debugf("correcting agent loglevel from %s to %s using coordinator state", ecsMeta.Elastic.Agent.LogLevel, state.LogLevel.String())
333+
// Fix loglevel with the current log level used by coordinator
334+
ecsMeta.Elastic.Agent.LogLevel = state.LogLevel.String()
340335

341336
// checkin
342337
cmd := fleetapi.NewCheckinCmd(f.agentInfo, f.client)

internal/pkg/agent/application/info/agent_metadata_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func TestECSMetadata(t *testing.T) {
2929
metadata, err := agentInfo.ECSMetadata(l)
3030
require.NoError(t, err)
3131

32+
if assert.NotNil(t, metadata.Elastic, "metadata.Elastic must not be nil") {
33+
assert.NotNil(t, metadata.Elastic.Agent, "metadata.Elastic.Agent must not be nil")
34+
}
35+
3236
sysInfo, err := sysinfo.Host()
3337
require.NoError(t, err)
3438

0 commit comments

Comments
 (0)