From 8cc62593297c73dc2b6c628c620f6053b1d931f2 Mon Sep 17 00:00:00 2001 From: Pawel Filipczak Date: Mon, 22 Jul 2024 15:00:38 +0200 Subject: [PATCH] Fix Centos7 EOL issue, fixed tests bind host (#1181) * Try to solve missing centos mirror list * Updated centos images * Changed status check host * Modified bind address for test * Next try * Disabled WordPressAutoInstrumentationTest only on unstable environments * Separate usages of local host IPs for server and client usages --------- Co-authored-by: Sergey Kleyman --- agent/native/ext/ConfigManager.cpp | 2 +- .../Impl/Config/AllOptionsMetadata.php | 2 +- packaging/Makefile | 12 +++--- packaging/test/centos/CentOS-Base.repo | 31 +++++++++++++++ packaging/test/centos/Dockerfile | 2 + packaging/test/docker-compose.yml | 14 +++---- .../CurlAutoInstrumentationTest.php | 2 +- .../ComponentTests/HttpTransactionTest.php | 4 +- .../BuiltinHttpServerAppCodeHostStarter.php | 2 +- .../Util/ComponentTestCaseBase.php | 11 ++++-- .../Util/HttpAppCodeRequestParams.php | 2 +- .../ComponentTests/Util/HttpServerHandle.php | 3 +- .../ComponentTests/Util/HttpServerStarter.php | 2 +- .../ComponentTests/Util/TestCaseHandle.php | 3 +- .../Util/TestInfraHttpServerProcessBase.php | 2 +- .../WordPressAutoInstrumentationTest.php | 39 ++++++++++++++++++- .../ElasticApmTests/Util/LogSinkForTests.php | 32 ++++++++++----- 17 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 packaging/test/centos/CentOS-Base.repo diff --git a/agent/native/ext/ConfigManager.cpp b/agent/native/ext/ConfigManager.cpp index b27ed5998..5fb2f0dc3 100644 --- a/agent/native/ext/ConfigManager.cpp +++ b/agent/native/ext/ConfigManager.cpp @@ -964,7 +964,7 @@ static void initOptionsMetadata( OptionMetadata* optsMeta ) buildBoolOptionMetadata, astProcessEnabled, ELASTIC_APM_CFG_OPT_NAME_AST_PROCESS_ENABLED, - /* defaultValue: */ true ); + /* defaultValue: */ false ); ELASTIC_APM_INIT_METADATA( buildBoolOptionMetadata, diff --git a/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php b/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php index e3bd9ecd3..cf9dbbe01 100644 --- a/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php +++ b/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php @@ -82,7 +82,7 @@ public static function get(): array /** @var array> $value */ $value = [ OptionNames::API_KEY => new NullableStringOptionMetadata(), - OptionNames::AST_PROCESS_ENABLED => new BoolOptionMetadata(/* defaultValue: */ true), + OptionNames::AST_PROCESS_ENABLED => new BoolOptionMetadata(/* defaultValue: */ false), OptionNames::AST_PROCESS_DEBUG_DUMP_CONVERTED_BACK_TO_SOURCE => new BoolOptionMetadata(/* defaultValue: */ true), OptionNames::AST_PROCESS_DEBUG_DUMP_FOR_PATH_PREFIX => new NullableStringOptionMetadata(), diff --git a/packaging/Makefile b/packaging/Makefile index 16b7d1279..993775e5d 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -173,7 +173,7 @@ tar-install: ## Install the tar installer to run some smoke tests .PHONY: rpm-install rpm-install: ## Install the rpm installer to run some smoke tests @echo "::group::$@" # Helping to group logs in GitHub actions - TYPE=rpm $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.1 + TYPE=rpm $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: deb-install-in-apache @@ -206,7 +206,7 @@ deb-install-release-github: ## Install the deb installer from a given release to .PHONY: rpm-install-release-github rpm-install-release-github: ## Install the rpm installer from a given release to run some smoke tests @echo "::group::$@" # Helping to group logs in GitHub actions - VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=release-github $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.1 + VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=release-github $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: tar-install-release-github @@ -248,7 +248,7 @@ deb-lifecycle-testing-in-fpm: ## Lifecycle testing for the deb installer with fp .PHONY: rpm-lifecycle-testing rpm-lifecycle-testing: ## Lifecycle testing for the rpm installer @echo "::group::$@" # Helping to group logs in GitHub actions - TYPE=rpm-uninstall PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.1 + TYPE=rpm-uninstall PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: tar-lifecycle-testing @@ -263,13 +263,13 @@ rpm-php-upgrade-testing: PHP_VERSION=7.2 rpm-php-upgrade-testing: ## PHP upgrade, from 7.2 to 7.4, testing for the rpm installer @echo "::group::$@" # Helping to group logs in GitHub actions echo "'$(PHP_VERSION)'" - TYPE=php-upgrade PHP_VERSION=$(PHP_VERSION) PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.2 + TYPE=php-upgrade PHP_VERSION=$(PHP_VERSION) PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: rpm-agent-upgrade-testing rpm-agent-upgrade-testing: ## Agent upgrade, from 1.0.0 to the current generated one, testing for the rpm installer @echo "::group::$@" # Helping to group logs in GitHub actions - VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=agent-upgrade PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.1 + VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=agent-upgrade PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: deb-agent-upgrade-testing @@ -281,7 +281,7 @@ deb-agent-upgrade-testing: ## Agent upgrade, from 1.0.0 to the current generated .PHONY: rpm-agent-upgrade-testing-local rpm-agent-upgrade-testing-local: ## Agent upgrade, from 1.0.0 to the current generated one, testing for the rpm installer @echo "::group::$@" # Helping to group logs in GitHub actions - VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=agent-upgrade-local PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.1 + VERSION=$(RELEASE_VERSION) GITHUB_RELEASES_URL=$(GITHUB_RELEASES_URL) TYPE=agent-upgrade-local PACKAGE=$(NAME) $(PWD)/.ci/run_docker_with_component_tests.sh elasticobservability/apm-agent-php-dev:packages-test-rpm-php-$(PHP_VERSION)-0.0.3 @echo "::endgroup::" .PHONY: deb-agent-upgrade-testing-local diff --git a/packaging/test/centos/CentOS-Base.repo b/packaging/test/centos/CentOS-Base.repo new file mode 100644 index 000000000..51f62fd46 --- /dev/null +++ b/packaging/test/centos/CentOS-Base.repo @@ -0,0 +1,31 @@ +[base] +name=CentOS-$releasever - Base +#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os +baseurl=http://vault.centos.org/7.9.2009/os/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 + +#released updates +[updates] +name=CentOS-$releasever - Updates +#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates +baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 + +#additional packages that may be useful +[extras] +name=CentOS-$releasever - Extras +#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras +baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 + +#additional packages that extend functionality of existing packages +[centosplus] +name=CentOS-$releasever - Plus +#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus +baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/ +gpgcheck=1 +enabled=0 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 diff --git a/packaging/test/centos/Dockerfile b/packaging/test/centos/Dockerfile index 2720cc9bd..c8682c468 100644 --- a/packaging/test/centos/Dockerfile +++ b/packaging/test/centos/Dockerfile @@ -2,6 +2,8 @@ FROM centos:centos7 ARG PHP_VERSION=7.2 ENV PHP_VERSION ${PHP_VERSION} +COPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo + RUN yum update -y \ && yum install -y \ git \ diff --git a/packaging/test/docker-compose.yml b/packaging/test/docker-compose.yml index b94d35435..f738f3e97 100644 --- a/packaging/test/docker-compose.yml +++ b/packaging/test/docker-compose.yml @@ -158,49 +158,49 @@ services: - PHP_VERSION=7.2 rpm-php83: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.3-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.3-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=8.3 rpm-php82: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.2-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.2-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=8.2 rpm-php81: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.1-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.1-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=8.1 rpm-php80: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.0-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-8.0-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=8.0 rpm-php74: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.4-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.4-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=7.4 rpm-php73: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.3-0.0.1 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.3-0.0.3 build: context: centos dockerfile: Dockerfile args: - PHP_VERSION=7.3 rpm-php72: - image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.2-0.0.2 + image: elasticobservability/apm-agent-php-dev:packages-test-rpm-php-7.2-0.0.3 build: context: centos dockerfile: Dockerfile diff --git a/tests/ElasticApmTests/ComponentTests/CurlAutoInstrumentationTest.php b/tests/ElasticApmTests/ComponentTests/CurlAutoInstrumentationTest.php index be53d9855..b423d9c30 100644 --- a/tests/ElasticApmTests/ComponentTests/CurlAutoInstrumentationTest.php +++ b/tests/ElasticApmTests/ComponentTests/CurlAutoInstrumentationTest.php @@ -65,7 +65,7 @@ public static function appCodeClient(MixedMap $appCodeArgs): void $curlHandle = null; try { $curlHandle = HttpClientUtilForTests::createCurlHandleToSendRequestToAppCode( - (new UrlParts())->host(HttpServerHandle::DEFAULT_HOST)->port($serverPort), + (new UrlParts())->host(HttpServerHandle::CLIENT_LOCALHOST_ADDRESS)->port($serverPort), $dataPerRequest, self::buildResourcesClientForAppCode() ); diff --git a/tests/ElasticApmTests/ComponentTests/HttpTransactionTest.php b/tests/ElasticApmTests/ComponentTests/HttpTransactionTest.php index 5ffdb35bb..20f142539 100644 --- a/tests/ElasticApmTests/ComponentTests/HttpTransactionTest.php +++ b/tests/ElasticApmTests/ComponentTests/HttpTransactionTest.php @@ -86,10 +86,10 @@ function (HttpAppCodeRequestParams $appCodeRequestParams) use ($httpMethod, &$ex self::assertNotNull($tx->context->request); self::assertSame($httpMethod, $tx->context->request->method); self::assertNotNull($tx->context->request->url); - self::assertSame(HttpServerHandle::DEFAULT_HOST, $tx->context->request->url->domain); + self::assertSame(HttpServerHandle::CLIENT_LOCALHOST_ADDRESS, $tx->context->request->url->domain); self::assertNotNull($expectedUrlParts->port); $expectedFullUrl - = $expectedUrlParts->scheme . '://' . HttpServerHandle::DEFAULT_HOST . ':' . $expectedUrlParts->port . '/'; + = $expectedUrlParts->scheme . '://' . HttpServerHandle::CLIENT_LOCALHOST_ADDRESS . ':' . $expectedUrlParts->port . '/'; self::assertSame($expectedFullUrl, $tx->context->request->url->full); self::assertSame($expectedFullUrl, $tx->context->request->url->original); self::assertSame($expectedUrlParts->scheme, $tx->context->request->url->protocol); diff --git a/tests/ElasticApmTests/ComponentTests/Util/BuiltinHttpServerAppCodeHostStarter.php b/tests/ElasticApmTests/ComponentTests/Util/BuiltinHttpServerAppCodeHostStarter.php index 4b04ef3d2..473080fae 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/BuiltinHttpServerAppCodeHostStarter.php +++ b/tests/ElasticApmTests/ComponentTests/Util/BuiltinHttpServerAppCodeHostStarter.php @@ -74,7 +74,7 @@ protected function buildCommandLine(array $ports): string { Assert::assertCount(1, $ports); return InfraUtilForTests::buildAppCodePhpCmd($this->agentConfigSourceBuilder->getPhpIniFile()) - . " -S 0.0.0.0:" . $ports[0] + . ' -S ' . HttpServerHandle::SERVER_LOCALHOST_ADDRESS . ':' . $ports[0] . ' "' . FileUtilForTests::listToPath([__DIR__, self::APP_CODE_HOST_ROUTER_SCRIPT]) . '"'; } diff --git a/tests/ElasticApmTests/ComponentTests/Util/ComponentTestCaseBase.php b/tests/ElasticApmTests/ComponentTests/Util/ComponentTestCaseBase.php index c39134f6e..25859b172 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/ComponentTestCaseBase.php +++ b/tests/ElasticApmTests/ComponentTests/Util/ComponentTestCaseBase.php @@ -24,6 +24,7 @@ namespace ElasticApmTests\ComponentTests\Util; use Elastic\Apm\Impl\AutoInstrument\AutoInstrumentationBase; +use Elastic\Apm\Impl\Config\AllOptionsMetadata; use Elastic\Apm\Impl\Config\OptionNames; use Elastic\Apm\Impl\GlobalTracerHolder; use Elastic\Apm\Impl\Log\Level as LogLevel; @@ -197,7 +198,9 @@ protected static function implTestIsAutoInstrumentationEnabled(string $instrClas $actualNames = $instr->keywords(); $actualNames[] = $instr->name(); self::assertEqualAsSets($expectedNames, $actualNames); - self::assertTrue($instr->isEnabled()); + $astProcessEnabledDefaultValue = AllOptionsMetadata::get()[OptionNames::AST_PROCESS_ENABLED]->defaultValue(); + $isEnabledByDefault = $astProcessEnabledDefaultValue || (!$instr->requiresUserlandCodeInstrumentation()); + self::assertSame($isEnabledByDefault, $instr->isEnabled()); /** * @param string $name @@ -238,17 +241,17 @@ protected static function implTestIsAutoInstrumentationEnabled(string $instrClas $dbgCtx->clearCurrentSubScope(['disableInstrumentationsOptVal' => $disableInstrumentationsOptVal]); $tracer = self::buildTracerForTests()->withConfig(OptionNames::DISABLE_INSTRUMENTATIONS, $disableInstrumentationsOptVal)->build(); $instr = new $instrClassName($tracer); - self::assertTrue($instr->isEnabled()); + self::assertSame($isEnabledByDefault, $instr->isEnabled()); } $dbgCtx->popSubScope(); $dbgCtx->pushSubScope(); foreach ([true, false] as $astProcessEnabled) { $dbgCtx->clearCurrentSubScope(['astProcessEnabled' => $astProcessEnabled]); - $expectedIsEnabled = $astProcessEnabled || (!$instr->requiresUserlandCodeInstrumentation()); + $isEnabledByDefault = $astProcessEnabled || (!$instr->requiresUserlandCodeInstrumentation()); $tracer = self::buildTracerForTests()->withConfig(OptionNames::AST_PROCESS_ENABLED, BoolUtil::toString($astProcessEnabled))->build(); $instr = new $instrClassName($tracer); - self::assertSame($expectedIsEnabled, $instr->isEnabled()); + self::assertSame($isEnabledByDefault, $instr->isEnabled()); } $dbgCtx->popSubScope(); } diff --git a/tests/ElasticApmTests/ComponentTests/Util/HttpAppCodeRequestParams.php b/tests/ElasticApmTests/ComponentTests/Util/HttpAppCodeRequestParams.php index b0a6aeafb..65608c4c2 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/HttpAppCodeRequestParams.php +++ b/tests/ElasticApmTests/ComponentTests/Util/HttpAppCodeRequestParams.php @@ -42,7 +42,7 @@ public function __construct(HttpServerHandle $httpServerHandle, AppCodeTarget $a $this->urlParts = new UrlParts(); $this->urlParts->scheme('http') - ->host(HttpServerHandle::DEFAULT_HOST) + ->host(HttpServerHandle::CLIENT_LOCALHOST_ADDRESS) ->port($httpServerHandle->getMainPort()) ->path('/'); } diff --git a/tests/ElasticApmTests/ComponentTests/Util/HttpServerHandle.php b/tests/ElasticApmTests/ComponentTests/Util/HttpServerHandle.php index 9d408151f..692146a27 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/HttpServerHandle.php +++ b/tests/ElasticApmTests/ComponentTests/Util/HttpServerHandle.php @@ -38,7 +38,8 @@ class HttpServerHandle implements LoggableInterface { use LoggableTrait; - public const DEFAULT_HOST = '127.0.0.1'; + public const CLIENT_LOCALHOST_ADDRESS = '127.0.0.1'; + public const SERVER_LOCALHOST_ADDRESS = self::CLIENT_LOCALHOST_ADDRESS; public const STATUS_CHECK_URI_PATH = '/elastic_apm_php_tests_status_check'; public const PID_KEY = 'pid'; diff --git a/tests/ElasticApmTests/ComponentTests/Util/HttpServerStarter.php b/tests/ElasticApmTests/ComponentTests/Util/HttpServerStarter.php index 162c21c9a..603a62dbb 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/HttpServerStarter.php +++ b/tests/ElasticApmTests/ComponentTests/Util/HttpServerStarter.php @@ -223,7 +223,7 @@ function () use ($port, $dataPerRequest, $logger, &$lastThrown, &$pid) { try { $response = HttpClientUtilForTests::sendRequest( HttpConstantsForTests::METHOD_GET, - (new UrlParts())->host(HttpServerHandle::DEFAULT_HOST) + (new UrlParts())->host(HttpServerHandle::CLIENT_LOCALHOST_ADDRESS) ->port($port) ->path(HttpServerHandle::STATUS_CHECK_URI_PATH), $dataPerRequest diff --git a/tests/ElasticApmTests/ComponentTests/Util/TestCaseHandle.php b/tests/ElasticApmTests/ComponentTests/Util/TestCaseHandle.php index 5f6ea5c75..30135037f 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/TestCaseHandle.php +++ b/tests/ElasticApmTests/ComponentTests/Util/TestCaseHandle.php @@ -214,7 +214,8 @@ private function setMandatoryOptions(AppCodeHostParams $params): void $escalatedLogLevelForProdCodeAsString = LogLevel::intToName($this->escalatedLogLevelForProdCode); $params->setAgentOption(AmbientContextForTests::testConfig()->escalatedRerunsProdCodeLogLevelOptionName ?? OptionNames::LOG_LEVEL_SYSLOG, $escalatedLogLevelForProdCodeAsString); } - $params->setAgentOption(OptionNames::SERVER_URL, 'http://localhost:' . $this->mockApmServer->getPortForAgent()); + /** @noinspection HttpUrlsUsage */ + $params->setAgentOption(OptionNames::SERVER_URL, 'http://' . HttpServerHandle::CLIENT_LOCALHOST_ADDRESS . ':' . $this->mockApmServer->getPortForAgent()); if (!$this->isTestSpanCompressionCompatible) { $params->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false); diff --git a/tests/ElasticApmTests/ComponentTests/Util/TestInfraHttpServerProcessBase.php b/tests/ElasticApmTests/ComponentTests/Util/TestInfraHttpServerProcessBase.php index fa8073f16..4064051e3 100644 --- a/tests/ElasticApmTests/ComponentTests/Util/TestInfraHttpServerProcessBase.php +++ b/tests/ElasticApmTests/ComponentTests/Util/TestInfraHttpServerProcessBase.php @@ -167,7 +167,7 @@ private function runHttpServer(): void $this->reactLoop = Loop::get(); TestCase::assertNotEmpty(AmbientContextForTests::testConfig()->dataPerProcess->thisServerPorts); foreach (AmbientContextForTests::testConfig()->dataPerProcess->thisServerPorts as $port) { - $uri = HttpServerHandle::DEFAULT_HOST . ':' . $port; + $uri = HttpServerHandle::SERVER_LOCALHOST_ADDRESS . ':' . $port; $serverSocket = new SocketServer($uri, /* context */ [], $this->reactLoop); $socketIndex = count($this->serverSockets); $this->serverSockets[] = $serverSocket; diff --git a/tests/ElasticApmTests/ComponentTests/WordPressAutoInstrumentationTest.php b/tests/ElasticApmTests/ComponentTests/WordPressAutoInstrumentationTest.php index 35052cdfa..716340a53 100644 --- a/tests/ElasticApmTests/ComponentTests/WordPressAutoInstrumentationTest.php +++ b/tests/ElasticApmTests/ComponentTests/WordPressAutoInstrumentationTest.php @@ -45,6 +45,7 @@ use ElasticApmTests\Util\DataProviderForTestBuilder; use ElasticApmTests\Util\FileUtilForTests; use ElasticApmTests\Util\LogCategoryForTests; +use ElasticApmTests\Util\LogSinkForTests; use ElasticApmTests\Util\MetadataExpectations; use ElasticApmTests\Util\MixedMap; use ElasticApmTests\Util\SpanExpectations; @@ -133,6 +134,10 @@ private static function getLoggerForThisClass(): Logger public function testIsAutoInstrumentationEnabled(): void { + if (self::skipNotStableEnv(__FUNCTION__)) { + return; + } + // In production code ELASTIC_APM_WORDPRESS_DIRECT_CALL_METHOD_SET_READY_TO_WRAP_FILTER_CALLBACKS is defined by the native part of the agent // but if we don't load elastic_apm extension in the component tests so we need to define a dummy $constantName = 'ELASTIC_APM_WORDPRESS_DIRECT_CALL_METHOD_SET_READY_TO_WRAP_FILTER_CALLBACKS'; @@ -296,6 +301,10 @@ public function dataProviderForTestAstProcessOnMockSource(): iterable */ public function testAstProcessOnMockSource(MixedMap $testArgs): void { + if (self::skipNotStableEnv(__FUNCTION__)) { + return; + } + $subDirName = FileUtilForTests::buildTempSubDirName(__CLASS__, __FUNCTION__); self::runAndEscalateLogLevelOnFailure( self::buildDbgDescForTestWithArtgs(__CLASS__, __FUNCTION__, $testArgs), @@ -369,7 +378,7 @@ private static function verifyAstProcessGeneratedFiles(string $astProcessDebugDu $phpFileRelativePath ): void { AssertMessageStack::newScope(/* out */ $dbgCtx); - $dbgCtx->add(['isExpectedVariant' => $isExpectedVariant, 'isAstDebugDump' => $isAstDebugDump, 'fileFullPath' => $fileFullPath]); + $dbgCtx->add(compact('isExpectedVariant', 'isAstDebugDump', 'fileFullPath')); $outSubDir = self::buildInputOrExpectedOutputVariantSubDir($astProcessDebugDumpOutDir, $isExpectedVariant); $fileName = $phpFileRelativePath . '.' . ($isExpectedVariant ? self::BEFORE_AST_PROCESS_FILE_NAME_SUFFIX : self::AFTER_AST_PROCESS_FILE_NAME_SUFFIX); @@ -646,6 +655,10 @@ function (AppCodeRequestParams $appCodeRequestParams) use ($testArgs): void { */ public function testOnMockSource(MixedMap $testArgs): void { + if (self::skipNotStableEnv(__FUNCTION__)) { + return; + } + self::runAndEscalateLogLevelOnFailure( self::buildDbgDescForTestWithArtgs(__CLASS__, __FUNCTION__, $testArgs), function () use ($testArgs): void { @@ -731,6 +744,10 @@ function (AppCodeRequestParams $appCodeRequestParams) use ($testArgs): void { */ public function testFrameworkDiscovery(MixedMap $testArgs): void { + if (self::skipNotStableEnv(__FUNCTION__)) { + return; + } + self::runAndEscalateLogLevelOnFailure( self::buildDbgDescForTestWithArtgs(__CLASS__, __FUNCTION__, $testArgs), function () use ($testArgs): void { @@ -738,4 +755,24 @@ function () use ($testArgs): void { } ); } + + private static function skipNotStableEnv(string $testFunc): bool + { + $componentTestingMatrixRow = getenv('ELASTIC_APM_PHP_TESTS_MATRIX_ROW'); + if (!is_string($componentTestingMatrixRow)) { + return false; + } + + // Testing WordPress instrumentation based on AST processing is not stable on CentOS with PHP 8.0 and 8.3 + if (TextUtil::isPrefixOf('8.0,rpm,', $componentTestingMatrixRow) || TextUtil::isPrefixOf('8.3,rpm,', $componentTestingMatrixRow)) { + LogSinkForTests::writeLineToStdErr( + __CLASS__ . '::' . $testFunc . ' is effectively disabled because WordPress instrumentation based on AST processing is not stable on CentOS with PHP 8.0 and 8.3' + . '; ELASTIC_APM_PHP_TESTS_MATRIX_ROW environment variable: ' . $componentTestingMatrixRow + ); + self::dummyAssert(); + return true; + } + + return false; + } } diff --git a/tests/ElasticApmTests/Util/LogSinkForTests.php b/tests/ElasticApmTests/Util/LogSinkForTests.php index 6b6f8af71..0cae6e3ea 100644 --- a/tests/ElasticApmTests/Util/LogSinkForTests.php +++ b/tests/ElasticApmTests/Util/LogSinkForTests.php @@ -35,20 +35,29 @@ */ final class LogSinkForTests extends SinkBase { + /** @var ?bool */ + private static $isStderrDefined = null; + /** @var string */ private $dbgProcessName; - /** @var bool */ - private $isStderrDefined; - public function __construct(string $dbgProcessName) { $this->dbgProcessName = $dbgProcessName; + } - if (!defined('STDERR')) { - define('STDERR', fopen('php://stderr', 'w')); + private static function ensureStdErrIsDefined(): bool + { + if (self::$isStderrDefined === null) { + if (defined('STDERR')) { + self::$isStderrDefined = true; + } else { + define('STDERR', fopen('php://stderr', 'w')); + self::$isStderrDefined = defined('STDERR'); + } } - $this->isStderrDefined = defined('STDERR'); + + return self::$isStderrDefined; } protected function consumePreformatted( @@ -70,6 +79,13 @@ protected function consumePreformatted( $this->consumeFormatted($statementLevel, $formattedRecord); } + public static function writeLineToStdErr(string $text): void + { + if (self::ensureStdErrIsDefined()) { + fwrite(STDERR, $text . PHP_EOL); + } + } + private function consumeFormatted(int $statementLevel, string $statementText): void { if (OsUtilForTests::isWindows()) { @@ -80,9 +96,7 @@ private function consumeFormatted(int $statementLevel, string $statementText): v syslog(self::levelToSyslog($statementLevel), $statementText); } - if ($this->isStderrDefined) { - fwrite(STDERR, $statementText . PHP_EOL); - } + self::writeLineToStdErr($statementText); } public static function levelToString(int $level): string