diff --git a/CHANGELOG.md b/CHANGELOG.md index ce6a0496..6044e98f 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 -- Nothing. +- [#170](https://github.com/scoutapp/scout-apm-php/pull/170) Always use musl instead of trying to detect libc flavour ### Deprecated diff --git a/src/Config.php b/src/Config.php index 7f445786..75d35e18 100644 --- a/src/Config.php +++ b/src/Config.php @@ -17,7 +17,6 @@ use Scoutapm\Config\TypeCoercion\CoerceBoolean; use Scoutapm\Config\TypeCoercion\CoerceJson; use Scoutapm\Config\TypeCoercion\CoerceType; -use Scoutapm\Helper\LibcDetection; use function array_combine; use function array_key_exists; use function array_map; @@ -41,7 +40,7 @@ public function __construct() $this->sources = [ new EnvSource(), $this->userSettingsSource, - new DerivedSource($this, new LibcDetection()), + new DerivedSource($this), new DefaultSource(), new NullSource(), ]; diff --git a/src/Config/Source/DerivedSource.php b/src/Config/Source/DerivedSource.php index 0352c04b..fc86f676 100644 --- a/src/Config/Source/DerivedSource.php +++ b/src/Config/Source/DerivedSource.php @@ -14,7 +14,6 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; -use Scoutapm\Helper\LibcDetection; use function in_array; use function php_uname; @@ -30,13 +29,9 @@ final class DerivedSource implements ConfigSource /** @var Config */ private $config; - /** @var LibcDetection */ - private $libcDetection; - - public function __construct(Config $config, LibcDetection $libcDetection) + public function __construct(Config $config) { - $this->config = $config; - $this->libcDetection = $libcDetection; + $this->config = $config; } /** @inheritDoc */ @@ -90,7 +85,12 @@ private function architecture() : string private function coreAgentTriple() : string { - $platform = 'unknown-linux-' . $this->libcDetection->detect(); + /** + * Since the `musl`-based agent should work on `glibc`-based systems, we can hard-code this now. + * + * @see https://github.com/scoutapp/scout-apm-php/issues/166 + */ + $platform = 'unknown-linux-musl'; $unamePlatform = php_uname('s'); if ($unamePlatform === 'Darwin') { diff --git a/tests/Unit/Config/Source/DerivedSourceTest.php b/tests/Unit/Config/Source/DerivedSourceTest.php index 7f1dcb2f..03944f2b 100644 --- a/tests/Unit/Config/Source/DerivedSourceTest.php +++ b/tests/Unit/Config/Source/DerivedSourceTest.php @@ -8,11 +8,6 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; use Scoutapm\Config\Source\DerivedSource; -use Scoutapm\Helper\LibcDetection; -use function sys_get_temp_dir; -use function tempnam; -use function uniqid; -use function unlink; /** @covers \Scoutapm\Config\Source\DerivedSource */ final class DerivedSourceTest extends TestCase @@ -29,7 +24,7 @@ public function setUp() : void $this->config = new Config(); - $this->derivedSource = new DerivedSource($this->config, new LibcDetection('/' . uniqid('file_should_not_exist', true))); + $this->derivedSource = new DerivedSource($this->config); } public function testHasKey() : void @@ -48,7 +43,7 @@ public function testGetReturnsNullWhenConfigKeyDoesNotExist() : void public function testCoreAgentFullNameIsDerivedCorrectly() : void { self::assertStringMatchesFormat( - 'scout_apm_core-v%d.%d.%d-%s-linux-gnu', + 'scout_apm_core-v%d.%d.%d-%s-linux-musl', $this->derivedSource->get(ConfigKey::CORE_AGENT_FULL_NAME) ); } @@ -63,19 +58,8 @@ public function testSocketPathIsDerivedCorrectly() : void ); } - public function testMuslIsDetectedWhenAlpineFileDetected() : void + public function testMuslIsUsedForLibcVersion() : void { - $muslHintFilename = tempnam(sys_get_temp_dir(), 'scoutapm_musl_hint_file'); - - $derivedSource = new DerivedSource(new Config(), new LibcDetection($muslHintFilename)); - - self::assertStringEndsWith('linux-musl', $derivedSource->get(ConfigKey::CORE_AGENT_TRIPLE)); - - unlink($muslHintFilename); - } - - public function testGnuLibcIsDetectedWhenAlpineFileDoesNotExist() : void - { - self::assertStringEndsWith('linux-gnu', $this->derivedSource->get(ConfigKey::CORE_AGENT_TRIPLE)); + self::assertStringEndsWith('linux-musl', $this->derivedSource->get(ConfigKey::CORE_AGENT_TRIPLE)); } } diff --git a/tests/Unit/Helper/LibcDetectionTest.php b/tests/Unit/Helper/LibcDetectionTest.php deleted file mode 100644 index 1ecd7244..00000000 --- a/tests/Unit/Helper/LibcDetectionTest.php +++ /dev/null @@ -1,54 +0,0 @@ -filename = tempnam(sys_get_temp_dir(), 'scoutapm_musl_hint_file'); - self::assertFileExists($this->filename); - - $this->libcDetection = new LibcDetection($this->filename); - } - - public function tearDown() : void - { - parent::tearDown(); - - if (! file_exists($this->filename)) { - return; - } - - unlink($this->filename); - } - - public function testDetectionOfMuslWhenHintFileExists() : void - { - self::assertSame('musl', $this->libcDetection->detect()); - } - - public function testDetectionOfGnuWhenHintFileDoesNotExist() : void - { - unlink($this->filename); - self::assertSame('gnu', $this->libcDetection->detect()); - } -}