Skip to content

Commit 07f0290

Browse files
[8.19] (backport #8551) [test] split up ess and beats serverless integration tests (#8658)
* [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: # testing/integration/ess/auditd_monitoring_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/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_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 c653ee5 commit 07f0290

Some content is hidden

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

54 files changed

+311
-199
lines changed

.buildkite/bk.integration-fips.pipeline.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ steps:
6161
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
6262
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
6363
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
64+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
6465
command: |
6566
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64-fips'
6667
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix.groups}} {{matrix.sudo}}
@@ -90,6 +91,7 @@ steps:
9091
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
9192
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
9293
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
94+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
9395
command: |
9496
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64-fips'
9597
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix.groups}} {{matrix.sudo}}

.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
@@ -2242,8 +2242,9 @@ func (Integration) Clean() error {
22422242
func (Integration) Check() error {
22432243
fmt.Println(">> check: Checking for define.Require in integration tests") // nolint:forbidigo // it's ok to use fmt.println in mage
22442244
return errors.Join(
2245-
define.ValidateDir("testing/integration"),
2245+
define.ValidateDir("testing/integration/ess"),
22462246
define.ValidateDir("testing/integration/serverless"),
2247+
define.ValidateDir("testing/integration/beats/serverless"),
22472248
define.ValidateDir("testing/integration/leak"),
22482249
define.ValidateDir("testing/integration/k8s"),
22492250
)
@@ -2303,17 +2304,17 @@ func (Integration) Auth(ctx context.Context) error {
23032304

23042305
// Test runs integration tests on remote hosts
23052306
func (Integration) Test(ctx context.Context) error {
2306-
return integRunner(ctx, "testing/integration", false, "")
2307+
return integRunner(ctx, "testing/integration/ess", false, "")
23072308
}
23082309

23092310
// Matrix runs integration tests on a matrix of all supported remote hosts
23102311
func (Integration) Matrix(ctx context.Context) error {
2311-
return integRunner(ctx, "testing/integration", true, "")
2312+
return integRunner(ctx, "testing/integration/ess", true, "")
23122313
}
23132314

23142315
// Single runs single integration test on remote host
23152316
func (Integration) Single(ctx context.Context, testName string) error {
2316-
return integRunner(ctx, "testing/integration", false, testName)
2317+
return integRunner(ctx, "testing/integration/ess", false, testName)
23172318
}
23182319

23192320
// TestServerless runs the integration tests defined in testing/integration/serverless
@@ -2871,7 +2872,7 @@ func (Integration) TestBeatServerless(ctx context.Context, beatname string) erro
28712872
if err != nil {
28722873
return fmt.Errorf("error setting binary name: %w", err)
28732874
}
2874-
return integRunner(ctx, "testing/integration", false, "TestBeatsServerless")
2875+
return integRunner(ctx, "testing/integration/beats/serverless", false, "TestBeatsServerless")
28752876
}
28762877

28772878
// TestForResourceLeaks runs tests that check for resource leaks
@@ -2954,7 +2955,7 @@ func (Integration) TestOnRemote(ctx context.Context) error {
29542955

29552956
func (Integration) Buildkite() error {
29562957
goTestFlags := os.Getenv("GOTEST_FLAGS")
2957-
batches, err := define.DetermineBatches("testing/integration", goTestFlags, "integration")
2958+
batches, err := define.DetermineBatches("testing/integration/ess", goTestFlags, "integration")
29582959
if err != nil {
29592960
return fmt.Errorf("failed to determine batches: %w", err)
29602961
}

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())

0 commit comments

Comments
 (0)