Skip to content

Commit

Permalink
fix: improve logging the output of status command when elastic-agent …
Browse files Browse the repository at this point in the history
…doesn't report healthy
  • Loading branch information
pkoutsovasilis committed Jul 24, 2024
1 parent 44193ba commit de8b24d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions testing/integration/kubernetes_agent_standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent/pkg/testing/define"
Expand Down Expand Up @@ -262,21 +261,28 @@ func deployK8SAgent(t *testing.T, ctx context.Context, client klient.Client, obj

var stdout, stderr bytes.Buffer
command := []string{"elastic-agent", "status"}
success := assert.Eventually(t, func() bool {
var agentHealthy bool

// we will wait maximum 60 seconds for the agent to report healthy
for range 60 {

Check failure on line 267 in testing/integration/kubernetes_agent_standalone_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

cannot range over 60 (untyped int constant) (typecheck)
stdout.Reset()
stderr.Reset()
err := client.Resources().ExecInPod(ctx, namespace, agentPodName, "elastic-agent-standalone", command, &stdout, &stderr)
if err != nil {
stdout.Reset()
stderr.Reset()
return false
if err == nil {
agentHealthy = true
break
}
return true
}, time.Second*100, time.Second*1, "elastic-agent never reported healthy")
time.Sleep(time.Second * 1)
}

if !success {
t.Log(stdout.String())
t.Log(stderr.String())
if !agentHealthy {
t.Log("elastic-agent never reported healthy")
t.Logf("stdout: %s\n", stdout.String())
t.Logf("stderr: %s\n", stderr.String())
t.FailNow()
return
}

stdout.Reset()
stderr.Reset()

Expand Down

0 comments on commit de8b24d

Please sign in to comment.