Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log level value reported by Agent to Fleet #4838

Merged
merged 9 commits into from
Jun 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ func (f *FleetGateway) execute(ctx context.Context) (*fleetapi.CheckinResponse,
// convert components into checkin components structure
components := f.convertToCheckinComponents(state.Components)

f.log.Debugf("correcting agent loglevel from %s to %s using coordinator state", ecsMeta.Elastic.Agent.LogLevel, state.LogLevel.String())
// Fix loglevel with the current log level used by coordinator
ecsMeta.Elastic.Agent.LogLevel = state.LogLevel.String()

// checkin
cmd := fleetapi.NewCheckinCmd(f.agentInfo, f.client)
req := &fleetapi.CheckinRequest{
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/agent/application/info/agent_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func TestECSMetadata(t *testing.T) {
metadata, err := agentInfo.ECSMetadata(l)
require.NoError(t, err)

if assert.NotNil(t, metadata.Elastic, "metadata.Elastic must not be nil") {
assert.NotNil(t, metadata.Elastic.Agent, "metadata.Elastic.Agent must not be nil")
}

sysInfo, err := sysinfo.Host()
require.NoError(t, err)

Expand Down
10 changes: 10 additions & 0 deletions pkg/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,16 @@ func (f *Fixture) PrepareAgentCommand(ctx context.Context, args []string, opts .
return nil, fmt.Errorf("failed to prepare before exec: %w", err)
}

// prepare a client if it's not already set
if f.c == nil {
cAddr, err := control.AddressFromPath(f.operatingSystem, f.workDir)
if err != nil {
return nil, fmt.Errorf("failed to get control protcol address: %w", err)
}
agentClient := client.New(client.WithAddress(cAddr))
f.setClient(agentClient)
}

// #nosec G204 -- Not so many ways to support variadic arguments to the elastic-agent command :(
cmd := exec.CommandContext(ctx, f.binaryPath(), args...)
for _, o := range opts {
Expand Down
Loading