From 6ff816f1f05a5e6e190acede19ae502f62b05c8a Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 08:50:58 +0100 Subject: [PATCH 1/6] Recommend upgrade to ext version 1.3.0 --- src/Agent.php | 2 +- src/Extension/Version.php | 17 ++--------------- tests/Unit/Extension/VersionTest.php | 1 + 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Agent.php b/src/Agent.php index f0f16e6e..e7ef7749 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -51,7 +51,7 @@ final class Agent implements ScoutApmAgent private const METADATA_CACHE_TTL_SECONDS = 600; - private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.0.2'; + private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.3.0'; /** @var Config */ private $config; diff --git a/src/Extension/Version.php b/src/Extension/Version.php index f6514b25..dc910471 100644 --- a/src/Extension/Version.php +++ b/src/Extension/Version.php @@ -53,21 +53,8 @@ public static function fromString(string $versionString): self public function isOlderThan(self $otherVersion): bool { - if ($this->major > $otherVersion->major) { - return false; - } - - if ($this->minor > $otherVersion->minor) { - return false; - } - - if ($this->patch > $otherVersion->patch) { - return false; - } - - return $otherVersion->major > $this->major - || $otherVersion->minor > $this->minor - || $otherVersion->patch > $this->patch; + return (($this->major * 1000000) + ($this->minor * 1000) + $this->patch) + < (($otherVersion->major * 1000000) + ($otherVersion->minor * 1000) + $otherVersion->patch); } public function toString(): string diff --git a/tests/Unit/Extension/VersionTest.php b/tests/Unit/Extension/VersionTest.php index 5ec884a1..2e46d134 100644 --- a/tests/Unit/Extension/VersionTest.php +++ b/tests/Unit/Extension/VersionTest.php @@ -27,6 +27,7 @@ public function olderThanVersionProvider(): array ['testVersion' => '1.0.0', 'isOlderThan' => '1.0.0', 'expectedResult' => false], ['testVersion' => '1.1.0', 'isOlderThan' => '1.1.0', 'expectedResult' => false], ['testVersion' => '1.1.1', 'isOlderThan' => '1.1.1', 'expectedResult' => false], + ['testVersion' => '1.3.0', 'isOlderThan' => '0.0.1', 'expectedResult' => false], ['testVersion' => '2.0.0', 'isOlderThan' => '1.0.2', 'expectedResult' => false], ['testVersion' => '2.0.0', 'isOlderThan' => '1.2.0', 'expectedResult' => false], ]; From f6841f9f577be804113913b071a48c7501f49130 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 08:54:57 +0100 Subject: [PATCH 2/6] Updated changelog for 6.3.0 patch to 1.3.0 recommended ext --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236a9131..970ce32d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 6.3.0 - TBC +## 6.3.0 - 2021-06-17 ### Added @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- Nothing. +- [#226](https://github.com/scoutapp/scout-apm-php/pull/226) Increased recommended extension version to 1.3.0 ### Deprecated From ecca660db070498e8d0addd9101ddbff434d43ae Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 10:31:46 +0100 Subject: [PATCH 3/6] Disable fail-fast on tests so we can see full matrix of failures --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 50a61b3e..5e04fee0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,7 @@ jobs: name: "Unit tests" runs-on: ubuntu-latest strategy: + fail-fast: false matrix: dependencies: ["lowest", "highest"] extensions: [ From 7d296c55fbcbdd9197e9558c399f3f6beab95f96 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 15:54:17 +0100 Subject: [PATCH 4/6] Updated recommended scout version to 1.4.0 --- CHANGELOG.md | 2 +- src/Agent.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 970ce32d..b00a8a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- [#226](https://github.com/scoutapp/scout-apm-php/pull/226) Increased recommended extension version to 1.3.0 +- [#226](https://github.com/scoutapp/scout-apm-php/pull/226) Increased recommended extension version to 1.4.0 ### Deprecated diff --git a/src/Agent.php b/src/Agent.php index e7ef7749..cc265f47 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -51,7 +51,7 @@ final class Agent implements ScoutApmAgent private const METADATA_CACHE_TTL_SECONDS = 600; - private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.3.0'; + private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.4.0'; /** @var Config */ private $config; From 2f1d684dd90a84cfd19f757bec07e16182fda1f3 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 16:46:41 +0100 Subject: [PATCH 5/6] If using scoutapm extension with scoutapm_enable_instrumentation function, call it to enable --- known-issues.xml | 11 ----------- src/Agent.php | 16 +++++++++------- src/Events/Metadata.php | 6 +++--- ...apabilities.php => ExtensionCapabilities.php} | 4 +++- ...PotentiallyAvailableExtensionCapabilities.php | 16 +++++++++++++++- src/ScoutApmBundle/ScoutApmAgentFactory.php | 6 +++--- tests/Unit/AgentTest.php | 6 +++--- tests/Unit/Events/MetadataTest.php | 6 +++--- .../ScoutApmBundle/ScoutApmAgentFactoryTest.php | 4 ++-- tests/psalm-stubs.php | 16 ++++++++++++++++ 10 files changed, 57 insertions(+), 34 deletions(-) rename src/Extension/{ExtentionCapabilities.php => ExtensionCapabilities.php} (78%) diff --git a/known-issues.xml b/known-issues.xml index ec59d3d2..26553147 100644 --- a/known-issues.xml +++ b/known-issues.xml @@ -138,17 +138,6 @@ $this->value - - - scoutapm_get_calls() - - - $call - - - list<RecordedCall> - - $composerContent['config'] diff --git a/src/Agent.php b/src/Agent.php index cc265f47..dd32f774 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -29,7 +29,7 @@ use Scoutapm\Events\Span\Span; use Scoutapm\Events\Span\SpanReference; use Scoutapm\Events\Tag\Tag; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities; use Scoutapm\Extension\Version; use Scoutapm\Helper\LocateFileOrFolder; @@ -65,7 +65,7 @@ final class Agent implements ScoutApmAgent private $ignoredEndpoints; /** @var bool If this request was marked as ignored*/ private $isIgnored = false; - /** @var ExtentionCapabilities */ + /** @var ExtensionCapabilities */ private $phpExtension; /** @var CacheInterface */ private $cache; @@ -80,7 +80,7 @@ private function __construct( Config $configuration, Connector $connector, LoggerInterface $logger, - ExtentionCapabilities $phpExtension, + ExtensionCapabilities $phpExtension, CacheInterface $cache, LocateFileOrFolder $locateFileOrFolder ) { @@ -136,14 +136,14 @@ public static function fromConfig( LoggerInterface $logger, ?CacheInterface $cache = null, ?Connector $connector = null, - ?ExtentionCapabilities $extentionCapabilities = null, + ?ExtensionCapabilities $extensionCapabilities = null, ?LocateFileOrFolder $locateFileOrFolder = null ): self { return new self( $config, $connector ?? self::createConnectorFromConfig($config), $logger, - $extentionCapabilities ?? new PotentiallyAvailableExtensionCapabilities(), + $extensionCapabilities ?? new PotentiallyAvailableExtensionCapabilities(), $cache ?? new DevNullCache(), $locateFileOrFolder ?? new LocateFileOrFolder() ); @@ -156,7 +156,7 @@ private function extensionVersion(): string return $extensionVersion === null ? 'n/a' : $extensionVersion->toString(); } - private function checkExtensionVersion(): void + private function checkExtensionVersionAndEnable(): void { $extensionVersion = $this->phpExtension->version(); @@ -175,6 +175,8 @@ private function checkExtensionVersion(): void $extensionVersion->toString(), $theMinimumRecommendedVersion->toString() )); + + $this->phpExtension->enable(); } public function connect(): void @@ -187,7 +189,7 @@ public function connect(): void return; } - $this->checkExtensionVersion(); + $this->checkExtensionVersionAndEnable(); if (! $this->connector->connected()) { $this->logger->info(sprintf( diff --git a/src/Events/Metadata.php b/src/Events/Metadata.php index 00ba06c0..48f1096e 100644 --- a/src/Events/Metadata.php +++ b/src/Events/Metadata.php @@ -9,7 +9,7 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; use Scoutapm\Connector\Command; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Helper\LocateFileOrFolder; use Scoutapm\Helper\Timer; @@ -40,7 +40,7 @@ final class Metadata implements Command private $timer; /** @var Config */ private $config; - /** @var ExtentionCapabilities */ + /** @var ExtensionCapabilities */ private $phpExtension; /** @var LocateFileOrFolder */ private $locateFileOrFolder; @@ -48,7 +48,7 @@ final class Metadata implements Command public function __construct( DateTimeImmutable $now, Config $config, - ExtentionCapabilities $phpExtension, + ExtensionCapabilities $phpExtension, LocateFileOrFolder $locateFileOrFolder ) { // Construct and stop the timer to use its timestamp logic. This event diff --git a/src/Extension/ExtentionCapabilities.php b/src/Extension/ExtensionCapabilities.php similarity index 78% rename from src/Extension/ExtentionCapabilities.php rename to src/Extension/ExtensionCapabilities.php index 9af04235..55c734d6 100644 --- a/src/Extension/ExtentionCapabilities.php +++ b/src/Extension/ExtensionCapabilities.php @@ -4,7 +4,7 @@ namespace Scoutapm\Extension; -interface ExtentionCapabilities +interface ExtensionCapabilities { /** @return RecordedCall[]|array */ public function getCalls(): array; @@ -12,4 +12,6 @@ public function getCalls(): array; public function clearRecordedCalls(): void; public function version(): ?Version; + + public function enable(): void; } diff --git a/src/Extension/PotentiallyAvailableExtensionCapabilities.php b/src/Extension/PotentiallyAvailableExtensionCapabilities.php index 8ab487ad..3c783d93 100644 --- a/src/Extension/PotentiallyAvailableExtensionCapabilities.php +++ b/src/Extension/PotentiallyAvailableExtensionCapabilities.php @@ -12,8 +12,22 @@ use function phpversion; use function scoutapm_get_calls; -final class PotentiallyAvailableExtensionCapabilities implements ExtentionCapabilities +final class PotentiallyAvailableExtensionCapabilities implements ExtensionCapabilities { + public function enable(): void + { + if (! $this->extensionIsAvailable()) { + return; + } + + // If the function doesn't exist, we're probably using an older `scoutapm` extension which doesn't need enabling + if (! function_exists('scoutapm_enable_instrumentation')) { + return; + } + + scoutapm_enable_instrumentation(true); + } + /** * @return RecordedCall[] * diff --git a/src/ScoutApmBundle/ScoutApmAgentFactory.php b/src/ScoutApmBundle/ScoutApmAgentFactory.php index 19af93f9..919caede 100644 --- a/src/ScoutApmBundle/ScoutApmAgentFactory.php +++ b/src/ScoutApmBundle/ScoutApmAgentFactory.php @@ -9,7 +9,7 @@ use Scoutapm\Agent; use Scoutapm\Config; use Scoutapm\Connector\Connector; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\ScoutApmAgent; use Symfony\Component\HttpKernel\Kernel; @@ -25,7 +25,7 @@ public static function createAgent( LoggerInterface $logger, ?CacheInterface $cache, ?Connector $connector, - ?ExtentionCapabilities $extentionCapabilities, + ?ExtensionCapabilities $extensionCapabilities, array $agentConfiguration ): ScoutApmAgent { return Agent::fromConfig( @@ -39,7 +39,7 @@ public static function createAgent( $logger, $cache, $connector, - $extentionCapabilities + $extensionCapabilities ); } } diff --git a/tests/Unit/AgentTest.php b/tests/Unit/AgentTest.php index 3df1adfb..1046a4d5 100644 --- a/tests/Unit/AgentTest.php +++ b/tests/Unit/AgentTest.php @@ -28,7 +28,7 @@ use Scoutapm\Events\Span\SpanReference; use Scoutapm\Events\Tag\Tag; use Scoutapm\Events\Tag\TagRequest; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\RecordedCall; use Scoutapm\Extension\Version; use Scoutapm\IntegrationTests\TestHelper; @@ -54,7 +54,7 @@ final class AgentTest extends TestCase /** @var Connector&MockObject */ private $connector; - /** @var ExtentionCapabilities&MockObject */ + /** @var ExtensionCapabilities&MockObject */ private $phpExtension; public function setUp(): void @@ -63,7 +63,7 @@ public function setUp(): void $this->logger = new TestLogger(); $this->connector = $this->createMock(Connector::class); - $this->phpExtension = $this->createMock(ExtentionCapabilities::class); + $this->phpExtension = $this->createMock(ExtensionCapabilities::class); } private function requestFromAgent(ScoutApmAgent $agent): ?Request diff --git a/tests/Unit/Events/MetadataTest.php b/tests/Unit/Events/MetadataTest.php index 51824da2..5f4c760b 100644 --- a/tests/Unit/Events/MetadataTest.php +++ b/tests/Unit/Events/MetadataTest.php @@ -13,7 +13,7 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; use Scoutapm\Events\Metadata; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\Version; use Scoutapm\Helper\LocateFileOrFolder; use Scoutapm\Helper\Timer; @@ -33,7 +33,7 @@ */ final class MetadataTest extends TestCase { - /** @var ExtentionCapabilities&MockObject */ + /** @var ExtensionCapabilities&MockObject */ private $phpExtension; /** @var LocateFileOrFolder&MockObject */ private $locateFileOrFolder; @@ -44,7 +44,7 @@ public function setUp(): void { parent::setUp(); - $this->phpExtension = $this->createMock(ExtentionCapabilities::class); + $this->phpExtension = $this->createMock(ExtensionCapabilities::class); $this->locateFileOrFolder = $this->createMock(LocateFileOrFolder::class); $this->time = new DateTimeImmutable('now', new DateTimeZone('UTC')); diff --git a/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php b/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php index ce6e9dc8..c3e7ffe3 100644 --- a/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php +++ b/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php @@ -10,7 +10,7 @@ use Scoutapm\Config\ConfigKey; use Scoutapm\Connector\Connector; use Scoutapm\Events\Metadata; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\ScoutApmBundle\ScoutApmAgentFactory; use function json_decode; @@ -24,7 +24,7 @@ public function testFactoryConfiguresFrameworkNameAndVersion(): void $logger = $this->createMock(LoggerInterface::class); $cache = $this->createMock(CacheInterface::class); $connector = $this->createMock(Connector::class); - $phpExtension = $this->createMock(ExtentionCapabilities::class); + $phpExtension = $this->createMock(ExtensionCapabilities::class); $connector->expects(self::at(3)) ->method('sendCommand') diff --git a/tests/psalm-stubs.php b/tests/psalm-stubs.php index dadadaf3..317bdbaf 100644 --- a/tests/psalm-stubs.php +++ b/tests/psalm-stubs.php @@ -3,6 +3,22 @@ /** @noinspection PhpIllegalPsrClassPathInspection */ declare(strict_types=1); +namespace { + function scoutapm_enable_instrumentation(bool $enabled): void + { + } + + /** @psalm-return list */ + function scoutapm_get_calls(): array + { + } + + /** @return list */ + function scoutapm_list_instrumented_functions(): array + { + } +} + namespace Composer { class InstalledVersions { /** From 911cc614065f609250bc03f21ab42dbdd9228f8c Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 17 Jun 2021 17:23:57 +0100 Subject: [PATCH 6/6] Avoid BC break by auto enabling the extension instrumentation when instantiating PotentiallyAvailableExtensionCapabilities --- phpcs.xml.dist | 3 +++ src/Agent.php | 6 ++---- src/Extension/ExtensionCapabilities.php | 6 ++++-- src/Extension/PotentiallyAvailableExtensionCapabilities.php | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 26d00837..6d4c1c1c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,4 +18,7 @@ + + src/Extension/ExtensionCapabilities.php + diff --git a/src/Agent.php b/src/Agent.php index dd32f774..1c56e3e2 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -156,7 +156,7 @@ private function extensionVersion(): string return $extensionVersion === null ? 'n/a' : $extensionVersion->toString(); } - private function checkExtensionVersionAndEnable(): void + private function checkExtensionVersion(): void { $extensionVersion = $this->phpExtension->version(); @@ -175,8 +175,6 @@ private function checkExtensionVersionAndEnable(): void $extensionVersion->toString(), $theMinimumRecommendedVersion->toString() )); - - $this->phpExtension->enable(); } public function connect(): void @@ -189,7 +187,7 @@ public function connect(): void return; } - $this->checkExtensionVersionAndEnable(); + $this->checkExtensionVersion(); if (! $this->connector->connected()) { $this->logger->info(sprintf( diff --git a/src/Extension/ExtensionCapabilities.php b/src/Extension/ExtensionCapabilities.php index 55c734d6..a2d06d37 100644 --- a/src/Extension/ExtensionCapabilities.php +++ b/src/Extension/ExtensionCapabilities.php @@ -4,6 +4,8 @@ namespace Scoutapm\Extension; +use function class_alias; + interface ExtensionCapabilities { /** @return RecordedCall[]|array */ @@ -12,6 +14,6 @@ public function getCalls(): array; public function clearRecordedCalls(): void; public function version(): ?Version; - - public function enable(): void; } + +class_alias(ExtensionCapabilities::class, ExtentionCapabilities::class); diff --git a/src/Extension/PotentiallyAvailableExtensionCapabilities.php b/src/Extension/PotentiallyAvailableExtensionCapabilities.php index 3c783d93..3dd051cd 100644 --- a/src/Extension/PotentiallyAvailableExtensionCapabilities.php +++ b/src/Extension/PotentiallyAvailableExtensionCapabilities.php @@ -14,7 +14,7 @@ final class PotentiallyAvailableExtensionCapabilities implements ExtensionCapabilities { - public function enable(): void + public function __construct() { if (! $this->extensionIsAvailable()) { return;