Skip to content

Commit

Permalink
Merge pull request #170 from scoutapp/default-to-musl
Browse files Browse the repository at this point in the history
Default to musl for libc detection
  • Loading branch information
Chris Schneider authored Mar 3, 2020
2 parents 00aab45 + 265e6b7 commit 6cb2650
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 85 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
];
Expand Down
16 changes: 8 additions & 8 deletions src/Config/Source/DerivedSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use Scoutapm\Config;
use Scoutapm\Config\ConfigKey;
use Scoutapm\Helper\LibcDetection;
use function in_array;
use function php_uname;

Expand All @@ -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 */
Expand Down Expand Up @@ -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') {
Expand Down
24 changes: 4 additions & 20 deletions tests/Unit/Config/Source/DerivedSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
);
}
Expand All @@ -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));
}
}
54 changes: 0 additions & 54 deletions tests/Unit/Helper/LibcDetectionTest.php

This file was deleted.

0 comments on commit 6cb2650

Please sign in to comment.