This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add an integration test that reports to a dockerized Jaeger instance * license header * Fix test namespace * Remove unused import
- Loading branch information
Showing
7 changed files
with
247 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2018 OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM gcr.io/google-appengine/php72 | ||
|
||
COPY . $APP_DIR | ||
RUN composer install | ||
|
||
ENTRYPOINT [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./tests/integration/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite> | ||
<directory>tests/integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright 2018 OpenCensus Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace OpenCensus\Tests\Integration\Trace\Exporter; | ||
|
||
use GuzzleHttp\Client; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class JaegerExporterTest extends TestCase | ||
{ | ||
private static $jaegerClient; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
$jaegerHost = getenv('JAEGER_HOST') ?: 'localhost'; | ||
$jaegerPort = (int)(getenv('JAEGER_PORT') ?: 16686); | ||
self::$jaegerClient = new Client([ | ||
'base_uri' => sprintf('http://%s:%d/', $jaegerHost, $jaegerPort) | ||
]); | ||
} | ||
|
||
public function testReportsTraceToJaeger() | ||
{ | ||
$rand = mt_rand(); | ||
$client = new Client(['base_uri' => 'http://localhost:9000']); | ||
$response = $client->request('GET', '/', [ | ||
'query' => [ | ||
'rand' => $rand | ||
] | ||
]); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
$this->assertEquals('Hello world!', $response->getBody()->getContents()); | ||
|
||
$response = $this->findTraces($rand); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
$data = json_decode($response->getBody()->getContents(), true); | ||
$this->assertCount(1, $data['data']); | ||
$trace = $data['data'][0]; | ||
$this->assertCount(2, $trace['spans']); | ||
} | ||
|
||
public function testCanReachJaegerServer() | ||
{ | ||
$response = self::$jaegerClient->request('GET', '/search'); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
} | ||
|
||
private function findTraces($rand) | ||
{ | ||
return self::$jaegerClient->request('GET', '/api/traces', [ | ||
'query' => [ | ||
'service' => 'integration-test', | ||
'operation' => "/?rand=$rand", | ||
'limit' => 20, | ||
'lookback' => '1h' | ||
] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright 2018 OpenCensusAuthors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* This PHPUnit bootstrap file starts a local web server using the built-in | ||
* PHP web server. The PHPUnit tests that run then hit this running server. | ||
* We also register a shutdown function to stop this server after tests have | ||
* run. | ||
*/ | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
$host = getenv('TESTHOST') ?: 'localhost'; | ||
$port = (int)(getenv('TESTPORT') ?: 9000); | ||
putenv( | ||
sprintf( | ||
'TESTURL=http://%s:%d', | ||
$host, | ||
$port | ||
) | ||
); | ||
|
||
$command = sprintf( | ||
'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!', | ||
$host, | ||
$port, | ||
__DIR__ . '/web' | ||
); | ||
|
||
$output = []; | ||
printf('Starting web server with command: %s' . PHP_EOL, $command); | ||
exec($command, $output); | ||
$pid = (int) $output[0]; | ||
|
||
printf( | ||
'%s - Web server started on %s:%d with PID %d', | ||
date('r'), | ||
$host, | ||
$port, | ||
$pid | ||
); | ||
|
||
// Give the server time to boot. | ||
sleep(1); | ||
|
||
// Kill the web server when the process ends | ||
register_shutdown_function(function() use ($pid) { | ||
echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL; | ||
exec('kill ' . $pid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright 2018 OpenCensus Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
use OpenCensus\Trace\Exporter\JaegerExporter; | ||
use OpenCensus\Trace\Tracer; | ||
|
||
$host = getenv('JAEGER_HOST') ?: 'localhost'; | ||
$exporter = new JaegerExporter('integration-test', [ | ||
'host' => $host, | ||
'tags' => [ | ||
'asdf' => 'qwer' | ||
] | ||
]); | ||
|
||
Tracer::start($exporter, [ | ||
'attributes' => [ | ||
'foo' => 'bar' | ||
] | ||
]); | ||
|
||
Tracer::inSpan( | ||
['name' => 'slow_function'], | ||
function () { | ||
usleep(50); | ||
} | ||
); | ||
|
||
echo 'Hello world!'; |