From eb7da88163c8c0285537d3060cd9209fe5d1d5dd Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 15 Jul 2024 12:36:31 +0300 Subject: [PATCH 01/16] added go based module definition --- .buildkite/heartbeat/heartbeat-pipeline.yml | 17 +-- .buildkite/libbeat/pipeline.libbeat.yml | 2 +- .buildkite/metricbeat/pipeline.yml | 17 +-- .../x-pack/pipeline.xpack.auditbeat.yml | 12 +- .../x-pack/pipeline.xpack.dockerlogbeat.yml | 6 +- .../x-pack/pipeline.xpack.metricbeat.yml | 27 ++-- .../x-pack/pipeline.xpack.winlogbeat.yml | 10 +- dev-tools/mage/module_changeset.go | 121 ++++++++++++++++++ metricbeat/magefile.go | 8 ++ .../cluster/cluster_integration_test.go | 2 + x-pack/auditbeat/auditbeat.reference.yml | 8 +- x-pack/auditbeat/magefile.go | 14 +- .../system/package/package_homebrew_test.go | 2 + x-pack/metricbeat/magefile.go | 8 ++ .../cloudfoundry/counter/counter_test.go | 2 + x-pack/winlogbeat/magefile.go | 5 + .../winlogbeat/module/wintest/docker_test.go | 2 + 17 files changed, 197 insertions(+), 66 deletions(-) create mode 100644 dev-tools/mage/module_changeset.go diff --git a/.buildkite/heartbeat/heartbeat-pipeline.yml b/.buildkite/heartbeat/heartbeat-pipeline.yml index 27cf5a0d847..53323f2b002 100644 --- a/.buildkite/heartbeat/heartbeat-pipeline.yml +++ b/.buildkite/heartbeat/heartbeat-pipeline.yml @@ -135,17 +135,9 @@ steps: - github_commit_status: context: "heartbeat: Win 2022 Unit Tests" + # Heartbeat has no modules - label: ":ubuntu: Heartbeat: Go Integration Tests" command: | - set -euo pipefail - echo "~~~ Installing @elastic/synthetics" - npm install -g @elastic/synthetics - - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet heartbeat - - echo "~~~ Running tests" cd heartbeat mage goIntegTest retry: @@ -162,14 +154,9 @@ steps: - github_commit_status: context: "heartbeat: Go Integration Tests" + # Heartbeat has no modules - label: ":ubuntu: Heartbeat: Python Integration Tests" command: | - set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet heartbeat - - echo "~~~ Running tests" cd heartbeat mage pythonIntegTest retry: diff --git a/.buildkite/libbeat/pipeline.libbeat.yml b/.buildkite/libbeat/pipeline.libbeat.yml index 0efad780523..bfa491ea063 100644 --- a/.buildkite/libbeat/pipeline.libbeat.yml +++ b/.buildkite/libbeat/pipeline.libbeat.yml @@ -67,7 +67,7 @@ steps: - "libbeat/build/*.json" notify: - github_commit_status: - context: "libbeat: Ununtu x86_64 Unit Tests" + context: "libbeat: Ubuntu x86_64 Unit Tests" - label: ":ubuntu: Libbeat: Go Integration Tests" key: "mandatory-int-test" diff --git a/.buildkite/metricbeat/pipeline.yml b/.buildkite/metricbeat/pipeline.yml index c6081bd4c29..12120e9c959 100644 --- a/.buildkite/metricbeat/pipeline.yml +++ b/.buildkite/metricbeat/pipeline.yml @@ -22,6 +22,9 @@ env: K8S_VERSION: "v1.29.0" ASDF_KIND_VERSION: "0.20.0" + # Module Tests + BEAT_PATH: "metricbeat" + # Other deps ASDF_MAGE_VERSION: 1.15.0 @@ -80,14 +83,10 @@ steps: - github_commit_status: context: "metricbeat: Ubuntu x86_64 Unit Tests" - - label: ":ubuntu: Metricbeat: Go Integration Tests" + - label: ":ubuntu: Metricbeat: Go Integration Tests (Module)" key: "mandatory-int-test" command: | set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet metricbeat - echo "~~~ Running tests" export KUBECONFIG="$$PWD/kubecfg" cd metricbeat @@ -104,16 +103,12 @@ steps: - "metricbeat/build/*.json" notify: - github_commit_status: - context: "metricbeat: Go Integration Tests" + context: "metricbeat: Go Integration Tests (Module)" - - label: ":ubuntu: Metricbeat: Python Integration Tests" + - label: ":ubuntu: Metricbeat: Python Integration Tests (Module)" key: "mandatory-python-int-test" command: | set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet metricbeat - echo "~~~ Running tests" export KUBECONFIG="$$PWD/kubecfg" cd metricbeat diff --git a/.buildkite/x-pack/pipeline.xpack.auditbeat.yml b/.buildkite/x-pack/pipeline.xpack.auditbeat.yml index 3e3baa4b138..40ff383bb83 100644 --- a/.buildkite/x-pack/pipeline.xpack.auditbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.auditbeat.yml @@ -26,6 +26,9 @@ env: RACE_DETECTOR: "true" TEST_COVERAGE: "true" + # Module tests + BEAT_PATH: "x-pack/auditbeat" + steps: - group: "Check/Update" key: "x-pack-auditbeat-check-update" @@ -59,14 +62,9 @@ steps: key: "x-pack-auditbeat-mandatory-tests" steps: - - label: ":ubuntu: x-pack/auditbeat: Build Tests" + - label: ":ubuntu: x-pack/auditbeat: Build Tests (Module)" key: "mandatory-linux-unit-test" command: | - set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet x-pack/auditbeat - echo "~~~ Running tests" cd x-pack/auditbeat mage update build test retry: @@ -81,7 +79,7 @@ steps: - "x-pack/auditbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/auditbeat: Build Tests" + context: "x-pack/auditbeat: Build Tests (Module)" - label: ":rhel: x-pack/auditbeat: RHEL9 Unit Tests" key: "mandatory-rhel9-unit-test" diff --git a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml index 30264774b63..49f3cda3b95 100644 --- a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml @@ -68,14 +68,10 @@ steps: - github_commit_status: context: "x-pack/dockerlogbeat: Ubuntu x86_64 Unit Tests" + # x-pack/dockerlogbeat has no modules - label: ":ubuntu: x-pack/dockerlogbeat: Go Integration Tests" key: "mandatory-int-test" command: | - set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet x-pack/dockerlogbeat - echo "~~~ Running tests" cd x-pack/dockerlogbeat mage goIntegTest retry: diff --git a/.buildkite/x-pack/pipeline.xpack.metricbeat.yml b/.buildkite/x-pack/pipeline.xpack.metricbeat.yml index 64ca511350d..4745f8d7d96 100644 --- a/.buildkite/x-pack/pipeline.xpack.metricbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.metricbeat.yml @@ -25,6 +25,9 @@ env: RACE_DETECTOR: "true" TEST_COVERAGE: "true" + # Module tests + BEAT_PATH: "x-pack/metricbeat" + steps: - group: "Check/Update" key: "x-pack-metricbeat-check-update" @@ -76,17 +79,13 @@ steps: - github_commit_status: context: "x-pack/metricbeat: Ubuntu x86_64 Unit Tests" - - label: ":ubuntu: x-pack/metricbeat: Go (MODULE) Integration Tests" + - label: ":ubuntu: x-pack/metricbeat: Go Integration Tests (Module)" key: "mandatory-int-test" env: TEST_TAGS: "oracle" command: | - set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Running tests" - cd x-pack/metricbeat && mage goIntegTest + cd x-pack/metricbeat + mage goIntegTest retry: automatic: - limit: 3 @@ -99,19 +98,15 @@ steps: - "x-pack/metricbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/metricbeat: Go (MODULE) Integration Tests" + context: "x-pack/metricbeat: Go Integration Tests (Module)" - - label: ":ubuntu: x-pack/metricbeat: Python (MODULE) Integration Tests" + - label: ":ubuntu: x-pack/metricbeat: Python Integration Tests (Module)" key: "mandatory-python-int-test" env: TEST_TAGS: "oracle" command: | - set -euo pipefail - # defines the MODULE env var based on what's changed in a PR - source .buildkite/scripts/changesets.sh - defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Running tests" - cd x-pack/metricbeat && mage pythonIntegTest + cd x-pack/metricbeat + mage pythonIntegTest retry: automatic: - limit: 3 @@ -124,7 +119,7 @@ steps: - "x-pack/metricbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/metricbeat: Python (MODULE) Integration Tests" + context: "x-pack/metricbeat: Python Integration Tests (Module)" - label: ":windows: x-pack/metricbeat: Win 2016 Unit Tests" command: | diff --git a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml index 7853f651670..ae168dd46d9 100644 --- a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml @@ -18,6 +18,9 @@ env: RACE_DETECTOR: "true" TEST_COVERAGE: "true" + # Module tests + BEAT_PATH: "x-pack/winlogbeat" + steps: - group: "Check/Update" key: "x-pack-winlogbeat-check-update" @@ -50,12 +53,9 @@ steps: key: "x-pack-winlogbeat-mandatory-tests" steps: - - label: ":windows: x-pack/winlogbeat Win 2019 Unit (MODULE) Tests" + - label: ":windows: x-pack/winlogbeat Win 2019 Unit Tests (Module)" key: "mandatory-win-2019-module-unit-tests" command: | - Import-Module ./.buildkite/scripts/changesets.psm1 - defineModuleFromTheChangeSet 'x-pack/winlogbeat' - Write-Output "~~~ Running tests" Set-Location -Path x-pack/winlogbeat mage build unitTest retry: @@ -72,7 +72,7 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat Win 2019 Unit (MODULE) Tests" + context: "x-pack/winlogbeat Win 2019 Unit Tests (Module)" - label: ":windows: x-pack/winlogbeat: Win 2016 Unit Tests" command: | diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go new file mode 100644 index 00000000000..fc41af1935b --- /dev/null +++ b/dev-tools/mage/module_changeset.go @@ -0,0 +1,121 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package mage + +import ( + "fmt" + "log" + "os" + "os/exec" + "regexp" + "strings" +) + +func DefineModules() { + beatPath := os.Getenv("BEAT_PATH") + if beatPath == "" { + fmt.Errorf("argument required: beatPath") + os.Exit(1) + } + + var modulePattern string + //if strings.Contains(beatPath, "x-pack") { + // modulePattern = "^x-pack\\/[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" + //} else { + // modulePattern = "^[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" + //} + modulePattern = fmt.Sprintf("^%s\\/module\\/([^\\/]+)\\/.*", beatPath) + + moduleRegex, err := regexp.Compile(modulePattern) + if err != nil { + log.Fatal("failed to compile regex: " + err.Error()) + } + + modules := make(map[string]bool) + for _, line := range getDiff() { + if !isAsciiOrPng(line) { + matches := moduleRegex.FindStringSubmatch(line) + if len(matches) > 0 { + modules[matches[1]] = true + } + } + } + + keys := make([]string, len(modules)) + i := 0 + for k := range modules { + keys[i] = k + i++ + } + + err = os.Setenv("MODULE", strings.Join(keys, ",")) +} + +func isAsciiOrPng(file string) bool { + return strings.HasSuffix(file, ".asciidoc") || strings.HasSuffix(file, ".png") +} + +func getDiff() []string { + commitRange := getCommitRange() + cmd := exec.Command("git", "diff", "--name-only", commitRange) + output, err := cmd.Output() + if err != nil { + fmt.Printf("Failed to execute 'git diff --name-only %s': %s", commitRange, err) + os.Exit(1) + } + + return strings.Split(string(output), "\n") +} + +func getFromCommit() string { + baseBranch := os.Getenv("BUILDKITE_PULL_REQUEST_BASE_BRANCH") + branch := os.Getenv("BUILDKITE_BRANCH") + commit := os.Getenv("BUILDKITE_COMMIT") + + if baseBranch != "" { + return fmt.Sprintf("origin/%s", baseBranch) + } + + if branch != "" { + return fmt.Sprintf("origin/%s", branch) + } + + previousCommit := getPreviousCommit() + if previousCommit != "" { + return previousCommit + } + + return commit +} + +func getPreviousCommit() string { + cmd := exec.Command("git", "rev-parse", "HEAD^") + output, err := cmd.Output() + if err != nil { + fmt.Println("Failed to execute 'git rev-parse HEAD^': ", err) + os.Exit(1) + } + + return strings.TrimSpace(string(output)) +} + +func getCommitRange() string { + commit := os.Getenv("BUILDKITE_COMMIT") + + return fmt.Sprintf("%s...%s", getFromCommit(), commit) +} diff --git a/metricbeat/magefile.go b/metricbeat/magefile.go index c3647359b29..7bf9f7de48b 100644 --- a/metricbeat/magefile.go +++ b/metricbeat/magefile.go @@ -214,6 +214,10 @@ func IntegTest() { // Use TEST_TAGS=tag1,tag2 to add additional build tags. // Use MODULE=module to run only tests for `module`. func GoIntegTest(ctx context.Context) error { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + if !devtools.IsInIntegTestEnv() { mg.SerialDeps(Fields, Dashboards) } @@ -226,6 +230,10 @@ func GoIntegTest(ctx context.Context) error { // Use PYTEST_ADDOPTS="-k pattern" to only run tests matching the specified pattern. // Use any other PYTEST_* environment variable to influence the behavior of pytest. func PythonIntegTest(ctx context.Context) error { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + if !devtools.IsInIntegTestEnv() { mg.SerialDeps(Fields, Dashboards) } diff --git a/metricbeat/module/couchbase/cluster/cluster_integration_test.go b/metricbeat/module/couchbase/cluster/cluster_integration_test.go index aeb101c1f7e..97934cbfc6e 100644 --- a/metricbeat/module/couchbase/cluster/cluster_integration_test.go +++ b/metricbeat/module/couchbase/cluster/cluster_integration_test.go @@ -20,6 +20,7 @@ package cluster import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -30,6 +31,7 @@ import ( ) func TestFetch(t *testing.T) { + fmt.Println("DELETEME") service := compose.EnsureUpWithTimeout(t, 120, "couchbase") f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host())) diff --git a/x-pack/auditbeat/auditbeat.reference.yml b/x-pack/auditbeat/auditbeat.reference.yml index 438ae307b80..ed82005f0eb 100644 --- a/x-pack/auditbeat/auditbeat.reference.yml +++ b/x-pack/auditbeat/auditbeat.reference.yml @@ -174,7 +174,7 @@ auditbeat.modules: # - file.pe.go_imports_names_entropy # - file.pe.go_imports_names_var_entropy # - file.pe.go_stripped - + # The system module collects security related information about a host. # All datasets send both periodic state information (e.g. all currently # running processes) and real-time changes (e.g. when a new process starts @@ -1245,7 +1245,7 @@ output.elasticsearch: # Permissions to use for file creation. The default is 0600. #permissions: 0600 - + # Configure automatic file rotation on every startup. The default is true. #rotate_on_startup: true @@ -1422,7 +1422,7 @@ setup.template.settings: # ======================== Data Stream Lifecycle (DSL) ========================= -# Configure Data Stream Lifecycle to manage data streams while connected to Serverless elasticsearch. +# Configure Data Stream Lifecycle to manage data streams while connected to Serverless elasticsearch. # These settings are mutually exclusive with ILM settings which are not supported in Serverless projects. # Enable DSL support. Valid values are true, or false. @@ -1430,7 +1430,7 @@ setup.template.settings: # Set the lifecycle policy name or pattern. For DSL, this name must match the data stream that the lifecycle is for. # The default data stream pattern is auditbeat-%{[agent.version]}" -# The template string `%{[agent.version]}` will resolve to the current stack version. +# The template string `%{[agent.version]}` will resolve to the current stack version. # The other possible template value is `%{[beat.name]}`. #setup.dsl.data_stream_pattern: "auditbeat-%{[agent.version]}" diff --git a/x-pack/auditbeat/magefile.go b/x-pack/auditbeat/magefile.go index 8ffcbf84c89..45b34095481 100644 --- a/x-pack/auditbeat/magefile.go +++ b/x-pack/auditbeat/magefile.go @@ -8,8 +8,11 @@ package main import ( "fmt" + "os" "time" + "github.com/elastic/beats/v7/dev-tools/mage/target/test" + "github.com/magefile/mage/mg" "go.uber.org/multierr" @@ -25,8 +28,6 @@ import ( _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest" //mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/docker" - //mage:import - _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) func init() { @@ -151,3 +152,12 @@ func ExportDashboard() error { func Dashboards() error { return devtools.KibanaDashboards(devtools.OSSBeatDir("module"), "module") } + +// Test runs all available tests (unitTest + integTest) +func Test() { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + + test.Test() +} diff --git a/x-pack/auditbeat/module/system/package/package_homebrew_test.go b/x-pack/auditbeat/module/system/package/package_homebrew_test.go index 3eeb7f3d14e..d7f60079f9d 100644 --- a/x-pack/auditbeat/module/system/package/package_homebrew_test.go +++ b/x-pack/auditbeat/module/system/package/package_homebrew_test.go @@ -7,6 +7,7 @@ package pkg import ( + "fmt" "os" "runtime" "testing" @@ -21,6 +22,7 @@ import ( ) func TestHomebrew(t *testing.T) { + fmt.Println("DELETEME") defer abtest.SetupDataDir(t)() oldPath := homebrewCellarPath diff --git a/x-pack/metricbeat/magefile.go b/x-pack/metricbeat/magefile.go index dfcc1a794c5..1de1a064d1f 100644 --- a/x-pack/metricbeat/magefile.go +++ b/x-pack/metricbeat/magefile.go @@ -234,6 +234,10 @@ func IntegTest() { // Use TEST_TAGS=tag1,tag2 to add additional build tags. // Use MODULE=module to run only tests for `module`. func GoIntegTest(ctx context.Context) error { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + if !devtools.IsInIntegTestEnv() { mg.SerialDeps(Fields, Dashboards) } @@ -246,6 +250,10 @@ func GoIntegTest(ctx context.Context) error { // Use PYTEST_ADDOPTS="-k pattern" to only run tests matching the specified pattern. // Use any other PYTEST_* environment variable to influence the behavior of pytest. func PythonIntegTest(ctx context.Context) error { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + if !devtools.IsInIntegTestEnv() { mg.SerialDeps(Fields, Dashboards) } diff --git a/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go b/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go index 43586d5d26d..f01d75e5843 100644 --- a/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go +++ b/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go @@ -7,6 +7,7 @@ package counter import ( + "fmt" "testing" "time" @@ -37,6 +38,7 @@ func newTestMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) { } func TestMetricSet(t *testing.T) { + fmt.Println("DELETEME") logp.TestingSetup(logp.WithSelectors("cloudfoundry")) config := map[string]interface{}{ diff --git a/x-pack/winlogbeat/magefile.go b/x-pack/winlogbeat/magefile.go index 304a736136e..a3b592bd8b5 100644 --- a/x-pack/winlogbeat/magefile.go +++ b/x-pack/winlogbeat/magefile.go @@ -9,6 +9,7 @@ package main import ( "context" "fmt" + "os" "github.com/magefile/mage/mg" @@ -49,6 +50,10 @@ func RegisterPythonTestDeps(deps ...interface{}) { // UnitTest executes the unit tests (Go and Python). func UnitTest() { + if os.Getenv("CI") == "true" { + mg.Deps(devtools.DefineModules) + } + mg.SerialDeps(GoUnitTest, PythonUnitTest) } diff --git a/x-pack/winlogbeat/module/wintest/docker_test.go b/x-pack/winlogbeat/module/wintest/docker_test.go index e45826f3b08..806a592944b 100644 --- a/x-pack/winlogbeat/module/wintest/docker_test.go +++ b/x-pack/winlogbeat/module/wintest/docker_test.go @@ -13,6 +13,7 @@ package wintest_test import ( "bytes" "context" + "fmt" "io" "net/http" "regexp" @@ -32,6 +33,7 @@ import ( ) func TestDocker(t *testing.T) { + fmt.Println("DELETEME") const ( host = "http://localhost:9200" user = "admin" From e88b1cb0f27c7d0c91a9d39409920c32209e1bc8 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 22 Jul 2024 12:15:26 +0300 Subject: [PATCH 02/16] updated module_changeset.go --- .buildkite/heartbeat/heartbeat-pipeline.yml | 2 +- .../x-pack/pipeline.xpack.dockerlogbeat.yml | 2 +- .../x-pack/pipeline.xpack.winlogbeat.yml | 18 +++++++++--------- dev-tools/mage/module_changeset.go | 8 +------- x-pack/auditbeat/auditbeat.reference.yml | 8 ++++---- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.buildkite/heartbeat/heartbeat-pipeline.yml b/.buildkite/heartbeat/heartbeat-pipeline.yml index 53323f2b002..1eeba29a60c 100644 --- a/.buildkite/heartbeat/heartbeat-pipeline.yml +++ b/.buildkite/heartbeat/heartbeat-pipeline.yml @@ -154,7 +154,7 @@ steps: - github_commit_status: context: "heartbeat: Go Integration Tests" - # Heartbeat has no modules + # Heartbeat has no modules yet - label: ":ubuntu: Heartbeat: Python Integration Tests" command: | cd heartbeat diff --git a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml index 49f3cda3b95..4ca750e76e8 100644 --- a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml @@ -68,7 +68,7 @@ steps: - github_commit_status: context: "x-pack/dockerlogbeat: Ubuntu x86_64 Unit Tests" - # x-pack/dockerlogbeat has no modules + # x-pack/dockerlogbeat has no modules yet - label: ":ubuntu: x-pack/dockerlogbeat: Go Integration Tests" key: "mandatory-int-test" command: | diff --git a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml index ae168dd46d9..8c576e89fe3 100644 --- a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml @@ -74,7 +74,7 @@ steps: - github_commit_status: context: "x-pack/winlogbeat Win 2019 Unit Tests (Module)" - - label: ":windows: x-pack/winlogbeat: Win 2016 Unit Tests" + - label: ":windows: x-pack/winlogbeat: Win 2016 Unit Tests (Module)" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -93,9 +93,9 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2016 Unit Tests" + context: "x-pack/winlogbeat: Win 2016 Unit Tests (Module)" - - label: ":windows: x-pack/winlogbeat: Win 2022 Unit Tests" + - label: ":windows: x-pack/winlogbeat: Win 2022 Unit Tests (Module)" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -114,14 +114,14 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2022 Unit Tests" + context: "x-pack/winlogbeat: Win 2022 Unit Tests (Module)" - group: "Extended Windows Tests" key: "extended-win-tests" if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*[Ww]indows.*/ steps: - - label: ":windows: x-pack/winlogbeat: Win 10 Unit Tests" + - label: ":windows: x-pack/winlogbeat: Win 10 Unit Tests (Module)" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -140,9 +140,9 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 10 Unit Tests" + context: "x-pack/winlogbeat: Win 10 Unit Tests (Module)" - - label: ":windows: x-pack/winlogbeat: Win 11 Unit Tests" + - label: ":windows: x-pack/winlogbeat: Win 11 Unit Tests (Module)" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -163,7 +163,7 @@ steps: - github_commit_status: context: "x-pack/winlogbeat: Win 11 Unit Tests" - - label: ":windows: x-pack/winlogbeat: Win 2019 Unit Tests" + - label: ":windows: x-pack/winlogbeat: Win 2019 Unit Tests (Module)" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -182,7 +182,7 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2019 Unit Tests" + context: "x-pack/winlogbeat: Win 2019 Unit Tests (Module)" - wait: ~ # with PRs, we want to run packaging only if mandatory tests succeed diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index fc41af1935b..5eef73ec5d6 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -29,16 +29,10 @@ import ( func DefineModules() { beatPath := os.Getenv("BEAT_PATH") if beatPath == "" { - fmt.Errorf("argument required: beatPath") - os.Exit(1) + panic(fmt.Errorf("argument required: beatPath")) } var modulePattern string - //if strings.Contains(beatPath, "x-pack") { - // modulePattern = "^x-pack\\/[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" - //} else { - // modulePattern = "^[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" - //} modulePattern = fmt.Sprintf("^%s\\/module\\/([^\\/]+)\\/.*", beatPath) moduleRegex, err := regexp.Compile(modulePattern) diff --git a/x-pack/auditbeat/auditbeat.reference.yml b/x-pack/auditbeat/auditbeat.reference.yml index ed82005f0eb..438ae307b80 100644 --- a/x-pack/auditbeat/auditbeat.reference.yml +++ b/x-pack/auditbeat/auditbeat.reference.yml @@ -174,7 +174,7 @@ auditbeat.modules: # - file.pe.go_imports_names_entropy # - file.pe.go_imports_names_var_entropy # - file.pe.go_stripped - + # The system module collects security related information about a host. # All datasets send both periodic state information (e.g. all currently # running processes) and real-time changes (e.g. when a new process starts @@ -1245,7 +1245,7 @@ output.elasticsearch: # Permissions to use for file creation. The default is 0600. #permissions: 0600 - + # Configure automatic file rotation on every startup. The default is true. #rotate_on_startup: true @@ -1422,7 +1422,7 @@ setup.template.settings: # ======================== Data Stream Lifecycle (DSL) ========================= -# Configure Data Stream Lifecycle to manage data streams while connected to Serverless elasticsearch. +# Configure Data Stream Lifecycle to manage data streams while connected to Serverless elasticsearch. # These settings are mutually exclusive with ILM settings which are not supported in Serverless projects. # Enable DSL support. Valid values are true, or false. @@ -1430,7 +1430,7 @@ setup.template.settings: # Set the lifecycle policy name or pattern. For DSL, this name must match the data stream that the lifecycle is for. # The default data stream pattern is auditbeat-%{[agent.version]}" -# The template string `%{[agent.version]}` will resolve to the current stack version. +# The template string `%{[agent.version]}` will resolve to the current stack version. # The other possible template value is `%{[beat.name]}`. #setup.dsl.data_stream_pattern: "auditbeat-%{[agent.version]}" From 2d7e9d588f60f0a896c5906d18d763f4d55c15da Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Wed, 24 Jul 2024 12:40:51 +0300 Subject: [PATCH 03/16] removed module definition for unit tests --- .../x-pack/pipeline.xpack.winlogbeat.yml | 27 +++++++++---------- .../cluster/cluster_integration_test.go | 2 -- .../system/package/package_homebrew_test.go | 2 -- .../cloudfoundry/counter/counter_test.go | 2 -- x-pack/winlogbeat/magefile.go | 5 ---- .../winlogbeat/module/wintest/docker_test.go | 2 -- 6 files changed, 12 insertions(+), 28 deletions(-) diff --git a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml index 8c576e89fe3..af48078c1d6 100644 --- a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml @@ -18,9 +18,6 @@ env: RACE_DETECTOR: "true" TEST_COVERAGE: "true" - # Module tests - BEAT_PATH: "x-pack/winlogbeat" - steps: - group: "Check/Update" key: "x-pack-winlogbeat-check-update" @@ -53,8 +50,8 @@ steps: key: "x-pack-winlogbeat-mandatory-tests" steps: - - label: ":windows: x-pack/winlogbeat Win 2019 Unit Tests (Module)" - key: "mandatory-win-2019-module-unit-tests" + - label: ":windows: x-pack/winlogbeat Win 2019 Unit Tests" + key: "mandatory-win-2019-unit-tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -72,9 +69,9 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat Win 2019 Unit Tests (Module)" + context: "x-pack/winlogbeat Win 2019 Unit Tests" - - label: ":windows: x-pack/winlogbeat: Win 2016 Unit Tests (Module)" + - label: ":windows: x-pack/winlogbeat: Win 2016 Unit Tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -93,9 +90,9 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2016 Unit Tests (Module)" + context: "x-pack/winlogbeat: Win 2016 Unit Tests" - - label: ":windows: x-pack/winlogbeat: Win 2022 Unit Tests (Module)" + - label: ":windows: x-pack/winlogbeat: Win 2022 Unit Tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -114,14 +111,14 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2022 Unit Tests (Module)" + context: "x-pack/winlogbeat: Win 2022 Unit Tests" - group: "Extended Windows Tests" key: "extended-win-tests" if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*[Ww]indows.*/ steps: - - label: ":windows: x-pack/winlogbeat: Win 10 Unit Tests (Module)" + - label: ":windows: x-pack/winlogbeat: Win 10 Unit Tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -140,9 +137,9 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 10 Unit Tests (Module)" + context: "x-pack/winlogbeat: Win 10 Unit Tests" - - label: ":windows: x-pack/winlogbeat: Win 11 Unit Tests (Module)" + - label: ":windows: x-pack/winlogbeat: Win 11 Unit Tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -163,7 +160,7 @@ steps: - github_commit_status: context: "x-pack/winlogbeat: Win 11 Unit Tests" - - label: ":windows: x-pack/winlogbeat: Win 2019 Unit Tests (Module)" + - label: ":windows: x-pack/winlogbeat: Win 2019 Unit Tests" command: | Set-Location -Path x-pack/winlogbeat mage build unitTest @@ -182,7 +179,7 @@ steps: - "x-pack/winlogbeat/build/*.json" notify: - github_commit_status: - context: "x-pack/winlogbeat: Win 2019 Unit Tests (Module)" + context: "x-pack/winlogbeat: Win 2019 Unit Tests" - wait: ~ # with PRs, we want to run packaging only if mandatory tests succeed diff --git a/metricbeat/module/couchbase/cluster/cluster_integration_test.go b/metricbeat/module/couchbase/cluster/cluster_integration_test.go index 97934cbfc6e..aeb101c1f7e 100644 --- a/metricbeat/module/couchbase/cluster/cluster_integration_test.go +++ b/metricbeat/module/couchbase/cluster/cluster_integration_test.go @@ -20,7 +20,6 @@ package cluster import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -31,7 +30,6 @@ import ( ) func TestFetch(t *testing.T) { - fmt.Println("DELETEME") service := compose.EnsureUpWithTimeout(t, 120, "couchbase") f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host())) diff --git a/x-pack/auditbeat/module/system/package/package_homebrew_test.go b/x-pack/auditbeat/module/system/package/package_homebrew_test.go index d7f60079f9d..3eeb7f3d14e 100644 --- a/x-pack/auditbeat/module/system/package/package_homebrew_test.go +++ b/x-pack/auditbeat/module/system/package/package_homebrew_test.go @@ -7,7 +7,6 @@ package pkg import ( - "fmt" "os" "runtime" "testing" @@ -22,7 +21,6 @@ import ( ) func TestHomebrew(t *testing.T) { - fmt.Println("DELETEME") defer abtest.SetupDataDir(t)() oldPath := homebrewCellarPath diff --git a/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go b/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go index f01d75e5843..43586d5d26d 100644 --- a/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go +++ b/x-pack/metricbeat/module/cloudfoundry/counter/counter_test.go @@ -7,7 +7,6 @@ package counter import ( - "fmt" "testing" "time" @@ -38,7 +37,6 @@ func newTestMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) { } func TestMetricSet(t *testing.T) { - fmt.Println("DELETEME") logp.TestingSetup(logp.WithSelectors("cloudfoundry")) config := map[string]interface{}{ diff --git a/x-pack/winlogbeat/magefile.go b/x-pack/winlogbeat/magefile.go index a3b592bd8b5..304a736136e 100644 --- a/x-pack/winlogbeat/magefile.go +++ b/x-pack/winlogbeat/magefile.go @@ -9,7 +9,6 @@ package main import ( "context" "fmt" - "os" "github.com/magefile/mage/mg" @@ -50,10 +49,6 @@ func RegisterPythonTestDeps(deps ...interface{}) { // UnitTest executes the unit tests (Go and Python). func UnitTest() { - if os.Getenv("CI") == "true" { - mg.Deps(devtools.DefineModules) - } - mg.SerialDeps(GoUnitTest, PythonUnitTest) } diff --git a/x-pack/winlogbeat/module/wintest/docker_test.go b/x-pack/winlogbeat/module/wintest/docker_test.go index 806a592944b..e45826f3b08 100644 --- a/x-pack/winlogbeat/module/wintest/docker_test.go +++ b/x-pack/winlogbeat/module/wintest/docker_test.go @@ -13,7 +13,6 @@ package wintest_test import ( "bytes" "context" - "fmt" "io" "net/http" "regexp" @@ -33,7 +32,6 @@ import ( ) func TestDocker(t *testing.T) { - fmt.Println("DELETEME") const ( host = "http://localhost:9200" user = "admin" From 0de4a1afb0ce2a27dbea77b97a67d1211a09c215 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 25 Jul 2024 11:07:52 +0300 Subject: [PATCH 04/16] updated module_changeset.go --- .buildkite/scripts/changesets.psm1 | 64 ------------------------------ dev-tools/mage/module_changeset.go | 48 +++++++++++++--------- 2 files changed, 29 insertions(+), 83 deletions(-) delete mode 100644 .buildkite/scripts/changesets.psm1 diff --git a/.buildkite/scripts/changesets.psm1 b/.buildkite/scripts/changesets.psm1 deleted file mode 100644 index 10e4d31a8b6..00000000000 --- a/.buildkite/scripts/changesets.psm1 +++ /dev/null @@ -1,64 +0,0 @@ -function ArePathsChanged($patterns) { - $changedlist = @() - foreach ($pattern in $patterns) { - $changedFiles = & git diff --name-only "HEAD@{1}" HEAD | Select-String -Pattern $pattern -SimpleMatch - if ($changedFiles) { - $changedlist += $changedFiles - } - } - if ($changedlist) { - Write-Host "--- Files changed: $changedlist" - return $true - } - else { - Write-Host "--- No files changed within specified changeset: $patterns" - return $false - } -} - -function AreChangedOnlyPaths($patterns) { - $changedFiles = & git diff --name-only "HEAD@{1}" HEAD - Write-Host "--- Git Diff result:" - Write-Host "$changedFiles" - - $matchedFiles = @() - foreach ($pattern in $patterns) { - $matched = $changedFiles | Select-String -Pattern $pattern -SimpleMatch - if ($matched) { - $matchedFiles += $matched - } - } - if (($matchedFiles.Count -eq $changedFiles.Count) -or ($changedFiles.Count -eq 0)) { - return $true - } - return $false -} - -# This function sets a `MODULE` env var, required by IT tests, containing a comma separated list of modules for a given beats project (specified via the first argument). -# The list is built depending on directories that have changed under `modules/` excluding anything else such as asciidoc and png files. -# `MODULE` will empty if no changes apply. -function DefineModuleFromTheChangeSet($projectPath) { - $projectPathTransformed = $projectPath -replace '/', '\\' - $projectPathExclusion = "((?!^$projectPathTransformed\\\/).)*\$" - $exclude = @("^($projectPathExclusion|((?!\\/module\\/).)*\$|.*\\.asciidoc|.*\\.png)") - - $changedModules = '' - - $moduleDirs = Get-ChildItem -Directory "$projectPath\module" - foreach($moduleDir in $moduleDirs) { - if((ArePathsChanged($moduleDir)) -and !(AreChangedOnlyPaths($exclude))) { - if(!$changedModules) { - $changedModules = $moduleDir.Name - } - else { - $changedModules += ',' + $moduleDir.Name - } - } - } - - if ($changedModules) { - $env:MODULE = $changedModules - Write-Output "~~~ Set env var MODULE to [$env:MODULE]" - Write-Output "~~~ Resuming commands" - } -} diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index 5eef73ec5d6..596bb485715 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -21,19 +21,21 @@ import ( "fmt" "log" "os" - "os/exec" "regexp" "strings" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" ) func DefineModules() { - beatPath := os.Getenv("BEAT_PATH") - if beatPath == "" { - panic(fmt.Errorf("argument required: beatPath")) + if mg.Verbose() { + fmt.Printf("Detecting changes in modules\n") } - var modulePattern string - modulePattern = fmt.Sprintf("^%s\\/module\\/([^\\/]+)\\/.*", beatPath) + beatPath := os.Getenv("BEAT_PATH") + + var modulePattern = fmt.Sprintf("^%s\\/module\\/([^\\/]+)\\/.*", beatPath) moduleRegex, err := regexp.Compile(modulePattern) if err != nil { @@ -57,7 +59,14 @@ func DefineModules() { i++ } - err = os.Setenv("MODULE", strings.Join(keys, ",")) + moduleVar := strings.Join(keys, ",") + + err = os.Setenv("MODULE", moduleVar) + if err != nil { + return + } + + _, _ = fmt.Fprintf(os.Stderr, "Detected changes in module(s): %s\n", moduleVar) } func isAsciiOrPng(file string) bool { @@ -66,14 +75,13 @@ func isAsciiOrPng(file string) bool { func getDiff() []string { commitRange := getCommitRange() - cmd := exec.Command("git", "diff", "--name-only", commitRange) - output, err := cmd.Output() - if err != nil { - fmt.Printf("Failed to execute 'git diff --name-only %s': %s", commitRange, err) - os.Exit(1) + var output, _ = sh.Output("git", "diff", "--name-only", commitRange) + + if mg.Verbose() { + _ = fmt.Sprintf("Git Diff result: %s\n", output) } - return strings.Split(string(output), "\n") + return strings.Split(output, "\n") } func getFromCommit() string { @@ -94,18 +102,20 @@ func getFromCommit() string { return previousCommit } + if mg.Verbose() { + _ = fmt.Sprintf("Git from commit: %s", commit) + } + return commit } func getPreviousCommit() string { - cmd := exec.Command("git", "rev-parse", "HEAD^") - output, err := cmd.Output() - if err != nil { - fmt.Println("Failed to execute 'git rev-parse HEAD^': ", err) - os.Exit(1) + var output, _ = sh.Output("git", "rev-parse", "HEAD^") + if mg.Verbose() { + _ = fmt.Sprintf("Git previous commit: %s\n", output) } - return strings.TrimSpace(string(output)) + return strings.TrimSpace(output) } func getCommitRange() string { From 8e019ecb33035bfcdf39b9826323b371af99fa80 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Fri, 26 Jul 2024 19:57:44 +0300 Subject: [PATCH 05/16] added skip condition in module_changeset.sh --- dev-tools/mage/module_changeset.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index 596bb485715..c3fcdb75a09 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -29,6 +29,11 @@ import ( ) func DefineModules() { + // If MODULE is set in Buildkite pipeline step, skip variable further definition + if os.Getenv("MODULE") != "" { + return + } + if mg.Verbose() { fmt.Printf("Detecting changes in modules\n") } From 25a2b19a756aafd0d80270257e7b25f636165de6 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 29 Jul 2024 12:45:59 +0300 Subject: [PATCH 06/16] added condition for module env var set up --- dev-tools/mage/module_changeset.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index c3fcdb75a09..c5771fd16aa 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -66,12 +66,14 @@ func DefineModules() { moduleVar := strings.Join(keys, ",") - err = os.Setenv("MODULE", moduleVar) - if err != nil { - return - } + if moduleVar != "" { + err = os.Setenv("MODULE", moduleVar) + if err != nil { + return + } - _, _ = fmt.Fprintf(os.Stderr, "Detected changes in module(s): %s\n", moduleVar) + _, _ = fmt.Fprintf(os.Stderr, "Detected changes in module(s): %s\n", moduleVar) + } } func isAsciiOrPng(file string) bool { From 462524291cdc954e1a81af46e0036d2bca8d71b5 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Wed, 14 Aug 2024 12:25:36 +0300 Subject: [PATCH 07/16] replaced map with struct --- dev-tools/mage/module_changeset.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index c5771fd16aa..dda376c7126 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -47,12 +47,12 @@ func DefineModules() { log.Fatal("failed to compile regex: " + err.Error()) } - modules := make(map[string]bool) + modules := map[string]struct{}{} for _, line := range getDiff() { if !isAsciiOrPng(line) { matches := moduleRegex.FindStringSubmatch(line) if len(matches) > 0 { - modules[matches[1]] = true + modules[matches[1]] = struct{}{} } } } From 29b3a48b14fe50091abed8d140360614a6eb28a0 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 15 Aug 2024 14:53:07 +0300 Subject: [PATCH 08/16] updated module_changeset.go --- dev-tools/mage/module_changeset.go | 61 ++++++++++++------- metricbeat/module/aerospike/aerospike_test.go | 6 ++ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index dda376c7126..b49aaefa3ba 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -28,6 +28,9 @@ import ( "github.com/magefile/mage/sh" ) +// DefineModules checks which modules were changed and populates MODULE environment variable, +// so that CI would run tests only for the changed ones. +// If no modules were changed MODULE variable won't be defined. func DefineModules() { // If MODULE is set in Buildkite pipeline step, skip variable further definition if os.Getenv("MODULE") != "" { @@ -49,7 +52,7 @@ func DefineModules() { modules := map[string]struct{}{} for _, line := range getDiff() { - if !isAsciiOrPng(line) { + if !shouldIgnore(line) { matches := moduleRegex.FindStringSubmatch(line) if len(matches) > 0 { modules[matches[1]] = struct{}{} @@ -72,48 +75,54 @@ func DefineModules() { return } - _, _ = fmt.Fprintf(os.Stderr, "Detected changes in module(s): %s\n", moduleVar) + _, _ = fmt.Fprintf(os.Stdout, "Detected changes in module(s): %s\n", moduleVar) + } else { + fmt.Print("No changed modules found") } } -func isAsciiOrPng(file string) bool { - return strings.HasSuffix(file, ".asciidoc") || strings.HasSuffix(file, ".png") +func shouldIgnore(file string) bool { + ignoreList := []string{".asciidoc", ".png"} + for ext := range ignoreList { + if strings.HasSuffix(file, ignoreList[ext]) { + return true + } + } + return false } func getDiff() []string { commitRange := getCommitRange() var output, _ = sh.Output("git", "diff", "--name-only", commitRange) - if mg.Verbose() { - _ = fmt.Sprintf("Git Diff result: %s\n", output) - } + printWhenVerbose("Git Diff result: %s\n", output) return strings.Split(output, "\n") } func getFromCommit() string { - baseBranch := os.Getenv("BUILDKITE_PULL_REQUEST_BASE_BRANCH") - branch := os.Getenv("BUILDKITE_BRANCH") - commit := os.Getenv("BUILDKITE_COMMIT") + if baseBranch := os.Getenv("BUILDKITE_PULL_REQUEST_BASE_BRANCH"); baseBranch != "" { + printWhenVerbose("PR branch: %s\n", baseBranch) - if baseBranch != "" { - return fmt.Sprintf("origin/%s", baseBranch) + return getBranchName(baseBranch) } - if branch != "" { - return fmt.Sprintf("origin/%s", branch) + if branch := os.Getenv("BUILDKITE_BRANCH"); branch != "" { + printWhenVerbose("Target branch: %s\n", branch) + + return getBranchName(branch) } - previousCommit := getPreviousCommit() - if previousCommit != "" { + if previousCommit := getPreviousCommit(); previousCommit != "" { + printWhenVerbose("Git from commit: %s\n", previousCommit) + return previousCommit - } + } else { + commit := os.Getenv("BUILDKITE_COMMIT") + printWhenVerbose("Git from commit: %s\n", commit) - if mg.Verbose() { - _ = fmt.Sprintf("Git from commit: %s", commit) + return commit } - - return commit } func getPreviousCommit() string { @@ -130,3 +139,13 @@ func getCommitRange() string { return fmt.Sprintf("%s...%s", getFromCommit(), commit) } + +func getBranchName(branch string) string { + return fmt.Sprintf("origin/%s", branch) +} + +func printWhenVerbose(template string, parameter string) { + if mg.Verbose() { + _ = fmt.Sprintf(template, parameter) + } +} diff --git a/metricbeat/module/aerospike/aerospike_test.go b/metricbeat/module/aerospike/aerospike_test.go index 9dbcbeec4a5..80222a5c787 100644 --- a/metricbeat/module/aerospike/aerospike_test.go +++ b/metricbeat/module/aerospike/aerospike_test.go @@ -19,6 +19,8 @@ package aerospike import ( "errors" + "fmt" + "github.com/magefile/mage/mg" "testing" "github.com/stretchr/testify/assert" @@ -104,6 +106,10 @@ func pointer[T any](d T) *T { } func TestParseClientPolicy(t *testing.T) { + if mg.Verbose() { + fmt.Printf("DELETEME\n") + } + sampleClusterName := "TestCluster" TLSPolicy := as.NewClientPolicy() From e58d0312a3bbdd3ba5a12494ebf24de1cd2d8783 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 15 Aug 2024 15:04:02 +0300 Subject: [PATCH 09/16] temporarily disabled checks for metricbeat --- .buildkite/metricbeat/pipeline.yml | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.buildkite/metricbeat/pipeline.yml b/.buildkite/metricbeat/pipeline.yml index 12120e9c959..75a987d1467 100644 --- a/.buildkite/metricbeat/pipeline.yml +++ b/.buildkite/metricbeat/pipeline.yml @@ -33,32 +33,32 @@ env: TEST_COVERAGE: "true" steps: - - group: "Check/Update" - key: "metricbeat-check-update" - steps: - - label: "Metricbeat: Run check/update" - command: | - set -eo pipefail - make -C metricbeat check update - make check-no-changes - retry: - automatic: - - limit: 3 - agents: - image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:latest" - cpu: "4000m" - memory: "8Gi" - useCustomGlobalHooks: true - notify: - - github_commit_status: - context: "metricbeat: check/update" - - - wait: ~ - # with PRs, we want to run mandatory tests only if check/update step succeed - # for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests - # this allows building DRA artifacts even if there is flakiness in check/update step - if: build.env("BUILDKITE_PULL_REQUEST") != "false" - depends_on: "metricbeat-check-update" +# - group: "Check/Update" +# key: "metricbeat-check-update" +# steps: +# - label: "Metricbeat: Run check/update" +# command: | +# set -eo pipefail +# make -C metricbeat check update +# make check-no-changes +# retry: +# automatic: +# - limit: 3 +# agents: +# image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:latest" +# cpu: "4000m" +# memory: "8Gi" +# useCustomGlobalHooks: true +# notify: +# - github_commit_status: +# context: "metricbeat: check/update" +# +# - wait: ~ +# # with PRs, we want to run mandatory tests only if check/update step succeed +# # for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests +# # this allows building DRA artifacts even if there is flakiness in check/update step +# if: build.env("BUILDKITE_PULL_REQUEST") != "false" +# depends_on: "metricbeat-check-update" - group: "Mandatory Tests" key: "metricbeat-mandatory-tests" From 28ba8b4339f1b67d72d6c1429e90c828a6f45668 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 15 Aug 2024 16:35:31 +0300 Subject: [PATCH 10/16] restored pipeline and aerospike tests --- .buildkite/metricbeat/pipeline.yml | 52 +++++++++---------- metricbeat/module/aerospike/aerospike_test.go | 6 --- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/.buildkite/metricbeat/pipeline.yml b/.buildkite/metricbeat/pipeline.yml index 75a987d1467..12120e9c959 100644 --- a/.buildkite/metricbeat/pipeline.yml +++ b/.buildkite/metricbeat/pipeline.yml @@ -33,32 +33,32 @@ env: TEST_COVERAGE: "true" steps: -# - group: "Check/Update" -# key: "metricbeat-check-update" -# steps: -# - label: "Metricbeat: Run check/update" -# command: | -# set -eo pipefail -# make -C metricbeat check update -# make check-no-changes -# retry: -# automatic: -# - limit: 3 -# agents: -# image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:latest" -# cpu: "4000m" -# memory: "8Gi" -# useCustomGlobalHooks: true -# notify: -# - github_commit_status: -# context: "metricbeat: check/update" -# -# - wait: ~ -# # with PRs, we want to run mandatory tests only if check/update step succeed -# # for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests -# # this allows building DRA artifacts even if there is flakiness in check/update step -# if: build.env("BUILDKITE_PULL_REQUEST") != "false" -# depends_on: "metricbeat-check-update" + - group: "Check/Update" + key: "metricbeat-check-update" + steps: + - label: "Metricbeat: Run check/update" + command: | + set -eo pipefail + make -C metricbeat check update + make check-no-changes + retry: + automatic: + - limit: 3 + agents: + image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:latest" + cpu: "4000m" + memory: "8Gi" + useCustomGlobalHooks: true + notify: + - github_commit_status: + context: "metricbeat: check/update" + + - wait: ~ + # with PRs, we want to run mandatory tests only if check/update step succeed + # for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests + # this allows building DRA artifacts even if there is flakiness in check/update step + if: build.env("BUILDKITE_PULL_REQUEST") != "false" + depends_on: "metricbeat-check-update" - group: "Mandatory Tests" key: "metricbeat-mandatory-tests" diff --git a/metricbeat/module/aerospike/aerospike_test.go b/metricbeat/module/aerospike/aerospike_test.go index 80222a5c787..9dbcbeec4a5 100644 --- a/metricbeat/module/aerospike/aerospike_test.go +++ b/metricbeat/module/aerospike/aerospike_test.go @@ -19,8 +19,6 @@ package aerospike import ( "errors" - "fmt" - "github.com/magefile/mage/mg" "testing" "github.com/stretchr/testify/assert" @@ -106,10 +104,6 @@ func pointer[T any](d T) *T { } func TestParseClientPolicy(t *testing.T) { - if mg.Verbose() { - fmt.Printf("DELETEME\n") - } - sampleClusterName := "TestCluster" TLSPolicy := as.NewClientPolicy() From 9c0b4e27cc785caf87ba1e2e6a39a1f0744bfdb1 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Tue, 10 Sep 2024 17:03:49 +0300 Subject: [PATCH 11/16] pr fixes --- dev-tools/mage/module_changeset.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index b49aaefa3ba..35dafdfb134 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -42,6 +42,9 @@ func DefineModules() { } beatPath := os.Getenv("BEAT_PATH") + if beatPath == "" { + log.Fatal("BEAT_PATH is not defined") + } var modulePattern = fmt.Sprintf("^%s\\/module\\/([^\\/]+)\\/.*", beatPath) @@ -93,7 +96,10 @@ func shouldIgnore(file string) bool { func getDiff() []string { commitRange := getCommitRange() - var output, _ = sh.Output("git", "diff", "--name-only", commitRange) + var output, err = sh.Output("git", "diff", "--name-only", commitRange) + if err != nil { + log.Fatal("git Diff failed: %w", err) + } printWhenVerbose("Git Diff result: %s\n", output) @@ -107,12 +113,6 @@ func getFromCommit() string { return getBranchName(baseBranch) } - if branch := os.Getenv("BUILDKITE_BRANCH"); branch != "" { - printWhenVerbose("Target branch: %s\n", branch) - - return getBranchName(branch) - } - if previousCommit := getPreviousCommit(); previousCommit != "" { printWhenVerbose("Git from commit: %s\n", previousCommit) @@ -127,9 +127,7 @@ func getFromCommit() string { func getPreviousCommit() string { var output, _ = sh.Output("git", "rev-parse", "HEAD^") - if mg.Verbose() { - _ = fmt.Sprintf("Git previous commit: %s\n", output) - } + printWhenVerbose("Git previous commit: %s\n", output) return strings.TrimSpace(output) } @@ -146,6 +144,6 @@ func getBranchName(branch string) string { func printWhenVerbose(template string, parameter string) { if mg.Verbose() { - _ = fmt.Sprintf(template, parameter) + fmt.Printf(template, parameter) } } From a67f8a13c826d9e259272765e9996f74a61f824e Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 16 Sep 2024 12:22:10 +0300 Subject: [PATCH 12/16] pr fixes --- dev-tools/mage/module_changeset.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index 35dafdfb134..d75e159dd11 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -78,9 +78,9 @@ func DefineModules() { return } - _, _ = fmt.Fprintf(os.Stdout, "Detected changes in module(s): %s\n", moduleVar) + log.Printf("Detected changes in module(s): %s\n", moduleVar) } else { - fmt.Print("No changed modules found") + log.Printf("No changed modules found") } } From 09f16a819c7aa491ea97e4349e70f34b4dc70285 Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 16 Sep 2024 14:21:24 +0300 Subject: [PATCH 13/16] added validation for buildkite commit env var --- dev-tools/mage/module_changeset.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index d75e159dd11..03898ef56e2 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -18,6 +18,7 @@ package mage import ( + "errors" "fmt" "log" "os" @@ -118,7 +119,10 @@ func getFromCommit() string { return previousCommit } else { - commit := os.Getenv("BUILDKITE_COMMIT") + commit, err := getBuildkiteCommit() + if err != nil { + log.Fatal(err) + } printWhenVerbose("Git from commit: %s\n", commit) return commit @@ -133,7 +137,10 @@ func getPreviousCommit() string { } func getCommitRange() string { - commit := os.Getenv("BUILDKITE_COMMIT") + commit, err := getBuildkiteCommit() + if err != nil { + log.Fatal(err) + } return fmt.Sprintf("%s...%s", getFromCommit(), commit) } @@ -147,3 +154,13 @@ func printWhenVerbose(template string, parameter string) { fmt.Printf(template, parameter) } } + +func getBuildkiteCommit() (string, error) { + commit := os.Getenv("BUILDKITE_COMMIT") + + if commit == "" { + return "", errors.New("BUILDKITE_COMMIT is not defined") + } + + return commit, nil +} From b5f03c9d6f49d0eab8577accdfc669dd3c4be74a Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 19 Sep 2024 17:19:43 +0300 Subject: [PATCH 14/16] test: changed metricbeat/module/logstash/logstash_integration_test --- metricbeat/module/logstash/logstash_integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/metricbeat/module/logstash/logstash_integration_test.go b/metricbeat/module/logstash/logstash_integration_test.go index 5865867cf1f..e6c1f1a1ea6 100644 --- a/metricbeat/module/logstash/logstash_integration_test.go +++ b/metricbeat/module/logstash/logstash_integration_test.go @@ -45,6 +45,7 @@ func TestFetch(t *testing.T) { service := compose.EnsureUpWithTimeout(t, 300, "logstash") for _, metricSet := range metricSets { + t.Log("DELETEME") t.Run(metricSet, func(t *testing.T) { config := getConfig(metricSet, service.Host()) f := mbtest.NewReportingMetricSetV2Error(t, config) From 3d09bc6a74311cdf77db7c0380f9fb6596df41de Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Fri, 20 Sep 2024 11:29:50 +0300 Subject: [PATCH 15/16] updated BUILDKITE_COMMIT validation --- dev-tools/mage/module_changeset.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dev-tools/mage/module_changeset.go b/dev-tools/mage/module_changeset.go index 03898ef56e2..c7ffdbfd9d9 100644 --- a/dev-tools/mage/module_changeset.go +++ b/dev-tools/mage/module_changeset.go @@ -18,7 +18,6 @@ package mage import ( - "errors" "fmt" "log" "os" @@ -157,9 +156,8 @@ func printWhenVerbose(template string, parameter string) { func getBuildkiteCommit() (string, error) { commit := os.Getenv("BUILDKITE_COMMIT") - if commit == "" { - return "", errors.New("BUILDKITE_COMMIT is not defined") + log.Fatal("BUILDKITE_COMMIT is not defined") } return commit, nil From b9d71957ee13440dae6963690314cde49502104b Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Mon, 23 Sep 2024 10:48:45 +0300 Subject: [PATCH 16/16] restored metricbeat/module/logstash/logstash_integration_test.go --- metricbeat/module/logstash/logstash_integration_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/metricbeat/module/logstash/logstash_integration_test.go b/metricbeat/module/logstash/logstash_integration_test.go index e6c1f1a1ea6..5865867cf1f 100644 --- a/metricbeat/module/logstash/logstash_integration_test.go +++ b/metricbeat/module/logstash/logstash_integration_test.go @@ -45,7 +45,6 @@ func TestFetch(t *testing.T) { service := compose.EnsureUpWithTimeout(t, 300, "logstash") for _, metricSet := range metricSets { - t.Log("DELETEME") t.Run(metricSet, func(t *testing.T) { config := getConfig(metricSet, service.Host()) f := mbtest.NewReportingMetricSetV2Error(t, config)