Skip to content

Commit c0eefa6

Browse files
[8.17] (backport #8551) [test] split up ess and beats serverless integration tests (#8655)
* [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/beats/serverless/beats_serverless_test.go # 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/logs_ingestion_test.go # testing/integration/ess/metrics_monitoring_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/restrict_upgrade_deb_test.go # testing/integration/ess/restrict_upgrade_rpm_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/ess/validate_items_deprecated_list_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 700dd45 commit c0eefa6

Some content is hidden

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

47 files changed

+274
-168
lines changed

.buildkite/bk.integration.pipeline.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ steps:
132132
- label: "Win2022:sudo:{{matrix}}"
133133
depends_on:
134134
- packaging-windows
135+
env:
136+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
135137
command: |
136138
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
137139
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} true
@@ -157,6 +159,8 @@ steps:
157159
- label: "Win2022:non-sudo:{{matrix}}"
158160
depends_on:
159161
- packaging-windows
162+
env:
163+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
160164
command: |
161165
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
162166
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -176,6 +180,8 @@ steps:
176180
- label: "Win2025:sudo:{{matrix}}"
177181
depends_on:
178182
- packaging-windows
183+
env:
184+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
179185
command: |
180186
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
181187
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} true
@@ -202,6 +208,8 @@ steps:
202208
- label: "Win2025:non-sudo:{{matrix}}"
203209
depends_on:
204210
- packaging-windows
211+
env:
212+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
205213
command: |
206214
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
207215
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -228,6 +236,8 @@ steps:
228236
steps:
229237
- label: "x86_64:non-sudo: {{matrix}}"
230238
depends_on: packaging-ubuntu-x86-64
239+
env:
240+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
231241
command: |
232242
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
233243
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -248,6 +258,8 @@ steps:
248258
depends_on:
249259
- packaging-ubuntu-x86-64
250260
# due to deb group present in matrix tar.gz and deb packages artifacts are required
261+
env:
262+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
251263
command: |
252264
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
253265
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -279,6 +291,8 @@ steps:
279291
- label: "arm:sudo: {{matrix}}"
280292
depends_on:
281293
- packaging-ubuntu-arm64
294+
env:
295+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
282296
command: |
283297
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64'
284298
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -312,6 +326,8 @@ steps:
312326
skip: true
313327
depends_on:
314328
- packaging-ubuntu-arm64
329+
env:
330+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
315331
command: |
316332
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64'
317333
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -338,6 +354,8 @@ steps:
338354
steps:
339355
- label: "x86_64:non-sudo: {{matrix}}"
340356
depends_on: packaging-ubuntu-x86-64
357+
env:
358+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
341359
command: |
342360
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
343361
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -358,6 +376,8 @@ steps:
358376
depends_on:
359377
- packaging-ubuntu-x86-64
360378
# due to deb group present in matrix tar.gz and deb packages artifacts are required
379+
env:
380+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
361381
command: |
362382
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
363383
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -399,6 +419,8 @@ steps:
399419
- label: "x86_64:sudo:rpm"
400420
depends_on:
401421
- packaging-ubuntu-x86-64
422+
env:
423+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
402424
command: |
403425
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
404426
.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
@@ -1920,8 +1920,9 @@ func (Integration) Clean() error {
19201920
func (Integration) Check() error {
19211921
fmt.Println(">> check: Checking for define.Require in integration tests") // nolint:forbidigo // it's ok to use fmt.println in mage
19221922
return errors.Join(
1923-
define.ValidateDir("testing/integration"),
1923+
define.ValidateDir("testing/integration/ess"),
19241924
define.ValidateDir("testing/integration/serverless"),
1925+
define.ValidateDir("testing/integration/beats/serverless"),
19251926
define.ValidateDir("testing/integration/leak"),
19261927
define.ValidateDir("testing/integration/k8s"),
19271928
)
@@ -1981,17 +1982,17 @@ func (Integration) Auth(ctx context.Context) error {
19811982

19821983
// Test runs integration tests on remote hosts
19831984
func (Integration) Test(ctx context.Context) error {
1984-
return integRunner(ctx, "testing/integration", false, "")
1985+
return integRunner(ctx, "testing/integration/ess", false, "")
19851986
}
19861987

19871988
// Matrix runs integration tests on a matrix of all supported remote hosts
19881989
func (Integration) Matrix(ctx context.Context) error {
1989-
return integRunner(ctx, "testing/integration", true, "")
1990+
return integRunner(ctx, "testing/integration/ess", true, "")
19901991
}
19911992

19921993
// Single runs single integration test on remote host
19931994
func (Integration) Single(ctx context.Context, testName string) error {
1994-
return integRunner(ctx, "testing/integration", false, testName)
1995+
return integRunner(ctx, "testing/integration/ess", false, testName)
19951996
}
19961997

19971998
// TestServerless runs the integration tests defined in testing/integration/serverless
@@ -2546,7 +2547,7 @@ func (Integration) TestBeatServerless(ctx context.Context, beatname string) erro
25462547
if err != nil {
25472548
return fmt.Errorf("error setting binary name: %w", err)
25482549
}
2549-
return integRunner(ctx, "testing/integration", false, "TestBeatsServerless")
2550+
return integRunner(ctx, "testing/integration/beats/serverless", false, "TestBeatsServerless")
25502551
}
25512552

25522553
// TestForResourceLeaks runs tests that check for resource leaks
@@ -2629,7 +2630,7 @@ func (Integration) TestOnRemote(ctx context.Context) error {
26292630

26302631
func (Integration) Buildkite() error {
26312632
goTestFlags := os.Getenv("GOTEST_FLAGS")
2632-
batches, err := define.DetermineBatches("testing/integration", goTestFlags, "integration")
2633+
batches, err := define.DetermineBatches("testing/integration/ess", goTestFlags, "integration")
26332634
if err != nil {
26342635
return fmt.Errorf("failed to determine batches: %w", err)
26352636
}

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
"github.com/elastic/elastic-agent/pkg/testing/define"
3030
"github.com/elastic/elastic-agent/pkg/testing/tools"
3131
"github.com/elastic/elastic-agent/pkg/testing/tools/estools"
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
@@ -102,19 +102,19 @@ func LogIngestionFleetManaged(t *testing.T, info *define.Info) {
102102
checkHealthAtStartup(t, ctx, agentFixture)
103103

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

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

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

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

164-
func testMonitoringLogsAreShipped(
164+
func TestMonitoringLogsAreShipped(
165165
t *testing.T,
166166
ctx context.Context,
167167
info *define.Info,
@@ -299,7 +299,7 @@ func queryESDocs(t *testing.T, findFn func() (estools.Documents, error)) estools
299299
return docs
300300
}
301301

302-
func testFlattenedDatastreamFleetPolicy(
302+
func TestFlattenedDatastreamFleetPolicy(
303303
t *testing.T,
304304
ctx context.Context,
305305
info *define.Info,
@@ -322,18 +322,18 @@ func testFlattenedDatastreamFleetPolicy(
322322
t.Fatalf("failed to chmod temp directory %s: %s", tempDir, err)
323323
}
324324
logFilePath := filepath.Join(tempDir, "log.log")
325-
generateLogFile(t, logFilePath, 2*time.Millisecond, numEvents)
325+
GenerateLogFile(t, logFilePath, 2*time.Millisecond, numEvents)
326326

327327
// 1. Prepare a request to add an integration to the policy
328-
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(policyJSON)
328+
tmpl, err := template.New(t.Name() + "custom-log-policy").Parse(PolicyJSON)
329329
if err != nil {
330330
t.Fatalf("cannot parse template: %s", err)
331331
}
332332

333333
// The time here ensures there are no conflicts with the integration name
334334
// in Fleet.
335335
agentPolicyBuilder := strings.Builder{}
336-
err = tmpl.Execute(&agentPolicyBuilder, policyVars{
336+
err = tmpl.Execute(&agentPolicyBuilder, PolicyVars{
337337
Name: "Log-Input-" + t.Name() + "-" + time.Now().Format(time.RFC3339),
338338
PolicyID: policy.ID,
339339
LogFilePath: logFilePath,
@@ -413,10 +413,10 @@ func ensureDocumentsInES(
413413
return f
414414
}
415415

416-
// generateLogFile generates a log file by appending new lines every tick
416+
// GenerateLogFile generates a log file by appending new lines every tick
417417
// the lines are composed by the test name and the current time in RFC3339Nano
418418
// This function spans a new goroutine and does not block
419-
func generateLogFile(t *testing.T, fullPath string, tick time.Duration, events int) {
419+
func GenerateLogFile(t *testing.T, fullPath string, tick time.Duration, events int) {
420420
t.Helper()
421421
f, err := os.Create(fullPath)
422422
if err != nil {
@@ -473,7 +473,7 @@ func cleanString(s string) string {
473473

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

476-
var policyJSON = `
476+
var PolicyJSON = `
477477
{
478478
"policy_id": "{{.PolicyID}}",
479479
"package": {
@@ -500,7 +500,7 @@ var policyJSON = `
500500
}
501501
}`
502502

503-
type policyVars struct {
503+
type PolicyVars struct {
504504
Name string
505505
PolicyID string
506506
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)