From de8b24dc34345e4e21096ed776719a6d9a1b7b3c Mon Sep 17 00:00:00 2001 From: Panos Koutsovasilis Date: Thu, 25 Jul 2024 00:10:31 +0300 Subject: [PATCH] fix: improve logging the output of status command when elastic-agent doesn't report healthy --- .../kubernetes_agent_standalone_test.go | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/testing/integration/kubernetes_agent_standalone_test.go b/testing/integration/kubernetes_agent_standalone_test.go index 743851706ec..df3dc1284c9 100644 --- a/testing/integration/kubernetes_agent_standalone_test.go +++ b/testing/integration/kubernetes_agent_standalone_test.go @@ -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" @@ -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 { + 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()