diff --git a/Jenkinsfile b/Jenkinsfile index 8373b599f123..4480a2af642c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -68,7 +68,7 @@ pipeline { } } steps { - makeTarget("Elastic Agent x-pack Linux", "-C x-pack/elastic-agent testsuite") + mageTarget("Elastic Agent x-pack Linux", "x-pack/elastic-agent", "build test") } } @@ -82,7 +82,7 @@ pipeline { } } steps { - mageTargetWin("Elastic Agent x-pack Windows Unit test", "x-pack/elastic-agent", "unitTest") + mageTargetWin("Elastic Agent x-pack Windows Unit test", "x-pack/elastic-agent", "build unitTest") } } @@ -96,7 +96,7 @@ pipeline { } } steps { - makeTarget("Elastic Agent x-pack Mac OS X", "TEST_ENVIRONMENT=0 -C x-pack/elastic-agent testsuite") + mageTarget("Elastic Agent x-pack Mac OS X", "x-pack/elastic-agent", "build unitTest") } } @@ -136,7 +136,7 @@ pipeline { } } steps { - makeTarget("Filebeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C filebeat testsuite") + mageTarget("Filebeat oss Mac OS X", "filebeat", "build unitTest") } } stage('Filebeat Windows'){ @@ -149,7 +149,7 @@ pipeline { } } steps { - mageTargetWin("Filebeat oss Windows Unit test", "filebeat", "unitTest") + mageTargetWin("Filebeat oss Windows Unit test", "filebeat", "build unitTest") } } stage('Heartbeat'){ @@ -177,7 +177,7 @@ pipeline { } } steps { - makeTarget("Heartbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C heartbeat testsuite") + mageTarget("Heartbeat oss Mac OS X", "heartbeat", "build unitTest") } } stage('Heartbeat Windows'){ @@ -190,7 +190,7 @@ pipeline { } } steps { - mageTargetWin("Heartbeat oss Windows Unit test", "heartbeat", "unitTest") + mageTargetWin("Heartbeat oss Windows Unit test", "heartbeat", "build unitTest") } } } @@ -225,7 +225,7 @@ pipeline { } } steps { - makeTarget("Auditbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C auditbeat testsuite") + mageTarget("Auditbeat oss Mac OS X", "auditbeat", "build unitTest") } } stage('Auditbeat Windows'){ @@ -238,7 +238,7 @@ pipeline { } } steps { - mageTargetWin("Auditbeat Windows Unit test", "auditbeat", "unitTest") + mageTargetWin("Auditbeat Windows Unit test", "auditbeat", "build unitTest") } } } @@ -296,7 +296,7 @@ pipeline { makeTarget("Libbeat x-pack Linux", "-C x-pack/libbeat testsuite") } } - stage('Metricbeat Unit tests'){ + stage('Metricbeat OSS Unit tests'){ agent { label 'ubuntu && immutable' } options { skipDefaultCheckout() } when { @@ -306,10 +306,10 @@ pipeline { } } steps { - makeTarget("Metricbeat Unit tests", "-C metricbeat unit-tests coverage-report") + mageTarget("Metricbeat OSS linux/amd64 (unitTest)", "metricbeat", "build unitTest") } } - stage('Metricbeat Integration tests'){ + stage('Metricbeat OSS Integration tests'){ agent { label 'ubuntu && immutable' } options { skipDefaultCheckout() } when { @@ -319,20 +319,7 @@ pipeline { } } steps { - makeTarget("Metricbeat Integration tests", "-C metricbeat integration-tests-environment coverage-report") - } - } - stage('Metricbeat System tests'){ - agent { label 'ubuntu && immutable' } - options { skipDefaultCheckout() } - when { - beforeAgent true - expression { - return env.BUILD_METRICBEAT != "false" - } - } - steps { - makeTarget("Metricbeat System tests", "-C metricbeat update system-tests-environment coverage-report") + mageTarget("Metricbeat OSS linux/amd64 (integTest)", "metricbeat", "integTest") } } stage('Metricbeat x-pack'){ @@ -345,7 +332,7 @@ pipeline { } } steps { - mageTarget("Metricbeat x-pack Linux", "x-pack/metricbeat", "update build test") + mageTarget("Metricbeat x-pack Linux", "x-pack/metricbeat", "build test") } } stage('Metricbeat crosscompile'){ @@ -358,7 +345,7 @@ pipeline { } } steps { - makeTarget("Metricbeat oss crosscompile", "-C metricbeat crosscompile") + makeTarget("Metricbeat OSS crosscompile", "-C metricbeat crosscompile") } } stage('Metricbeat Mac OS X'){ @@ -371,7 +358,7 @@ pipeline { } } steps { - makeTarget("Metricbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C metricbeat testsuite") + mageTarget("Metricbeat OSS Mac OS X", "metricbeat", "build unitTest") } } stage('Metricbeat Windows'){ @@ -384,7 +371,7 @@ pipeline { } } steps { - mageTargetWin("Metricbeat Windows Unit test", "metricbeat", "unitTest") + mageTargetWin("Metricbeat Windows Unit test", "metricbeat", "build unitTest") } } stage('Packetbeat'){ @@ -446,7 +433,7 @@ pipeline { } } steps { - mageTargetWin("Winlogbeat Windows Unit test", "winlogbeat", "unitTest") + mageTargetWin("Winlogbeat Windows Unit test", "winlogbeat", "build unitTest") } } } @@ -461,7 +448,7 @@ pipeline { } } steps { - mageTargetWin("Winlogbeat Windows Unit test", "x-pack/winlogbeat", "unitTest") + mageTargetWin("Winlogbeat Windows Unit test", "x-pack/winlogbeat", "build unitTest") } } stage('Functionbeat'){ @@ -492,7 +479,7 @@ pipeline { } } steps { - mageTarget("Functionbeat x-pack Mac OS X", "x-pack/functionbeat", "update build test") + mageTarget("Functionbeat x-pack Mac OS X", "x-pack/functionbeat", "build unitTest") } } stage('Functionbeat Windows'){ @@ -505,7 +492,7 @@ pipeline { } } steps { - mageTargetWin("Functionbeat Windows Unit test", "x-pack/functionbeat", "unitTest") + mageTargetWin("Functionbeat Windows Unit test", "x-pack/functionbeat", "build unitTest") } } } diff --git a/auditbeat/magefile.go b/auditbeat/magefile.go index e51bebb327ed..115547619406 100644 --- a/auditbeat/magefile.go +++ b/auditbeat/magefile.go @@ -45,12 +45,6 @@ func init() { devtools.BeatDescription = "Audit the activities of users and processes on your system." } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) diff --git a/dev-tools/jenkins_ci.ps1 b/dev-tools/jenkins_ci.ps1 deleted file mode 100755 index 9d43fef5c9b7..000000000000 --- a/dev-tools/jenkins_ci.ps1 +++ /dev/null @@ -1,74 +0,0 @@ -function Exec { - [CmdletBinding()] - param( - [Parameter(Mandatory = $true)] - [scriptblock]$cmd, - [string]$errorMessage = ($msgs.error_bad_command -f $cmd) - ) - - try { - $global:lastexitcode = 0 - & $cmd - if ($lastexitcode -ne 0) { - throw $errorMessage - } - } - catch [Exception] { - throw $_ - } -} - -# Setup Go. -$env:GOPATH = $env:WORKSPACE -$env:PATH = "$env:GOPATH\bin;C:\tools\mingw64\bin;$env:PATH" -& gvm --format=powershell $(Get-Content .go-version) | Invoke-Expression - -# Write cached magefile binaries to workspace to ensure -# each run starts from a clean slate. -$env:MAGEFILE_CACHE = "$env:WORKSPACE\.magefile" - -# Configure testing parameters. -$env:TEST_COVERAGE = "true" -$env:RACE_DETECTOR = "true" - -# Install mage from vendor. -exec { go install -mod=vendor github.com/magefile/mage } "mage install FAILURE" - -if (Test-Path "$env:beat\magefile.go") { - cd "$env:beat" -} else { - echo "$env:beat\magefile.go does not exist" - New-Item -ItemType directory -Path build | Out-Null - New-Item -Name build\TEST-empty.out -ItemType File | Out-Null - exit -} - -if (Test-Path "build") { Remove-Item -Recurse -Force build } -New-Item -ItemType directory -Path build\coverage | Out-Null -New-Item -ItemType directory -Path build\system-tests | Out-Null -New-Item -ItemType directory -Path build\system-tests\run | Out-Null - -echo "Building fields.yml" -exec { mage fields } "mage fields FAILURE" - -echo "Building $env:beat" -exec { mage build } "Build FAILURE" - -echo "Unit testing $env:beat" -exec { mage goTestUnit } "mage goTestUnit FAILURE" - -echo "System testing $env:beat" -# Get a CSV list of package names. -$packages = $(go list ./... | select-string -Pattern "/vendor/" -NotMatch | select-string -Pattern "/scripts/cmd/" -NotMatch) -$packages = ($packages|group|Select -ExpandProperty Name) -join "," -exec { go test -race -c -cover -covermode=atomic -coverpkg $packages } "go test -race -cover FAILURE" - -if (Test-Path "tests\system") { - echo "Running python tests" - choco install python -y -r --no-progress --version 3.8.1.20200110 - refreshenv - $env:PATH = "C:\Python38;C:\Python38\Scripts;$env:PATH" - $env:PYTHON_ENV = "$env:TEMP\python-env" - python --version - exec { mage pythonUnitTest } "System test FAILURE" -} diff --git a/dev-tools/mage/common.go b/dev-tools/mage/common.go index e109d752506b..7d31038d06d0 100644 --- a/dev-tools/mage/common.go +++ b/dev-tools/mage/common.go @@ -803,3 +803,21 @@ func listModuleDir(modpath string) (string, error) { } return gotool.ListModuleCacheDir(modpath) } + +// ListMatchingEnvVars returns all of the environment variables names that begin +// with prefix. +func ListMatchingEnvVars(prefixes ...string) []string { + var vars []string + for _, v := range os.Environ() { + for _, prefix := range prefixes { + if strings.HasPrefix(v, prefix) { + eqIdx := strings.Index(v, "=") + if eqIdx != -1 { + vars = append(vars, v[:eqIdx]) + } + break + } + } + } + return vars +} diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go index 2c4b302c0673..539e4fba03c7 100644 --- a/dev-tools/mage/crossbuild.go +++ b/dev-tools/mage/crossbuild.go @@ -296,7 +296,8 @@ func DockerChown(path string) { // chownPaths will chown the file and all of the dirs specified in the path. func chownPaths(uid, gid int, path string) error { start := time.Now() - defer log.Printf("chown took: %v", time.Now().Sub(start)) + numFixed := 0 + defer log.Printf("chown took: %v, changed %d files", time.Now().Sub(start), numFixed) return filepath.Walk(path, func(name string, info os.FileInfo, err error) error { if err != nil { @@ -315,10 +316,10 @@ func chownPaths(uid, gid int, path string) error { return nil } - log.Printf("chown file: %v", name) if err := os.Chown(name, uid, gid); err != nil { return errors.Wrapf(err, "failed to chown path=%v", name) } + numFixed++ return nil }) } diff --git a/dev-tools/mage/fmt.go b/dev-tools/mage/fmt.go index f86ed59a692d..02a8001895e2 100644 --- a/dev-tools/mage/fmt.go +++ b/dev-tools/mage/fmt.go @@ -51,10 +51,12 @@ func Format() { } // GoImports executes goimports against all .go files in and below the CWD. It -// ignores vendor/ directories. +// ignores vendor/ and generator/_templates/ directories. func GoImports() error { goFiles, err := FindFilesRecursive(func(path string, _ os.FileInfo) bool { - return filepath.Ext(path) == ".go" && !strings.Contains(path, "vendor/") + return filepath.Ext(path) == ".go" && + !strings.Contains(path, "vendor/") && + !strings.Contains(path, "generator/_templates/") }) if err != nil { return err diff --git a/dev-tools/mage/pkg_test.go b/dev-tools/mage/pkg_test.go index e360686b54a3..c0b92f15de3f 100644 --- a/dev-tools/mage/pkg_test.go +++ b/dev-tools/mage/pkg_test.go @@ -103,7 +103,7 @@ func TestDumpVariables(t *testing.T) { } func TestLoadSpecs(t *testing.T) { - pkgs, err := LoadSpecs("files/packages.yml") + pkgs, err := LoadSpecs("../packaging/packages.yml") if err != nil { t.Fatal(err) } diff --git a/dev-tools/mage/target/integtest/integtest.go b/dev-tools/mage/target/integtest/integtest.go index abf276bc0388..324fa25e7324 100644 --- a/dev-tools/mage/target/integtest/integtest.go +++ b/dev-tools/mage/target/integtest/integtest.go @@ -70,7 +70,11 @@ func GoIntegTest(ctx context.Context) error { }, whitelistedEnvVars...) } -// PythonIntegTest executes the python system tests in the integration environment (Docker). +// PythonIntegTest executes the python system tests in the integration +// environment (Docker). +// Use NOSE_TESTMATCH=pattern to only run tests matching the specified pattern. +// Use any other NOSE_* environment variable to influence the behavior of +// nosetests. func PythonIntegTest(ctx context.Context) error { if !devtools.IsInIntegTestEnv() { mg.SerialDeps(pythonTestDeps...) @@ -78,5 +82,5 @@ func PythonIntegTest(ctx context.Context) error { return devtools.RunIntegTest("pythonIntegTest", func() error { mg.Deps(devtools.BuildSystemTestBinary) return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs()) - }, whitelistedEnvVars...) + }, append(whitelistedEnvVars, devtools.ListMatchingEnvVars("NOSE_")...)...) } diff --git a/dev-tools/mage/target/integtest/notests/integtest.go b/dev-tools/mage/target/integtest/notests/integtest.go index 2249faf75cba..b94cf5ddf9de 100644 --- a/dev-tools/mage/target/integtest/notests/integtest.go +++ b/dev-tools/mage/target/integtest/notests/integtest.go @@ -19,7 +19,7 @@ package notests import "fmt" -// IntegTest method fallbacks to GoIntegTest() +// IntegTest executes integration tests (it uses Docker to run the tests). func IntegTest() { GoIntegTest() } diff --git a/dev-tools/magefile.go b/dev-tools/magefile.go index 083e7e3479c1..5bdc24790422 100644 --- a/dev-tools/magefile.go +++ b/dev-tools/magefile.go @@ -20,6 +20,23 @@ package main import ( + "context" + + devtools "github.com/elastic/beats/v7/dev-tools/mage" + // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" + // mage:import + "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) + +func init() { + test.RegisterDeps(GoUnitTest) +} + +// GoUnitTest executes the Go unit tests. +// Use TEST_COVERAGE=true to enable code coverage profiling. +// Use RACE_DETECTOR=true to enable the race detector. +func GoUnitTest(ctx context.Context) { + devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) +} diff --git a/dev-tools/packaging/templates/common/magefile.go.tmpl b/dev-tools/packaging/templates/common/magefile.go.tmpl deleted file mode 100644 index 286f9d30555a..000000000000 --- a/dev-tools/packaging/templates/common/magefile.go.tmpl +++ /dev/null @@ -1,92 +0,0 @@ -// +build mage - -package main - -import ( - "context" - "fmt" - "time" - - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" - - devtools "github.com/elastic/beats/v7/dev-tools/mage" -) - -func init() { - devtools.BeatDescription = "One sentence description of the Beat." -} - -// Build builds the Beat binary. -func Build() error { - return devtools.Build(devtools.DefaultBuildArgs()) -} - -// GolangCrossBuild build the Beat binary inside of the golang-builder. -// Do not use directly, use crossBuild instead. -func GolangCrossBuild() error { - return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs()) -} - -// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon). -func BuildGoDaemon() error { - return devtools.BuildGoDaemon() -} - -// CrossBuild cross-builds the beat for all target platforms. -func CrossBuild() error { - return devtools.CrossBuild() -} - -// CrossBuildGoDaemon cross-builds the go-daemon binary using Docker. -func CrossBuildGoDaemon() error { - return devtools.CrossBuildGoDaemon() -} - -// Clean cleans all generated files and build artifacts. -func Clean() error { - return devtools.Clean() -} - -// Package packages the Beat for distribution. -// Use SNAPSHOT=true to build snapshots. -// Use PLATFORMS to control the target platforms. -func Package() { - start := time.Now() - defer func() { fmt.Println("package ran for", time.Since(start)) }() - - devtools.UseCommunityBeatPackaging() - - mg.Deps(Update) - mg.Deps(CrossBuild, CrossBuildGoDaemon) - mg.SerialDeps(devtools.Package, TestPackages) -} - -// TestPackages tests the generated packages (i.e. file modes, owners, groups). -func TestPackages() error { - return devtools.TestPackages() -} - -// Update updates the generated files (aka make update). -func Update() error { - return sh.Run("make", "update") -} - -// Fields generates a fields.yml for the Beat. -func Fields() error { - return devtools.GenerateFieldsYAML() -} - -// GoTestUnit executes the Go unit tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoTestUnit(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) -} - -// GoTestIntegration executes the Go integration tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoTestIntegration(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) -} diff --git a/filebeat/magefile.go b/filebeat/magefile.go index e63c63318524..0c3d8881892d 100644 --- a/filebeat/magefile.go +++ b/filebeat/magefile.go @@ -34,7 +34,7 @@ import ( // mage:import generate _ "github.com/elastic/beats/v7/filebeat/scripts/mage/generate" // mage:import - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) @@ -46,12 +46,6 @@ func init() { devtools.BeatDescription = "Filebeat sends log files to Logstash or directly to Elasticsearch." } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) @@ -207,5 +201,5 @@ func PythonIntegTest(ctx context.Context) error { args := devtools.DefaultPythonTestIntegrationArgs() args.Env["MODULES_PATH"] = devtools.CWD("module") return devtools.PythonNoseTest(args) - }, "GENERATE", "TESTING_FILEBEAT_MODULES", "TESTING_FILEBEAT_FILESETS") + }, append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "NOSE_"), "GENERATE")...) } diff --git a/heartbeat/docker-compose.yml b/heartbeat/docker-compose.yml index 3f905081441b..c7da39a8798e 100644 --- a/heartbeat/docker-compose.yml +++ b/heartbeat/docker-compose.yml @@ -4,11 +4,11 @@ services: build: ${PWD}/. depends_on: - proxy_dep - env_file: - - ${PWD}/build/test.env environment: - REDIS_HOST=redis - REDIS_PORT=6379 + - ES_HOST=elasticsearch + - ES_PORT=9200 working_dir: /go/src/github.com/elastic/beats/heartbeat volumes: - ${PWD}/..:/go/src/github.com/elastic/beats/ diff --git a/heartbeat/magefile.go b/heartbeat/magefile.go index 0771f376c4c7..298ee0443d1a 100644 --- a/heartbeat/magefile.go +++ b/heartbeat/magefile.go @@ -20,7 +20,6 @@ package main import ( - "context" "fmt" "time" @@ -34,13 +33,17 @@ import ( // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import - _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/notests" + "github.com/elastic/beats/v7/dev-tools/mage/target/integtest" // mage:import - _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + // mage:import + _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) func init() { common.RegisterCheckDeps(Update) + unittest.RegisterPythonTestDeps(Fields) + integtest.RegisterPythonTestDeps(Fields) devtools.BeatDescription = "Ping remote services for availability and log " + "results to Elasticsearch or send to Logstash." @@ -124,13 +127,6 @@ func Imports() error { return devtools.GenerateIncludeListGo(options) } -// GoTestUnit executes the Go unit tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoTestUnit(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) -} - func customizePackaging() { monitorsDTarget := "monitors.d" unixMonitorsDir := "/etc/{{.BeatName}}/monitors.d" diff --git a/journalbeat/magefile.go b/journalbeat/magefile.go index ae30d5983a6d..d119e2e75540 100644 --- a/journalbeat/magefile.go +++ b/journalbeat/magefile.go @@ -20,7 +20,6 @@ package main import ( - "context" "fmt" "strings" "time" @@ -37,6 +36,8 @@ import ( _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/notests" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + // mage:import + _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) func init() { @@ -116,13 +117,6 @@ func Fields() error { return devtools.GenerateFieldsYAML() } -// GoTestUnit executes the Go unit tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoTestUnit(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) -} - // ----------------------------------------------------------------------------- // Customizations specific to Journalbeat. // - Install required headers on builders for different architectures. diff --git a/libbeat/docker-compose.yml b/libbeat/docker-compose.yml index 267cc441a153..e2c759cda81d 100644 --- a/libbeat/docker-compose.yml +++ b/libbeat/docker-compose.yml @@ -5,6 +5,8 @@ services: depends_on: - proxy_dep environment: + - LIBBEAT_PATH=/go/src/github.com/elastic/beats/libbeat + - BEAT_STRICT_PERMS=false - REDIS_HOST=redis - REDIS_PORT=6379 - SREDIS_HOST=sredis @@ -12,18 +14,22 @@ services: - LS_HOST=logstash - LS_TCP_PORT=5044 - LS_TLS_PORT=5055 - # Setup work environment - - LIBBEAT_PATH=/go/src/github.com/elastic/beats/libbeat - KAFKA_HOST=kafka - KAFKA_PORT=9092 - KIBANA_HOST=kibana - KIBANA_PORT=5601 + - KIBANA_USER=beats + - KIBANA_PASS=testing + - ES_HOST=elasticsearch + - ES_PORT=9200 + - ES_USER=beats + - ES_PASS=testing - ES_MONITORING_HOST=elasticsearch_monitoring - ES_MONITORING_PORT=9200 - ES_HOST_SSL=elasticsearchssl - ES_PORT_SSL=9200 - env_file: - - ${PWD}/build/test.env + - ES_SUPERUSER_USER=admin + - ES_SUPERUSER_PASS=changeme volumes: - ${PWD}/..:/go/src/github.com/elastic/beats/ # Used for docker integration tests: @@ -86,7 +92,7 @@ services: - "xpack.security.authc.realms.file.file1.order=0" volumes: - ${ES_BEATS}/testing/environments/docker/elasticsearch/pki:/usr/share/elasticsearch/config/pki:ro - ports: + expose: - 9200 command: bash -c "bin/elasticsearch-users useradd admin -r superuser -p changeme | /usr/local/bin/docker-entrypoint.sh eswrapper" @@ -95,8 +101,6 @@ services: extends: file: ${ES_BEATS}/testing/environments/${TESTING_ENVIRONMENT}.yml service: logstash - env_file: - - ${PWD}/build/test.env depends_on: elasticsearch: condition: service_healthy @@ -115,8 +119,6 @@ services: environment: - REDIS_HOST=redis - REDIS_PORT=6379 - env_file: - - ${PWD}/build/test.env kafka: build: ${ES_BEATS}/testing/environments/docker/kafka diff --git a/libbeat/magefile.go b/libbeat/magefile.go index ff168daec533..e5a22799b6dc 100644 --- a/libbeat/magefile.go +++ b/libbeat/magefile.go @@ -20,16 +20,23 @@ package main import ( - "context" - devtools "github.com/elastic/beats/v7/dev-tools/mage" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import - _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + // mage:import + "github.com/elastic/beats/v7/dev-tools/mage/target/integtest" + // mage:import + _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) +func init() { + unittest.RegisterPythonTestDeps(Fields) + integtest.RegisterGoTestDeps(Fields) +} + // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) @@ -40,21 +47,7 @@ func Fields() error { return devtools.GenerateFieldsYAML("processors") } -// GoTestUnit executes the Go unit tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoTestUnit(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) -} - // Config generates example and reference configuration for libbeat. func Config() error { return devtools.Config(devtools.ShortConfigType|devtools.ReferenceConfigType, devtools.ConfigFileParams{}, ".") } - -// GoIntegTest executes the Go integration tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoIntegTest(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) -} diff --git a/libbeat/tests/system/keystore.py b/libbeat/tests/system/keystore.py index 5ba96a4d58a4..12418ba5a731 100644 --- a/libbeat/tests/system/keystore.py +++ b/libbeat/tests/system/keystore.py @@ -12,14 +12,17 @@ def add_secret(self, key, value="hello world\n", force=False): """ Add new secret using the --stdin option """ - args = [self.test_binary, - "-systemTest", + args = [self.test_binary, "-systemTest"] + if os.getenv("TEST_COVERAGE") == "true": + args += [ "-test.coverprofile", os.path.join(self.working_dir, "coverage.cov"), - "-c", os.path.join(self.working_dir, "mockbeat.yml"), - "-e", "-v", "-d", "*", - "keystore", "add", key, "--stdin", - ] + ] + args += [ + "-c", os.path.join(self.working_dir, "mockbeat.yml"), + "-e", "-v", "-d", "*", + "keystore", "add", key, "--stdin", + ] if force: args.append("--force") diff --git a/libbeat/tests/system/requirements.txt b/libbeat/tests/system/requirements.txt index 52c360334062..f979754ed330 100644 --- a/libbeat/tests/system/requirements.txt +++ b/libbeat/tests/system/requirements.txt @@ -32,3 +32,4 @@ jsondiff==1.1.2 semver==2.8.1 stomp.py==4.1.22 deepdiff==4.2.0 +kafka-python==1.4.3 diff --git a/metricbeat/Makefile b/metricbeat/Makefile index fd2c60935e76..c558416eb44f 100644 --- a/metricbeat/Makefile +++ b/metricbeat/Makefile @@ -16,10 +16,8 @@ include ${ES_BEATS}/libbeat/scripts/Makefile # Collects all module dashboards .PHONY: kibana -kibana: - @rm -rf _meta/kibana.generated - @mkdir -p _meta/kibana.generated - @-cp -pr module/*/_meta/kibana/* _meta/kibana.generated +kibana: mage + @mage dashboards # Collects all module docs .PHONY: collect-docs diff --git a/metricbeat/magefile.go b/metricbeat/magefile.go index d100e555c78c..753e5e5a5184 100644 --- a/metricbeat/magefile.go +++ b/metricbeat/magefile.go @@ -53,20 +53,14 @@ import ( func init() { common.RegisterCheckDeps(update.Update) - test.RegisterDeps(GoIntegTest) + test.RegisterDeps(GoIntegTest, PythonIntegTest) unittest.RegisterGoTestDeps(Fields) unittest.RegisterPythonTestDeps(Fields) devtools.BeatDescription = "Metricbeat is a lightweight shipper for metrics." } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - -//CollectAll generates the docs and the fields. +// CollectAll generates the docs and the fields. func CollectAll() { mg.Deps(CollectDocs, FieldsDocs) } @@ -144,15 +138,6 @@ func Fields() error { return devtools.GenerateFieldsYAML("module") } -// ExportDashboard exports a dashboard and writes it into the correct directory -// -// Required ENV variables: -// * MODULE: Name of the module -// * ID: Dashboard id -func ExportDashboard() error { - return devtools.ExportDashboard() -} - // FieldsDocs generates docs/fields.asciidoc containing all fields // (including x-pack). func FieldsDocs() error { @@ -172,6 +157,11 @@ func CollectDocs() error { return metricbeat.CollectDocs() } +// IntegTest executes integration tests (it uses Docker to run the tests). +func IntegTest() { + mg.SerialDeps(GoIntegTest, PythonIntegTest) +} + // GoIntegTest executes the Go integration tests. // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. @@ -181,3 +171,18 @@ func GoIntegTest(ctx context.Context) error { mg.Deps(Fields) return devtools.GoTestIntegrationForModule(ctx) } + +// PythonIntegTest executes the python system tests in the integration +// environment (Docker). +// Use NOSE_TESTMATCH=pattern to only run tests matching the specified pattern. +// Use any other NOSE_* environment variable to influence the behavior of +// nosetests. +func PythonIntegTest(ctx context.Context) error { + if !devtools.IsInIntegTestEnv() { + mg.SerialDeps(Fields, Dashboards) + } + return devtools.RunIntegTest("pythonIntegTest", func() error { + mg.Deps(devtools.BuildSystemTestBinary) + return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs()) + }, devtools.ListMatchingEnvVars("NOSE_")...) +} diff --git a/metricbeat/tests/system/test_base.py b/metricbeat/tests/system/test_base.py index 5e52872bb7ba..4f680d291728 100644 --- a/metricbeat/tests/system/test_base.py +++ b/metricbeat/tests/system/test_base.py @@ -106,4 +106,4 @@ def get_kibana_url(self): return "http://" + self.compose_host("kibana") def kibana_dir(self): - return os.path.join(self.beat_path, "_meta", "kibana.generated") + return os.path.join(self.beat_path, "build", "kibana") diff --git a/packetbeat/magefile.go b/packetbeat/magefile.go index 7793ed32ec07..8e381260a92d 100644 --- a/packetbeat/magefile.go +++ b/packetbeat/magefile.go @@ -20,7 +20,6 @@ package main import ( - "context" "fmt" "log" "regexp" @@ -38,6 +37,8 @@ import ( "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/notests" + // mage:import + _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) func init() { @@ -46,12 +47,6 @@ func init() { devtools.BeatDescription = "Packetbeat analyzes network traffic and sends the data to Elasticsearch." } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) @@ -192,24 +187,6 @@ func Dashboards() error { return devtools.KibanaDashboards("protos") } -// UnitTest executes the unit tests. -func UnitTest() { - mg.SerialDeps(GoUnitTest, PythonUnitTest) -} - -// GoUnitTest executes the Go unit tests. -// Use TEST_COVERAGE=true to enable code coverage profiling. -// Use RACE_DETECTOR=true to enable the race detector. -func GoUnitTest(ctx context.Context) error { - return devtools.GoTest(ctx, devtools.DefaultGoTestUnitArgs()) -} - -// PythonUnitTest executes the python system tests. -func PythonUnitTest() error { - mg.SerialDeps(Fields, devtools.BuildSystemTestBinary) - return devtools.PythonNoseTest(devtools.DefaultPythonTestUnitArgs()) -} - // ----------------------------------------------------------------------------- // Customizations specific to Packetbeat. // - Config file contains an OS specific device name (affects darwin, windows). diff --git a/winlogbeat/magefile.go b/winlogbeat/magefile.go index 84596c9a677b..65bb92af96ee 100644 --- a/winlogbeat/magefile.go +++ b/winlogbeat/magefile.go @@ -50,15 +50,3 @@ func init() { // Update is an alias for update:all. This is a workaround for // https://github.com/magefile/mage/issues/217. func Update() { mg.Deps(winlogbeat.Update.All) } - -// Fields is an alias for update:fields. -// -// TODO: dev-tools/jenkins_ci.ps1 uses this. This should be removed when all -// projects have update to use goUnitTest. -func Fields() { mg.Deps(winlogbeat.Update.Fields) } - -// GoTestUnit is an alias for goUnitTest. -// -// TODO: dev-tools/jenkins_ci.ps1 uses this. This should be removed when all -// projects have update to use goUnitTest. -func GoTestUnit() { mg.Deps(unittest.GoUnitTest) } diff --git a/x-pack/auditbeat/magefile.go b/x-pack/auditbeat/magefile.go index 91659ed3ca42..cb70fb3d44d7 100644 --- a/x-pack/auditbeat/magefile.go +++ b/x-pack/auditbeat/magefile.go @@ -20,7 +20,7 @@ import ( // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest" // mage:import @@ -35,12 +35,6 @@ func init() { devtools.Platforms = devtools.Platforms.Filter("!linux/ppc64 !linux/mips64") } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) diff --git a/x-pack/elastic-agent/magefile.go b/x-pack/elastic-agent/magefile.go index a626d638cf1c..8168890998ee 100644 --- a/x-pack/elastic-agent/magefile.go +++ b/x-pack/elastic-agent/magefile.go @@ -20,15 +20,16 @@ import ( "github.com/magefile/mage/sh" devtools "github.com/elastic/beats/v7/dev-tools/mage" - "github.com/elastic/beats/v7/dev-tools/mage/target/common" - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release" // mage:import - _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" - + "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/docs" + // mage:import + _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/notests" + // mage:import + "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) const ( @@ -48,6 +49,7 @@ var Aliases = map[string]interface{}{ func init() { common.RegisterCheckDeps(Update, Check.All) + test.RegisterDeps(UnitTest) devtools.BeatDescription = "Agent manages other beats based on configuration provided." devtools.BeatLicense = "Elastic License" @@ -421,22 +423,11 @@ func combineErr(errors ...error) error { return e } -// GoTestUnit is an alias for goUnitTest. -func GoTestUnit() { - mg.Deps(unittest.GoUnitTest) -} - // UnitTest performs unit test on agent. func UnitTest() { mg.Deps(Test.All) } -// IntegTest calls go integtest, we dont have python integ test so far -// TODO: call integtest mage package when python tests are available -func IntegTest() { - os.Create(filepath.Join("build", "TEST-go-integration.out")) -} - // BuildFleetCfg embed the default fleet configuration as part of the binary. func BuildFleetCfg() error { goF := filepath.Join("dev-tools", "cmd", "buildfleetcfg", "buildfleetcfg.go") @@ -447,11 +438,6 @@ func BuildFleetCfg() error { return RunGo("run", goF, "--in", in, "--out", out) } -// Fields placeholder methods to fix the windows build. -func Fields() error { - return nil -} - // Enroll runs agent which enrolls before running. func (Demo) Enroll() error { env := map[string]string{ diff --git a/x-pack/filebeat/magefile.go b/x-pack/filebeat/magefile.go index e25385fb0a3c..f157b8b1a063 100644 --- a/x-pack/filebeat/magefile.go +++ b/x-pack/filebeat/magefile.go @@ -22,7 +22,7 @@ import ( // mage:import generate _ "github.com/elastic/beats/v7/filebeat/scripts/mage/generate" // mage:import - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) @@ -35,12 +35,6 @@ func init() { devtools.BeatLicense = "Elastic License" } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) @@ -181,5 +175,5 @@ func PythonIntegTest(ctx context.Context) error { args := devtools.DefaultPythonTestIntegrationArgs() args.Env["MODULES_PATH"] = devtools.CWD("module") return devtools.PythonNoseTest(args) - }, "GENERATE", "TESTING_FILEBEAT_MODULES", "TESTING_FILEBEAT_FILESETS") + }, append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "NOSE_"), "GENERATE")...) } diff --git a/x-pack/functionbeat/magefile.go b/x-pack/functionbeat/magefile.go index d4554e4da1a2..a317bd0cb71f 100644 --- a/x-pack/functionbeat/magefile.go +++ b/x-pack/functionbeat/magefile.go @@ -14,10 +14,11 @@ import ( "github.com/magefile/mage/mg" + devtools "github.com/elastic/beats/v7/dev-tools/mage" + functionbeat "github.com/elastic/beats/v7/x-pack/functionbeat/scripts/mage" + // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" - // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/pkg" // mage:import @@ -26,9 +27,6 @@ import ( _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest/notests" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" - - devtools "github.com/elastic/beats/v7/dev-tools/mage" - functionbeat "github.com/elastic/beats/v7/x-pack/functionbeat/scripts/mage" ) func init() { @@ -153,11 +151,6 @@ func TestPackages() error { return devtools.TestPackages() } -// GoTestUnit is an alias for goUnitTest. -func GoTestUnit() { - mg.Deps(unittest.GoUnitTest) -} - // BuildPkgForFunctions creates a folder named pkg and adds functions to it. // This makes testing the manager more comfortable. func BuildPkgForFunctions() error { diff --git a/x-pack/libbeat/magefile.go b/x-pack/libbeat/magefile.go index 9e1f254af565..01e9b4d7f2d4 100644 --- a/x-pack/libbeat/magefile.go +++ b/x-pack/libbeat/magefile.go @@ -14,7 +14,7 @@ import ( // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/integtest" // mage:import - "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" + _ "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/test" ) @@ -32,9 +32,3 @@ func Build() error { func Fields() error { return devtools.GenerateFieldsYAML() } - -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} diff --git a/x-pack/metricbeat/magefile.go b/x-pack/metricbeat/magefile.go index 030b2b1889ea..1821f21a435c 100644 --- a/x-pack/metricbeat/magefile.go +++ b/x-pack/metricbeat/magefile.go @@ -29,18 +29,13 @@ import ( func init() { common.RegisterCheckDeps(Update) + unittest.RegisterPythonTestDeps(Fields) test.RegisterDeps(IntegTest) devtools.BeatDescription = "Metricbeat is a lightweight shipper for metrics." devtools.BeatLicense = "Elastic License" } -// Aliases provides compatibility with CI while we transition all Beats -// to having common testing targets. -var Aliases = map[string]interface{}{ - "goTestUnit": unittest.GoUnitTest, // dev-tools/jenkins_ci.ps1 uses this. -} - // Build builds the Beat binary. func Build() error { return devtools.Build(devtools.DefaultBuildArgs()) @@ -151,7 +146,11 @@ func GoIntegTest(ctx context.Context) error { return devtools.GoTestIntegrationForModule(ctx) } -// PythonIntegTest executes the python system tests in the integration environment (Docker). +// PythonIntegTest executes the python system tests in the integration +// environment (Docker). +// Use NOSE_TESTMATCH=pattern to only run tests matching the specified pattern. +// Use any other NOSE_* environment variable to influence the behavior of +// nosetests. func PythonIntegTest(ctx context.Context) error { if !devtools.IsInIntegTestEnv() { mg.SerialDeps(Fields, Dashboards) @@ -159,5 +158,5 @@ func PythonIntegTest(ctx context.Context) error { return devtools.RunIntegTest("pythonIntegTest", func() error { mg.Deps(devtools.BuildSystemTestBinary) return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs()) - }) + }, devtools.ListMatchingEnvVars("NOSE_")...) } diff --git a/x-pack/winlogbeat/magefile.go b/x-pack/winlogbeat/magefile.go index 6b6646bed152..a52000fa830f 100644 --- a/x-pack/winlogbeat/magefile.go +++ b/x-pack/winlogbeat/magefile.go @@ -37,15 +37,3 @@ func init() { // Update is an alias for update:all. This is a workaround for // https://github.com/magefile/mage/issues/217. func Update() { mg.Deps(winlogbeat.Update.All) } - -// Fields is an alias for update:fields. -// -// TODO: dev-tools/jenkins_ci.ps1 uses this. This should be removed when all -// projects have update to use goUnitTest. -func Fields() { mg.Deps(winlogbeat.Update.Fields) } - -// GoTestUnit is an alias for goUnitTest. -// -// TODO: dev-tools/jenkins_ci.ps1 uses this. This should be removed when all -// projects have update to use goUnitTest. -func GoTestUnit() { mg.Deps(unittest.GoUnitTest) }