This repository was archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
OpenCensus - Redis Integration #236
Open
asenlog
wants to merge
13
commits into
census-instrumentation:master
Choose a base branch
from
asenlog:redis-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
868081d
First draft of Redis Integration
2ba6772
Linting Redis.php
aeeb1ff
Adding Tests (draft)
61fe9c7
Functional implementation of Predis Client
37b2f13
Functional Version for Predis-PHP with tests
c2929b1
Adding Redis on CircleCI pipeline
5f63b19
Fix Redis build step
245ed7e
Fix Redis build step
62bdde1
Fix Redis test step
15537d7
Removed php71-32bit build step (unable to find 32bit binary)
2bfe141
corrected comment mistake
0ccadf2
Removed unupdated/unsupported php71-32bit as Debian 8 Jessie updates …
05b6261
Reveted change on travis.yml
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2019 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\Trace\Integrations; | ||
|
|
||
| use OpenCensus\Trace\Span; | ||
|
|
||
| /** | ||
| * This class handles instrumenting Redis requests using the opencensus extension. | ||
| * | ||
| * Example: | ||
| * ``` | ||
| * use OpenCensus\Trace\Integrations\Redis; | ||
| * | ||
| * Redis::load(); | ||
| * ``` | ||
| */ | ||
| class Redis implements IntegrationInterface | ||
| { | ||
| /** | ||
| * Static method to add instrumentation to memcache requests | ||
asenlog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public static function load() | ||
| { | ||
| if (!extension_loaded('opencensus')) { | ||
| trigger_error('opencensus extension required to load Redis integrations.', E_USER_WARNING); | ||
| } | ||
|
|
||
| opencensus_trace_method('Predis\Client', '__construct', [static::class, 'handleConstruct']); | ||
|
|
||
| opencensus_trace_method('Predis\Client', 'set', [static::class, 'handleCall']); | ||
|
|
||
| opencensus_trace_method('Predis\Client', 'get', [static::class, 'handleCall']); | ||
|
|
||
| opencensus_trace_method('Predis\Client', 'flushDB'); | ||
| } | ||
|
|
||
| /** | ||
| * Trace Construct Options | ||
| * | ||
| * @param $predis | ||
| * @param $params | ||
| * @return array | ||
| */ | ||
| public static function handleConstruct($predis, $params) | ||
| { | ||
| return [ | ||
| 'attributes' => [ | ||
| 'host' => $params['host'], | ||
| 'port' => $params['port'] | ||
| ], | ||
| 'kind' => Span::KIND_CLIENT | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Trace Set / Get Operations | ||
| * | ||
| * @param $predis | ||
| * @param $key | ||
| * @return array | ||
| */ | ||
| public static function handleCall($predis, $key) | ||
| { | ||
| return [ | ||
| 'attributes' => ['key' => $key], | ||
| 'kind' => Span::KIND_CLIENT | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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,18 @@ | ||
| { | ||
| "require": { | ||
| "php": "^7.2", | ||
| "opencensus/opencensus": "dev-master", | ||
| "predis/predis": "1.1.0", | ||
| "ext-opencensus": "*", | ||
| "ext-redis": "*" | ||
| }, | ||
| "require-dev": { | ||
| "phpunit/phpunit": "^7.0" | ||
| }, | ||
| "repositories": [ | ||
| { | ||
| "type": "git", | ||
| "url": "https://github.com/census-instrumentation/opencensus-php" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,21 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <phpunit bootstrap="./vendor/autoload.php" colors="true"> | ||
| <testsuites> | ||
| <testsuite> | ||
| <directory>tests</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| <filter> | ||
| <whitelist> | ||
| <directory suffix=".php">src</directory> | ||
| <exclude> | ||
| <directory suffix=".php">src/*/V[!a-zA-Z]*</directory> | ||
| <directory suffix=".php">src/*/*/V[!a-zA-Z]*</directory> | ||
| <directory suffix=".php">src/*/*/*/V[!a-zA-Z]*</directory> | ||
| </exclude> | ||
| </whitelist> | ||
| </filter> | ||
| <logging> | ||
| <log type="coverage-clover" target="build/clover.xml"/> | ||
| </logging> | ||
| </phpunit> |
This file contains hidden or 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,27 @@ | ||
| #!/bin/bash | ||
| # 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. | ||
|
|
||
| set -e | ||
|
|
||
| pushd $(dirname ${BASH_SOURCE[0]}) | ||
| source ../setup_test_repo.sh | ||
|
|
||
| sed -i "s|dev-master|dev-${BRANCH}|" composer.json | ||
| sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json | ||
| composer install -n --prefer-dist | ||
|
|
||
| vendor/bin/phpunit | ||
|
|
||
| popd |
This file contains hidden or 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,71 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2019 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 OpenCensus\Trace\Tracer; | ||
| use OpenCensus\Trace\Exporter\ExporterInterface; | ||
| use OpenCensus\Trace\Integrations\Redis as RedisIntegration; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Predis\Client; | ||
|
|
||
| class RedisTest extends TestCase | ||
| { | ||
| private $tracer; | ||
| private static $redisHost; | ||
| private static $redisPort; | ||
|
|
||
| public static function setUpBeforeClass() | ||
| { | ||
| RedisIntegration::load(); | ||
| self::$redisHost = getenv('REDIS_HOST') ?: '127.0.0.1'; | ||
| self::$redisPort = (int) (getenv('REDIS_PORT') ?: 6379); | ||
| } | ||
|
|
||
| public function setUp() | ||
| { | ||
| if (!extension_loaded('opencensus')) { | ||
| $this->markTestSkipped('Please enable the opencensus extension.'); | ||
| } | ||
| opencensus_trace_clear(); | ||
| $exporter = $this->prophesize(ExporterInterface::class); | ||
| $this->tracer = Tracer::start($exporter->reveal(), [ | ||
| 'skipReporting' => true | ||
| ]); | ||
| } | ||
|
|
||
| private function getSpans() | ||
| { | ||
| $this->tracer->onExit(); | ||
| return $this->tracer->tracer()->spans(); | ||
| } | ||
|
|
||
| public function testAddGet() | ||
| { | ||
| $client = new Client([ | ||
| 'host' => self::$redisHost, | ||
| 'port' => self::$redisPort | ||
| ]); | ||
|
|
||
| $client->set('foo', 'bar'); | ||
| $value = $client->get('foo'); | ||
| $this->assertEquals('bar', $value); | ||
|
|
||
| $spans = $this->getSpans(); | ||
| $this->assertCount(4, $spans); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.