Skip to content

Commit bfe5efc

Browse files
[9.0] (backport #8551) [test] split up ess and beats serverless integration tests (#8656)
* [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/beat_receivers_test.go # testing/integration/ess/endpoint_security_test.go # testing/integration/ess/fleetserver_fips_test.go # testing/integration/ess/upgrade_fleet_test.go * fix: resolve conflicts --------- Co-authored-by: Panos Koutsovasilis <[email protected]>
1 parent 1e99da1 commit bfe5efc

File tree

59 files changed

+322
-208
lines changed

Some content is hidden

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

59 files changed

+322
-208
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
@@ -156,6 +158,8 @@ steps:
156158
- label: "Win2022:non-sudo:{{matrix}}"
157159
depends_on:
158160
- packaging-windows
161+
env:
162+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
159163
command: |
160164
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
161165
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -175,6 +179,8 @@ steps:
175179
- label: "Win2025:sudo:{{matrix}}"
176180
depends_on:
177181
- packaging-windows
182+
env:
183+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
178184
command: |
179185
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
180186
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} true
@@ -201,6 +207,8 @@ steps:
201207
- label: "Win2025:non-sudo:{{matrix}}"
202208
depends_on:
203209
- packaging-windows
210+
env:
211+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
204212
command: |
205213
buildkite-agent artifact download build/distributions/** . --step 'packaging-windows'
206214
.buildkite/scripts/steps/integration_tests_tf.ps1 {{matrix}} false
@@ -227,6 +235,8 @@ steps:
227235
steps:
228236
- label: "x86_64:non-sudo: {{matrix}}"
229237
depends_on: packaging-ubuntu-x86-64
238+
env:
239+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
230240
command: |
231241
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
232242
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -247,6 +257,8 @@ steps:
247257
depends_on:
248258
- packaging-ubuntu-x86-64
249259
# due to deb group present in matrix tar.gz and deb packages artifacts are required
260+
env:
261+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
250262
command: |
251263
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
252264
.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
@@ -313,6 +327,8 @@ steps:
313327
skip: true
314328
depends_on:
315329
- packaging-ubuntu-arm64
330+
env:
331+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
316332
command: |
317333
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64'
318334
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -339,6 +355,8 @@ steps:
339355
steps:
340356
- label: "x86_64:non-sudo: {{matrix}}"
341357
depends_on: packaging-ubuntu-x86-64
358+
env:
359+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
342360
command: |
343361
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64'
344362
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
@@ -359,6 +377,8 @@ steps:
359377
depends_on:
360378
- packaging-ubuntu-x86-64
361379
# due to deb group present in matrix tar.gz and deb packages artifacts are required
380+
env:
381+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
362382
command: |
363383
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
364384
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
@@ -400,6 +420,8 @@ steps:
400420
- label: "x86_64:sudo:rpm"
401421
depends_on:
402422
- packaging-ubuntu-x86-64
423+
env:
424+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
403425
command: |
404426
buildkite-agent artifact download build/distributions/** . --step packaging-ubuntu-x86-64
405427
.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
@@ -2017,8 +2017,9 @@ func (Integration) Clean() error {
20172017
func (Integration) Check() error {
20182018
fmt.Println(">> check: Checking for define.Require in integration tests") // nolint:forbidigo // it's ok to use fmt.println in mage
20192019
return errors.Join(
2020-
define.ValidateDir("testing/integration"),
2020+
define.ValidateDir("testing/integration/ess"),
20212021
define.ValidateDir("testing/integration/serverless"),
2022+
define.ValidateDir("testing/integration/beats/serverless"),
20222023
define.ValidateDir("testing/integration/leak"),
20232024
define.ValidateDir("testing/integration/k8s"),
20242025
)
@@ -2078,17 +2079,17 @@ func (Integration) Auth(ctx context.Context) error {
20782079

20792080
// Test runs integration tests on remote hosts
20802081
func (Integration) Test(ctx context.Context) error {
2081-
return integRunner(ctx, "testing/integration", false, "")
2082+
return integRunner(ctx, "testing/integration/ess", false, "")
20822083
}
20832084

20842085
// Matrix runs integration tests on a matrix of all supported remote hosts
20852086
func (Integration) Matrix(ctx context.Context) error {
2086-
return integRunner(ctx, "testing/integration", true, "")
2087+
return integRunner(ctx, "testing/integration/ess", true, "")
20872088
}
20882089

20892090
// Single runs single integration test on remote host
20902091
func (Integration) Single(ctx context.Context, testName string) error {
2091-
return integRunner(ctx, "testing/integration", false, testName)
2092+
return integRunner(ctx, "testing/integration/ess", false, testName)
20922093
}
20932094

20942095
// TestServerless runs the integration tests defined in testing/integration/serverless
@@ -2643,7 +2644,7 @@ func (Integration) TestBeatServerless(ctx context.Context, beatname string) erro
26432644
if err != nil {
26442645
return fmt.Errorf("error setting binary name: %w", err)
26452646
}
2646-
return integRunner(ctx, "testing/integration", false, "TestBeatsServerless")
2647+
return integRunner(ctx, "testing/integration/beats/serverless", false, "TestBeatsServerless")
26472648
}
26482649

26492650
// TestForResourceLeaks runs tests that check for resource leaks
@@ -2726,7 +2727,7 @@ func (Integration) TestOnRemote(ctx context.Context) error {
27262727

27272728
func (Integration) Buildkite() error {
27282729
goTestFlags := os.Getenv("GOTEST_FLAGS")
2729-
batches, err := define.DetermineBatches("testing/integration", goTestFlags, "integration")
2730+
batches, err := define.DetermineBatches("testing/integration/ess", goTestFlags, "integration")
27302731
if err != nil {
27312732
return fmt.Errorf("failed to determine batches: %w", err)
27322733
}

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/auditd_monitoring_test.go renamed to testing/integration/ess/auditd_monitoring_test.go

Lines changed: 5 additions & 3 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
"context"
@@ -22,6 +22,7 @@ import (
2222
atesting "github.com/elastic/elastic-agent/pkg/testing"
2323
"github.com/elastic/elastic-agent/pkg/testing/define"
2424
"github.com/elastic/elastic-agent/pkg/testing/tools"
25+
"github.com/elastic/elastic-agent/testing/integration"
2526
)
2627

2728
type AuditDRunner struct {
@@ -34,7 +35,7 @@ type AuditDRunner struct {
3435

3536
func TestAuditdCorrectBinaries(t *testing.T) {
3637
info := define.Require(t, define.Requirements{
37-
Group: Fleet,
38+
Group: integration.Fleet,
3839
Stack: &define.Stack{},
3940
Local: false, // requires Agent installation
4041
Sudo: true, // requires Agent installation
@@ -75,7 +76,8 @@ func (runner *AuditDRunner) SetupSuite() {
7576
require.NoError(runner.T(), err)
7677

7778
packageFile := filepath.Join("testdata", "auditd_package.json")
78-
_, err = tools.InstallPackageFromDefaultFile(ctx, runner.info.KibanaClient, "auditd_manager", PreinstalledPackages["auditd_manager"], packageFile, uuid.Must(uuid.NewV4()).String(), policyResp.ID)
79+
_, err = tools.InstallPackageFromDefaultFile(ctx, runner.info.KibanaClient, "auditd_manager",
80+
integration.PreinstalledPackages["auditd_manager"], packageFile, uuid.Must(uuid.NewV4()).String(), policyResp.ID)
7981
require.NoError(runner.T(), err)
8082

8183
}

0 commit comments

Comments
 (0)