From 6286301dfcd8a6c4f2c1a7b666696e09613cb680 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 05:30:29 -0800 Subject: [PATCH 01/14] Adding debugging --- metricbeat/magefile.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metricbeat/magefile.go b/metricbeat/magefile.go index 2a96df12bfb..e23daf5831c 100644 --- a/metricbeat/magefile.go +++ b/metricbeat/magefile.go @@ -167,5 +167,7 @@ func CollectDocs() error { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { + e, _ := os.LookupEnv("TEST_ENVIRONMENT") + fmt.Printf("In metricbeat/magefile.go:GoIntegTest. TEST_ENVIRONMENT=%v\n", e) return devtools.GoTestIntegrationForModule(ctx) } From 4c0e33e741a1bf626b1ad792e8921878c340d0c7 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 06:10:24 -0800 Subject: [PATCH 02/14] Still debugging --- libbeat/magefile.go | 4 ++++ libbeat/scripts/Makefile | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libbeat/magefile.go b/libbeat/magefile.go index efdbc87d497..d24de0b8359 100644 --- a/libbeat/magefile.go +++ b/libbeat/magefile.go @@ -21,6 +21,8 @@ package main import ( "context" + "fmt" + "os" devtools "github.com/elastic/beats/dev-tools/mage" @@ -54,5 +56,7 @@ func Config() error { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { + e, _ := os.LookupEnv("TEST_ENVIRONMENT") + fmt.Printf("In libbeat/magefile.go:GoIntegTest. TEST_ENVIRONMENT=%v\n", e) return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) } diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index ddd460c3d4c..9a8fc91e678 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -196,6 +196,7 @@ unit: ## @testing Runs the unit tests without coverage reports. .PHONY: integration-tests integration-tests: ## @testing Run integration tests. Unit tests are run as part of the integration tests. integration-tests: prepare-tests mage + echo "[integration-tests] TEST_ENVIRONMENT=${TEST_ENVIRONMENT}" rm -f docker-compose.yml.lock mage goIntegTest @@ -207,7 +208,12 @@ integration-tests-environment: prepare-tests build-image # # This will make docker-compose command to display the logs on stdout on error, It's not enabled # by default because it can create noise if the test inside the container fails. - ${DOCKER_COMPOSE} run beat make integration-tests RACE_DETECTOR=$(RACE_DETECTOR) DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} + echo "[integration-tests-environment] TEST_ENVIRONMENT=${TEST_ENVIRONMENT}" + ${DOCKER_COMPOSE} run \ + -e RACE_DETECTOR=$(RACE_DETECTOR) \ + -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ + -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} \ + beat make integration-tests # Runs the system tests .PHONY: system-tests From 0f2af2c7a40e861a0e8682e4b41c6bf1c23b6281 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 07:19:23 -0800 Subject: [PATCH 03/14] Add deps for integration tests --- dev-tools/mage/target/integtest/integtest.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev-tools/mage/target/integtest/integtest.go b/dev-tools/mage/target/integtest/integtest.go index 33c924bbe18..ac9b671a2cf 100644 --- a/dev-tools/mage/target/integtest/integtest.go +++ b/dev-tools/mage/target/integtest/integtest.go @@ -62,6 +62,10 @@ func IntegTest() { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { + if !devtools.IsInIntegTestEnv() { + mg.SerialDeps(goTestDeps...) + } + return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) } From a01beab408e4ee0c24c5f92068d8b0f028eb4ede Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 08:57:14 -0800 Subject: [PATCH 04/14] Making progress, I think :) --- dev-tools/mage/common.go | 6 +----- dev-tools/mage/target/integtest/integtest.go | 4 ---- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/dev-tools/mage/common.go b/dev-tools/mage/common.go index 4b8215b7b43..151138d5f5b 100644 --- a/dev-tools/mage/common.go +++ b/dev-tools/mage/common.go @@ -193,11 +193,7 @@ func HaveDocker() error { // GetDockerInfo returns data from the docker info command. func GetDockerInfo() (*DockerInfo, error) { - dockerInfoOnce.Do(func() { - dockerInfoValue, dockerInfoErr = dockerInfo() - }) - - return dockerInfoValue, dockerInfoErr + return dockerInfo() } func dockerInfo() (*DockerInfo, error) { diff --git a/dev-tools/mage/target/integtest/integtest.go b/dev-tools/mage/target/integtest/integtest.go index ac9b671a2cf..33c924bbe18 100644 --- a/dev-tools/mage/target/integtest/integtest.go +++ b/dev-tools/mage/target/integtest/integtest.go @@ -62,10 +62,6 @@ func IntegTest() { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { - if !devtools.IsInIntegTestEnv() { - mg.SerialDeps(goTestDeps...) - } - return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) } From cb2ed6ee50d802adcee49895668bbe567a9a90bf Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 09:52:35 -0800 Subject: [PATCH 05/14] Testing --- dev-tools/mage/gotest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 2c8dd1cd2b7..798bcf5c755 100644 --- a/dev-tools/mage/gotest.go +++ b/dev-tools/mage/gotest.go @@ -148,7 +148,7 @@ func GoTestIntegrationForModule(ctx context.Context) error { return errors.New("integration tests failed") } return nil - }) + }, "BEATS_DOCKER_INTEGRATION_TEST_ENV=1") } // GoTest invokes "go test" and reports the results to stdout. It returns an From 23bff3481e611c53d19264d9362970d6ee377f12 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 11:13:36 -0800 Subject: [PATCH 06/14] Try a different way of passing the env var --- dev-tools/mage/gotest.go | 2 +- libbeat/scripts/Makefile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 798bcf5c755..2c8dd1cd2b7 100644 --- a/dev-tools/mage/gotest.go +++ b/dev-tools/mage/gotest.go @@ -148,7 +148,7 @@ func GoTestIntegrationForModule(ctx context.Context) error { return errors.New("integration tests failed") } return nil - }, "BEATS_DOCKER_INTEGRATION_TEST_ENV=1") + }) } // GoTest invokes "go test" and reports the results to stdout. It returns an diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 9a8fc91e678..01d906c6053 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -213,6 +213,7 @@ integration-tests-environment: prepare-tests build-image -e RACE_DETECTOR=$(RACE_DETECTOR) \ -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} \ + -e BEATS_DOCKER_INTEGRATION_TEST_ENV=1 \ beat make integration-tests # Runs the system tests From efa0c46f00c6f18de820743403126ca5e7746b9a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 11:57:41 -0800 Subject: [PATCH 07/14] Revert docker info change --- dev-tools/mage/common.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dev-tools/mage/common.go b/dev-tools/mage/common.go index 151138d5f5b..4b8215b7b43 100644 --- a/dev-tools/mage/common.go +++ b/dev-tools/mage/common.go @@ -193,7 +193,11 @@ func HaveDocker() error { // GetDockerInfo returns data from the docker info command. func GetDockerInfo() (*DockerInfo, error) { - return dockerInfo() + dockerInfoOnce.Do(func() { + dockerInfoValue, dockerInfoErr = dockerInfo() + }) + + return dockerInfoValue, dockerInfoErr } func dockerInfo() (*DockerInfo, error) { From 9ac6477b36b25d6d99eef8d0bcf59a4335b60ed8 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 12:28:40 -0800 Subject: [PATCH 08/14] Removing debugging statements --- libbeat/magefile.go | 4 ---- libbeat/scripts/Makefile | 2 -- metricbeat/magefile.go | 2 -- 3 files changed, 8 deletions(-) diff --git a/libbeat/magefile.go b/libbeat/magefile.go index d24de0b8359..efdbc87d497 100644 --- a/libbeat/magefile.go +++ b/libbeat/magefile.go @@ -21,8 +21,6 @@ package main import ( "context" - "fmt" - "os" devtools "github.com/elastic/beats/dev-tools/mage" @@ -56,7 +54,5 @@ func Config() error { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { - e, _ := os.LookupEnv("TEST_ENVIRONMENT") - fmt.Printf("In libbeat/magefile.go:GoIntegTest. TEST_ENVIRONMENT=%v\n", e) return devtools.GoTest(ctx, devtools.DefaultGoTestIntegrationArgs()) } diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 01d906c6053..04d6106340c 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -196,7 +196,6 @@ unit: ## @testing Runs the unit tests without coverage reports. .PHONY: integration-tests integration-tests: ## @testing Run integration tests. Unit tests are run as part of the integration tests. integration-tests: prepare-tests mage - echo "[integration-tests] TEST_ENVIRONMENT=${TEST_ENVIRONMENT}" rm -f docker-compose.yml.lock mage goIntegTest @@ -208,7 +207,6 @@ integration-tests-environment: prepare-tests build-image # # This will make docker-compose command to display the logs on stdout on error, It's not enabled # by default because it can create noise if the test inside the container fails. - echo "[integration-tests-environment] TEST_ENVIRONMENT=${TEST_ENVIRONMENT}" ${DOCKER_COMPOSE} run \ -e RACE_DETECTOR=$(RACE_DETECTOR) \ -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ diff --git a/metricbeat/magefile.go b/metricbeat/magefile.go index e23daf5831c..2a96df12bfb 100644 --- a/metricbeat/magefile.go +++ b/metricbeat/magefile.go @@ -167,7 +167,5 @@ func CollectDocs() error { // Use TEST_COVERAGE=true to enable code coverage profiling. // Use RACE_DETECTOR=true to enable the race detector. func GoIntegTest(ctx context.Context) error { - e, _ := os.LookupEnv("TEST_ENVIRONMENT") - fmt.Printf("In metricbeat/magefile.go:GoIntegTest. TEST_ENVIRONMENT=%v\n", e) return devtools.GoTestIntegrationForModule(ctx) } From 1e9c7c6e8ec4bf7dcf1a63970949b6ffbd770d52 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 24 Jan 2020 13:09:37 -0800 Subject: [PATCH 09/14] Ensure "AND"ing of build tags --- metricbeat/module/windows/perfmon/perfmon_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/windows/perfmon/perfmon_test.go b/metricbeat/module/windows/perfmon/perfmon_test.go index 77599ce82c4..1d43286e151 100644 --- a/metricbeat/module/windows/perfmon/perfmon_test.go +++ b/metricbeat/module/windows/perfmon/perfmon_test.go @@ -15,7 +15,8 @@ // specific language governing permissions and limitations // under the License. -// +build integration windows +// +build integration +// +build windows package perfmon From 4375bb3734c79cda6e3e34ddcb065702a1b797ea Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 28 Jan 2020 10:20:19 -0800 Subject: [PATCH 10/14] Don't explicitly pass BEATS_DOCKER_INTEGRATION_TEST_ENV --- libbeat/scripts/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 04d6106340c..0c9cd1a5fff 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -210,8 +210,7 @@ integration-tests-environment: prepare-tests build-image ${DOCKER_COMPOSE} run \ -e RACE_DETECTOR=$(RACE_DETECTOR) \ -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ - -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} \ - -e BEATS_DOCKER_INTEGRATION_TEST_ENV=1 \ + -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} beat make integration-tests # Runs the system tests From bef696020864b9ecc948ec2c45de3b03b20a1d9f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 28 Jan 2020 10:25:07 -0800 Subject: [PATCH 11/14] Move mage goIntegTest usage to metricbeat makefile --- libbeat/scripts/Makefile | 2 +- metricbeat/Makefile | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 0c9cd1a5fff..b53d9e5af50 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -197,7 +197,7 @@ unit: ## @testing Runs the unit tests without coverage reports. integration-tests: ## @testing Run integration tests. Unit tests are run as part of the integration tests. integration-tests: prepare-tests mage rm -f docker-compose.yml.lock - mage goIntegTest + $(COVERAGE_TOOL) -tags=integration $(RACE) -coverprofile=${COVERAGE_DIR}/integration.cov ${GOPACKAGES} .PHONY: integration-tests-environment integration-tests-environment: ## @testing Runs the integration inside a virtual environment. This can be run on any docker-machine (local, remote) diff --git a/metricbeat/Makefile b/metricbeat/Makefile index 2900f9e4cc7..92e7c48235e 100644 --- a/metricbeat/Makefile +++ b/metricbeat/Makefile @@ -3,6 +3,7 @@ BEAT_NAME?=metricbeat BEAT_TITLE?=Metricbeat SYSTEM_TESTS?=true TEST_ENVIRONMENT?=true +BEATS_DOCKER_INTEGRATION_TEST_ENV?=true ES_BEATS?=.. # Metricbeat can only be cross-compiled on platforms not requiring CGO. @@ -76,3 +77,9 @@ assets: go run ${ES_BEATS}/metricbeat/scripts/assets/assets.go ${ES_BEATS}/metricbeat/module mkdir -p include/fields go run ${ES_BEATS}/libbeat/scripts/cmd/global_fields/main.go -es_beats_path ${ES_BEATS} -beat_path ${PWD} | go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -license ${LICENSE} -out ./include/fields/fields.go -pkg include -priority asset.LibbeatFieldsPri ${ES_BEATS}/libbeat/fields.yml $(BEAT_NAME) + +.PHONY: integration-tests +integration-tests: ## @testing Run integration tests. Unit tests are run as part of the integration tests. +integration-tests: prepare-tests mage + rm -f docker-compose.yml.lock + mage goIntegTest From 7aaaeec7fab6035b37f0145c4b89c5157eb5e993 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 28 Jan 2020 10:26:41 -0800 Subject: [PATCH 12/14] Fixing up comment --- metricbeat/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricbeat/Makefile b/metricbeat/Makefile index 92e7c48235e..c0ff55b4435 100644 --- a/metricbeat/Makefile +++ b/metricbeat/Makefile @@ -79,7 +79,7 @@ assets: go run ${ES_BEATS}/libbeat/scripts/cmd/global_fields/main.go -es_beats_path ${ES_BEATS} -beat_path ${PWD} | go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -license ${LICENSE} -out ./include/fields/fields.go -pkg include -priority asset.LibbeatFieldsPri ${ES_BEATS}/libbeat/fields.yml $(BEAT_NAME) .PHONY: integration-tests -integration-tests: ## @testing Run integration tests. Unit tests are run as part of the integration tests. +integration-tests: ## @testing Run golang integration tests. integration-tests: prepare-tests mage rm -f docker-compose.yml.lock mage goIntegTest From d530cb3a21768fb7c77b33016e097f1d854e4c6a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 28 Jan 2020 11:23:44 -0800 Subject: [PATCH 13/14] Forgot the line continuation mark --- libbeat/scripts/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index b53d9e5af50..75b34481694 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -210,7 +210,7 @@ integration-tests-environment: prepare-tests build-image ${DOCKER_COMPOSE} run \ -e RACE_DETECTOR=$(RACE_DETECTOR) \ -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ - -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} + -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} \ beat make integration-tests # Runs the system tests From bef4f890d2ff67eba5c78992b2a44d205924397a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 28 Jan 2020 11:48:14 -0800 Subject: [PATCH 14/14] Pass the env var --- libbeat/scripts/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 75b34481694..db8236cdeef 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -211,6 +211,7 @@ integration-tests-environment: prepare-tests build-image -e RACE_DETECTOR=$(RACE_DETECTOR) \ -e DOCKER_COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} \ -e TEST_ENVIRONMENT=${TEST_ENVIRONMENT} \ + -e BEATS_DOCKER_INTEGRATION_TEST_ENV=${BEATS_DOCKER_INTEGRATION_TEST_ENV} \ beat make integration-tests # Runs the system tests