Skip to content

Commit

Permalink
[testing/integration]: fix TestLogIngestionFleetManaged (#5648)
Browse files Browse the repository at this point in the history
fix TestLogIngestionFleetManaged

---------

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent ae48b95 commit 26f3d59
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
39 changes: 39 additions & 0 deletions testing/integration/logs_ingestion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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)
})
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 26f3d59

Please sign in to comment.