Skip to content

Commit 3fabc88

Browse files
[8.18] (backport #8551) [test] split up ess and beats serverless integration tests (#8657)
* [test] split up ess and beats serverless integration tests (#8551) * feat: split up ess and beats serverless integration tests * feat: add the new integration test packages in the CI pipelines * feat: migrate serveless_beats to beats/serverless package (cherry picked from commit 73737c9) # Conflicts: # .buildkite/bk.integration-fips.pipeline.yml # testing/integration/ess/auditd_monitoring_test.go # testing/integration/ess/beat_receivers_test.go # testing/integration/ess/endpoint_security_test.go # testing/integration/ess/enroll_replace_token_test.go # testing/integration/ess/fleetserver_fips_test.go # testing/integration/ess/fleetserver_test.go # testing/integration/ess/install_test.go # testing/integration/ess/linux_deb_test.go # testing/integration/ess/linux_rpm_test.go # testing/integration/ess/network_traffic_monitoring_test.go # testing/integration/ess/osquery_monitoring_test.go # testing/integration/ess/otel_test.go # testing/integration/ess/testdata/auditd_package.json # testing/integration/ess/testdata/fleet-server.json # testing/integration/ess/testdata/network_traffic_package.json # testing/integration/ess/testdata/osquery_package.json # testing/integration/ess/upgrade_fleet_test.go # testing/integration/ess/upgrade_standalone_flavors_test.go # testing/integration/fleet-server.json # testing/integration/testdata/fleet-server.json * fix: resolve conflicts * fix: mage fmt * fix: move fleet-server.json --------- Co-authored-by: Panos Koutsovasilis <[email protected]>
1 parent 903eea5 commit 3fabc88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+287
-180
lines changed

.buildkite/bk.integration.pipeline.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ steps:
130130
- label: "Win2022:sudo:{{matrix}}"
131131
depends_on:
132132
- packaging-windows
133+
env:
134+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
133135
command: |
134136
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
135137
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} true
@@ -155,6 +157,8 @@ steps:
155157
- label: "Win2022:non-sudo:{{matrix}}"
156158
depends_on:
157159
- packaging-windows
160+
env:
161+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
158162
command: |
159163
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
160164
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -174,6 +178,8 @@ steps:
174178
- label: "Win2025:sudo:{{matrix}}"
175179
depends_on:
176180
- packaging-windows
181+
env:
182+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
177183
command: |
178184
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
179185
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} true
@@ -200,6 +206,8 @@ steps:
200206
- label: "Win2025:non-sudo:{{matrix}}"
201207
depends_on:
202208
- packaging-windows
209+
env:
210+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
203211
command: |
204212
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
205213
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -226,6 +234,8 @@ steps:
226234
steps:
227235
- label: "x86_64:non-sudo: {{matrix}}"
228236
depends_on: packaging-ubuntu-x86-64
237+
env:
238+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
229239
command: |
230240
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
231241
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -246,6 +256,8 @@ steps:
246256
depends_on:
247257
- packaging-ubuntu-x86-64
248258
# due to deb group present in matrix tar.gz and deb packages artifacts are required
259+
env:
260+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
249261
command: |
250262
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
251263
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -277,6 +289,8 @@ steps:
277289
- label: "arm:sudo: {{matrix}}"
278290
depends_on:
279291
- packaging-ubuntu-arm64
292+
env:
293+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
280294
command: |
281295
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64'
282296
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -310,6 +324,8 @@ steps:
310324
skip: true
311325
depends_on:
312326
- packaging-ubuntu-arm64
327+
env:
328+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
313329
command: |
314330
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64'
315331
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -336,6 +352,8 @@ steps:
336352
steps:
337353
- label: "x86_64:non-sudo: {{matrix}}"
338354
depends_on: packaging-ubuntu-x86-64
355+
env:
356+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
339357
command: |
340358
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
341359
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -356,6 +374,8 @@ steps:
356374
depends_on:
357375
- packaging-ubuntu-x86-64
358376
# due to deb group present in matrix tar.gz and deb packages artifacts are required
377+
env:
378+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
359379
command: |
360380
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
361381
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -397,6 +417,8 @@ steps:
397417
- label: "x86_64:sudo:rpm"
398418
depends_on:
399419
- packaging-ubuntu-x86-64
420+
env:
421+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
400422
command: |
401423
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
402424
.buildkite/scripts/steps/integration_tests_tf.sh rpm true

magefile.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,9 @@ func (Integration) Clean() error {
19951995
func (Integration) Check() error {
19961996
fmt.Println(">> check: Checking for define.Require in integration tests") // nolint:forbidigo // it's ok to use fmt.println in mage
19971997
return errors.Join(
1998-
define.ValidateDir("testing/integration"),
1998+
define.ValidateDir("testing/integration/ess"),
19991999
define.ValidateDir("testing/integration/serverless"),
2000+
define.ValidateDir("testing/integration/beats/serverless"),
20002001
define.ValidateDir("testing/integration/leak"),
20012002
define.ValidateDir("testing/integration/k8s"),
20022003
)
@@ -2056,17 +2057,17 @@ func (Integration) Auth(ctx context.Context) error {
20562057

20572058
// Test runs integration tests on remote hosts
20582059
func (Integration) Test(ctx context.Context) error {
2059-
return integRunner(ctx, "testing/integration", false, "")
2060+
return integRunner(ctx, "testing/integration/ess", false, "")
20602061
}
20612062

20622063
// Matrix runs integration tests on a matrix of all supported remote hosts
20632064
func (Integration) Matrix(ctx context.Context) error {
2064-
return integRunner(ctx, "testing/integration", true, "")
2065+
return integRunner(ctx, "testing/integration/ess", true, "")
20652066
}
20662067

20672068
// Single runs single integration test on remote host
20682069
func (Integration) Single(ctx context.Context, testName string) error {
2069-
return integRunner(ctx, "testing/integration", false, testName)
2070+
return integRunner(ctx, "testing/integration/ess", false, testName)
20702071
}
20712072

20722073
// TestServerless runs the integration tests defined in testing/integration/serverless
@@ -2621,7 +2622,7 @@ func (Integration) TestBeatServerless(ctx context.Context, beatname string) erro
26212622
if err != nil {
26222623
return fmt.Errorf("error setting binary name: %w", err)
26232624
}
2624-
return integRunner(ctx, "testing/integration", false, "TestBeatsServerless")
2625+
return integRunner(ctx, "testing/integration/beats/serverless", false, "TestBeatsServerless")
26252626
}
26262627

26272628
// TestForResourceLeaks runs tests that check for resource leaks
@@ -2704,7 +2705,7 @@ func (Integration) TestOnRemote(ctx context.Context) error {
27042705

27052706
func (Integration) Buildkite() error {
27062707
goTestFlags := os.Getenv("GOTEST_FLAGS")
2707-
batches, err := define.DetermineBatches("testing/integration", goTestFlags, "integration")
2708+
batches, err := define.DetermineBatches("testing/integration/ess", goTestFlags, "integration")
27082709
if err != nil {
27092710
return fmt.Errorf("failed to determine batches: %w", err)
27102711
}

testing/integration/beats_serverless_test.go renamed to testing/integration/beats/serverless/beats_serverless_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:build integration
66

7-
package integration
7+
package serverless
88

99
import (
1010
"bytes"
@@ -29,6 +29,7 @@ import (
2929
atesting "github.com/elastic/elastic-agent/pkg/testing"
3030
"github.com/elastic/elastic-agent/pkg/testing/define"
3131
"github.com/elastic/elastic-agent/pkg/testing/tools"
32+
"github.com/elastic/elastic-agent/testing/integration"
3233
)
3334

3435
type BeatRunner struct {
@@ -50,7 +51,7 @@ type BeatRunner struct {
5051

5152
func TestBeatsServerless(t *testing.T) {
5253
info := define.Require(t, define.Requirements{
53-
Group: Default,
54+
Group: integration.Default,
5455
OS: []define.OS{
5556
{Type: define.Linux},
5657
},
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
//go:build integration
6+
7+
package serverless
8+
9+
import (
10+
"flag"
11+
"log"
12+
"os"
13+
"testing"
14+
15+
"github.com/elastic/elastic-agent/pkg/testing/define"
16+
)
17+
18+
var flagSet = flag.CommandLine
19+
20+
func init() {
21+
define.RegisterFlags("integration.", flagSet)
22+
}
23+
24+
func TestMain(m *testing.M) {
25+
flag.Parse()
26+
27+
if define.AutoDiscover {
28+
define.InitAutodiscovery(nil)
29+
}
30+
31+
runExitCode := m.Run()
32+
33+
if define.AutoDiscover {
34+
discoveredTests, err := define.DumpAutodiscoveryYAML()
35+
if err != nil {
36+
log.Fatalf("Error dumping autodiscovery YAML: %v\n", err)
37+
}
38+
39+
err = os.WriteFile(define.AutoDiscoveryOutput, discoveredTests, 0644)
40+
if err != nil {
41+
log.Fatalf("Error writing autodiscovery data in %q: %v\n", define.AutoDiscoveryOutput, err)
42+
}
43+
}
44+
45+
os.Exit(runExitCode)
46+
}

testing/integration/logs_ingestion.go renamed to testing/integration/common_logs_ingestion.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ func LogIngestionFleetManaged(t *testing.T, info *define.Info) {
101101
checkHealthAtStartup(t, ctx, agentFixture)
102102

103103
t.Run("Monitoring logs are shipped", func(t *testing.T) {
104-
testMonitoringLogsAreShipped(t, ctx, info, agentFixture, policy)
104+
TestMonitoringLogsAreShipped(t, ctx, info, agentFixture, policy)
105105
})
106106

107107
t.Run("Normal logs with flattened data_stream are shipped", func(t *testing.T) {
108-
testFlattenedDatastreamFleetPolicy(t, ctx, info, policy)
108+
TestFlattenedDatastreamFleetPolicy(t, ctx, info, policy)
109109
})
110110
}
111111

112-
// startMockES starts a MockES on a random port using httptest.NewServer.
112+
// StartMockES starts a MockES on a random port using httptest.NewServer.
113113
// It registers a cleanup function to close the server when the test finishes.
114114
// The server will respond with the passed error probabilities. If they add
115115
// up to zero, all requests are a success.
116-
func startMockES(t *testing.T, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge uint) string {
116+
func StartMockES(t *testing.T, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge uint) string {
117117
uid := uuid.Must(uuid.NewV4())
118118
clusterUUID := uuid.Must(uuid.NewV4()).String()
119119

@@ -160,7 +160,7 @@ func checkHealthAtStartup(t *testing.T, ctx context.Context, agentFixture *atest
160160
}, 3*time.Minute, 3*time.Second, "install never became healthy: components did not return a healthy state: %s", compDebugName)
161161
}
162162

163-
func testMonitoringLogsAreShipped(
163+
func TestMonitoringLogsAreShipped(
164164
t *testing.T,
165165
ctx context.Context,
166166
info *define.Info,
@@ -291,7 +291,7 @@ func queryESDocs(t *testing.T, findFn func() (estools.Documents, error)) estools
291291
return docs
292292
}
293293

294-
func testFlattenedDatastreamFleetPolicy(
294+
func TestFlattenedDatastreamFleetPolicy(
295295
t *testing.T,
296296
ctx context.Context,
297297
info *define.Info,
@@ -314,18 +314,18 @@ func testFlattenedDatastreamFleetPolicy(
314314
t.Fatalf("failed to chmod temp directory %s: %s", tempDir, err)
315315
}
316316
logFilePath := filepath.Join(tempDir, "log.log")
317-
generateLogFile(t, logFilePath, 2*time.Millisecond, numEvents)
317+
GenerateLogFile(t, logFilePath, 2*time.Millisecond, numEvents)
318318

319319
// 1. Prepare a request to add an integration to the policy
320-
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(policyJSON)
320+
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(PolicyJSON)
321321
if err != nil {
322322
t.Fatalf("cannot parse template: %s", err)
323323
}
324324

325325
// The time here ensures there are no conflicts with the integration name
326326
// in Fleet.
327327
agentPolicyBuilder := strings.Builder{}
328-
err = tmpl.Execute(&agentPolicyBuilder, policyVars{
328+
err = tmpl.Execute(&agentPolicyBuilder, PolicyVars{
329329
Name: "Log-Input-" + t.Name() + "-" + time.Now().Format(time.RFC3339),
330330
PolicyID: policy.ID,
331331
LogFilePath: logFilePath,
@@ -405,10 +405,10 @@ func ensureDocumentsInES(
405405
return f
406406
}
407407

408-
// generateLogFile generates a log file by appending new lines every tick
408+
// GenerateLogFile generates a log file by appending new lines every tick
409409
// the lines are composed by the test name and the current time in RFC3339Nano
410410
// This function spans a new goroutine and does not block
411-
func generateLogFile(t *testing.T, fullPath string, tick time.Duration, events int) {
411+
func GenerateLogFile(t *testing.T, fullPath string, tick time.Duration, events int) {
412412
t.Helper()
413413
f, err := os.Create(fullPath)
414414
if err != nil {
@@ -465,7 +465,7 @@ func cleanString(s string) string {
465465

466466
var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9 ]+`)
467467

468-
var policyJSON = `
468+
var PolicyJSON = `
469469
{
470470
"policy_id": "{{.PolicyID}}",
471471
"package": {
@@ -492,7 +492,7 @@ var policyJSON = `
492492
}
493493
}`
494494

495-
type policyVars struct {
495+
type PolicyVars struct {
496496
Name string
497497
PolicyID string
498498
LogFilePath string

testing/integration/apm_propagation_test.go renamed to testing/integration/ess/apm_propagation_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:build integration
66

7-
package integration
7+
package ess
88

99
import (
1010
"bytes"
@@ -27,6 +27,7 @@ import (
2727
"github.com/elastic/elastic-agent/pkg/control/v2/client"
2828
atesting "github.com/elastic/elastic-agent/pkg/testing"
2929
"github.com/elastic/elastic-agent/pkg/testing/define"
30+
"github.com/elastic/elastic-agent/testing/integration"
3031
)
3132

3233
const agentConfigTemplateString = `
@@ -52,7 +53,7 @@ agent.monitoring:
5253

5354
func TestAPMConfig(t *testing.T) {
5455
info := define.Require(t, define.Requirements{
55-
Group: Default,
56+
Group: integration.Default,
5657
Stack: &define.Stack{},
5758
})
5859
f, err := define.NewFixtureFromLocalBuild(t, define.Version())

testing/integration/container_cmd_test.go renamed to testing/integration/ess/container_cmd_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:build integration
66

7-
package integration
7+
package ess
88

99
import (
1010
"bufio"
@@ -31,6 +31,7 @@ import (
3131
atesting "github.com/elastic/elastic-agent/pkg/testing"
3232
"github.com/elastic/elastic-agent/pkg/testing/define"
3333
"github.com/elastic/elastic-agent/pkg/testing/tools/fleettools"
34+
"github.com/elastic/elastic-agent/testing/integration"
3435
)
3536

3637
func createPolicy(
@@ -355,7 +356,7 @@ func TestContainerCMDEventToStderr(t *testing.T) {
355356

356357
cmd, agentOutput := prepareAgentCMD(t, ctx, agentFixture, []string{"container"}, env)
357358
addLogIntegration(t, info, policyID, "/tmp/flog.log")
358-
generateLogFile(t, "/tmp/flog.log", time.Second/2, 100)
359+
integration.GenerateLogFile(t, "/tmp/flog.log", time.Second/2, 100)
359360

360361
t.Logf(">> running binary with: %v", cmd.Args)
361362
if err := cmd.Start(); err != nil {
@@ -396,7 +397,7 @@ func TestContainerCMDEventToStderr(t *testing.T) {
396397
// The server will respond with the passed error probabilities. If they add
397398
// up to zero, all requests are a success.
398399
func createMockESOutput(t *testing.T, info *define.Info, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge uint) (string, string) {
399-
mockesURL := startMockES(t, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge)
400+
mockesURL := integration.StartMockES(t, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge)
400401
createOutputBody := `
401402
{
402403
"id": "mock-es-%[1]s",
@@ -445,12 +446,12 @@ func createMockESOutput(t *testing.T, info *define.Info, percentDuplicate, perce
445446

446447
func addLogIntegration(t *testing.T, info *define.Info, policyID, logFilePath string) {
447448
agentPolicyBuilder := strings.Builder{}
448-
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(policyJSON)
449+
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(integration.PolicyJSON)
449450
if err != nil {
450451
t.Fatalf("cannot parse template: %s", err)
451452
}
452453

453-
err = tmpl.Execute(&agentPolicyBuilder, policyVars{
454+
err = tmpl.Execute(&agentPolicyBuilder, integration.PolicyVars{
454455
Name: "Log-Input-" + t.Name() + "-" + time.Now().Format(time.RFC3339),
455456
PolicyID: policyID,
456457
LogFilePath: logFilePath,

0 commit comments

Comments
 (0)