From d81285a3e43723dca2f97d1540b7f7123ffb9494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chema=20Mart=C3=ADnez?= Date: Fri, 4 Jul 2025 12:14:16 +0200 Subject: [PATCH] x-pack/filebeat/input/gcppubsub: fix integration tests (#45150) Solved two issues in the GCP Pub/Sub input tests: - GCP Pub/Sub Emulator Container Missing: this has been fixed by ensuring the Pub/Sub emulator Docker container is properly launched for the test environment. - Fix for Segfault in NewInput.func2: a segmentation fault occurred when test code accessed in.metrics before it was initialized. Metrics are now explicitly initialized in the test setup to avoid nil pointer dereferencing. (cherry picked from commit 5373f23794f7015b71cf265b0adc3141fb499a5b) --- CHANGELOG-developer.next.asciidoc | 1 + dev-tools/mage/integtest_docker.go | 2 ++ .../environments/docker/googlepubsub}/Dockerfile | 0 .../docker/googlepubsub}/supported-versions.yml | 0 x-pack/agentbeat/docker-compose.yml | 10 ++++++++++ x-pack/filebeat/docker-compose.yml | 10 ++++++++++ x-pack/filebeat/input/gcppubsub/docker-compose.yml | 11 ----------- x-pack/filebeat/input/gcppubsub/pubsub_test.go | 2 ++ 8 files changed, 25 insertions(+), 11 deletions(-) rename {x-pack/filebeat/input/gcppubsub/_meta => testing/environments/docker/googlepubsub}/Dockerfile (100%) rename {x-pack/filebeat/input/gcppubsub/_meta => testing/environments/docker/googlepubsub}/supported-versions.yml (100%) delete mode 100644 x-pack/filebeat/input/gcppubsub/docker-compose.yml diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 738630859259..cf3027aeee38 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -114,6 +114,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only. - Fix IIS module logging errors in case application pool PDH counter is not found. {pull}42274[42274] - Removed direct dependency on Azure/go-autorest/autorest/adal, which is deprecated. {issue}41463[41463] {pull}42959[42959] - Fixed flaky zookeeper integration tests. {pull}43638[43638] +- Fixed Fileebat GCP Pub/Sub input integration tests. {pull}45150[45150] ==== Added diff --git a/dev-tools/mage/integtest_docker.go b/dev-tools/mage/integtest_docker.go index c1b094984667..c9c16e2193e5 100644 --- a/dev-tools/mage/integtest_docker.go +++ b/dev-tools/mage/integtest_docker.go @@ -191,6 +191,8 @@ func WithGoIntegTestHostEnv(env map[string]string) map[string]string { // images for the next release after a feature freeze, which causes temporary test failures. env["TESTING_FILEBEAT_ALLOW_OLDER"] = "1" + env["PUBSUB_EMULATOR_HOST"] = "localhost:8432" + return env } diff --git a/x-pack/filebeat/input/gcppubsub/_meta/Dockerfile b/testing/environments/docker/googlepubsub/Dockerfile similarity index 100% rename from x-pack/filebeat/input/gcppubsub/_meta/Dockerfile rename to testing/environments/docker/googlepubsub/Dockerfile diff --git a/x-pack/filebeat/input/gcppubsub/_meta/supported-versions.yml b/testing/environments/docker/googlepubsub/supported-versions.yml similarity index 100% rename from x-pack/filebeat/input/gcppubsub/_meta/supported-versions.yml rename to testing/environments/docker/googlepubsub/supported-versions.yml diff --git a/x-pack/agentbeat/docker-compose.yml b/x-pack/agentbeat/docker-compose.yml index b4dbda4d86f6..37eb6dd516c4 100644 --- a/x-pack/agentbeat/docker-compose.yml +++ b/x-pack/agentbeat/docker-compose.yml @@ -20,6 +20,16 @@ services: ports: - 9200:9200 + googlepubsub: + image: docker.elastic.co/integrations-ci/beats-googlepubsub:emulator-${SDK_VERSION:-398.0.0-0}-1 + build: + context: ${ES_BEATS}/testing/environments/docker/googlepubsub + args: + SDK_VERSION: ${SDK_VERSION:-398.0.0-0} + hostname: googlepubsub + ports: + - 8432:8432 + cometd: build: ${ES_BEATS}/testing/environments/docker/cometd hostname: cometd diff --git a/x-pack/filebeat/docker-compose.yml b/x-pack/filebeat/docker-compose.yml index dfb2a061e91b..3638a7e9b25f 100644 --- a/x-pack/filebeat/docker-compose.yml +++ b/x-pack/filebeat/docker-compose.yml @@ -20,6 +20,16 @@ services: ports: - 9200:9200 + googlepubsub: + image: docker.elastic.co/integrations-ci/beats-googlepubsub:emulator-${SDK_VERSION:-398.0.0-0}-1 + build: + context: ${ES_BEATS}/testing/environments/docker/googlepubsub + args: + SDK_VERSION: ${SDK_VERSION:-398.0.0-0} + hostname: googlepubsub + ports: + - 8432:8432 + cometd: build: ${ES_BEATS}/testing/environments/docker/cometd hostname: cometd diff --git a/x-pack/filebeat/input/gcppubsub/docker-compose.yml b/x-pack/filebeat/input/gcppubsub/docker-compose.yml deleted file mode 100644 index 60ce3ebd83f7..000000000000 --- a/x-pack/filebeat/input/gcppubsub/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: '2.3' - -services: - googlepubsub: - image: docker.elastic.co/integrations-ci/beats-googlepubsub:emulator-${SDK_VERSION:-398.0.0-0}-1 - build: - context: ./_meta - args: - SDK_VERSION: ${SDK_VERSION:-398.0.0-0} - ports: - - '127.0.0.1:8432:8432' diff --git a/x-pack/filebeat/input/gcppubsub/pubsub_test.go b/x-pack/filebeat/input/gcppubsub/pubsub_test.go index 7e719d7102db..6e845d3f3d1d 100644 --- a/x-pack/filebeat/input/gcppubsub/pubsub_test.go +++ b/x-pack/filebeat/input/gcppubsub/pubsub_test.go @@ -251,6 +251,8 @@ func runTestWithACKer(t *testing.T, cfg *conf.C, onEvent eventHandler, run func( } //nolint:errcheck // ignore pubsubInput := in.(*pubsubInput) + // Initialize metrics explicitly for tests + pubsubInput.metrics = newInputMetrics("", nil) defer pubsubInput.Stop() run(client, pubsubInput, eventOutlet, t)