From 26f3d5975ef18b578c20aba2f814b90fbf44e008 Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Thu, 10 Oct 2024 07:44:37 +0530 Subject: [PATCH] [testing/integration]: fix TestLogIngestionFleetManaged (#5648) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix TestLogIngestionFleetManaged --------- Co-authored-by: Paolo ChilĂ  Co-authored-by: Blake Rouse --- NOTICE.txt | 4 +-- go.mod | 2 +- go.sum | 4 +-- testing/integration/logs_ingestion_test.go | 39 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 6f2aebf44a5..53bfe7b723e 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1264,11 +1264,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.11.0 +Version: v0.12.1-0.20241009140206-6634efed32ab Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.11.0/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.12.1-0.20241009140206-6634efed32ab/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index cfe562b85e3..edd2110647e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5 github.com/elastic/elastic-agent-autodiscover v0.9.0 github.com/elastic/elastic-agent-client/v7 v7.16.0 - github.com/elastic/elastic-agent-libs v0.11.0 + github.com/elastic/elastic-agent-libs v0.12.1-0.20241009140206-6634efed32ab github.com/elastic/elastic-agent-system-metrics v0.11.3 github.com/elastic/elastic-transport-go/v8 v8.6.0 github.com/elastic/go-elasticsearch/v8 v8.15.0 diff --git a/go.sum b/go.sum index 3021462afc2..916b5c9df98 100644 --- a/go.sum +++ b/go.sum @@ -248,8 +248,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.16.0 h1:yKGq2+CxAuW8Kh0EoNl202tqAyQKfBcPRawVKs2Jve0= github.com/elastic/elastic-agent-client/v7 v7.16.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= -github.com/elastic/elastic-agent-libs v0.11.0 h1:m9rnNE3BkBF2XJoqubqEbu/kbtKEBZ7pHCjDlxfVRH0= -github.com/elastic/elastic-agent-libs v0.11.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= +github.com/elastic/elastic-agent-libs v0.12.1-0.20241009140206-6634efed32ab h1:7XHtHd5w4BV48ToCKGE4NYA0kpI+hv+7S08kdiTjpac= +github.com/elastic/elastic-agent-libs v0.12.1-0.20241009140206-6634efed32ab/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= github.com/elastic/elastic-agent-system-metrics v0.11.3 h1:LDzRwP8kxvsYEtMDgMSKZs1TgPcSEukit+/EAP5Y28A= github.com/elastic/elastic-agent-system-metrics v0.11.3/go.mod h1:saqLKe9fuyuAo6IADAnnuy1kaBI7VNlxfwMo8KzSRyQ= github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= diff --git a/testing/integration/logs_ingestion_test.go b/testing/integration/logs_ingestion_test.go index f005e9bfb30..56a2fcf2e29 100644 --- a/testing/integration/logs_ingestion_test.go +++ b/testing/integration/logs_ingestion_test.go @@ -27,6 +27,7 @@ import ( "github.com/elastic/elastic-agent-libs/kibana" "github.com/elastic/elastic-agent/pkg/control/v2/client" + "github.com/elastic/elastic-agent/pkg/control/v2/cproto" atesting "github.com/elastic/elastic-agent/pkg/testing" "github.com/elastic/elastic-agent/pkg/testing/define" "github.com/elastic/elastic-agent/pkg/testing/tools" @@ -77,6 +78,13 @@ func TestLogIngestionFleetManaged(t *testing.T) { "enabled": true, }, }, + Overrides: map[string]interface{}{ + "agent": map[string]interface{}{ + "monitoring": map[string]interface{}{ + "metrics_period": "1s", + }, + }, + }, } installOpts := atesting.InstallOpts{ @@ -100,6 +108,9 @@ func TestLogIngestionFleetManaged(t *testing.T) { // 3. Ensure installation is correct. require.NoError(t, installtest.CheckSuccess(ctx, agentFixture, installOpts.BasePath, &installtest.CheckOpts{Privileged: installOpts.Privileged})) + // 4. Ensure healthy state at startup + checkHealthAtStartup(t, ctx, agentFixture) + t.Run("Monitoring logs are shipped", func(t *testing.T) { testMonitoringLogsAreShipped(t, ctx, info, agentFixture, policy) }) @@ -127,6 +138,34 @@ func startMockES(t *testing.T) string { return s.URL } +// checkHealthAtStartup ensures all the beats and agent are healthy and working before we continue +func checkHealthAtStartup(t *testing.T, ctx context.Context, agentFixture *atesting.Fixture) { + // because we need to separately fetch the PIDs, wait until everything is healthy before we look for running beats + compDebugName := "" + require.Eventually(t, func() bool { + allHealthy := true + status, err := agentFixture.ExecStatus(ctx) + if err != nil { + t.Logf("agent status returned an error: %v", err) + return false + } + t.Logf("Received agent status:\n%+v\n", status) // this can be re-marshaled to JSON if we prefer that notation + for _, comp := range status.Components { + // make sure the components include the expected integrations + for _, v := range comp.Units { + if v.State != int(cproto.State_HEALTHY) { + allHealthy = false + } + } + if comp.State != int(cproto.State_HEALTHY) { + compDebugName = comp.Name + allHealthy = false + } + } + return allHealthy + }, 3*time.Minute, 3*time.Second, "install never became healthy: components did not return a healthy state: %s", compDebugName) +} + func testMonitoringLogsAreShipped( t *testing.T, ctx context.Context,