From 868081de6ad6e7e9c5872af6144f533e5a28c42c Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Thu, 11 Apr 2019 18:55:54 +0300 Subject: [PATCH 01/13] First draft of Redis Integration --- src/Trace/Integrations/Redis.php | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/Trace/Integrations/Redis.php diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php new file mode 100644 index 00000000000..4e369ca0307 --- /dev/null +++ b/src/Trace/Integrations/Redis.php @@ -0,0 +1,76 @@ + [ + 'host' => $params['host'], + 'port' => $params['port'], + 'db' => $params['database'], + ], + 'kind' => Span::KIND_CLIENT + ]; + } + + public static function handleConnect($redis, $params) + { + return [ + 'attributes' => [ + 'host' => $params['host'], + 'port' => $params['port'], + 'db' => $params['database'], + ], + 'kind' => Span::KIND_CLIENT + ]; + } + + public static function handleSet($redis, $key) + { + return [ + 'attributes' => ['setKey' => $key], + 'kind' => Span::KIND_CLIENT + ]; + } + + public static function handleGet($redis, $key) + { + return [ + 'attributes' => ['retrievedKey' => $key], + 'kind' => Span::KIND_CLIENT + ]; + } + +} \ No newline at end of file From 2ba67729308940c8f158a1fc65d35a2f35b89ef1 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Sat, 13 Apr 2019 01:32:49 +0300 Subject: [PATCH 02/13] Linting Redis.php --- src/Trace/Integrations/Redis.php | 57 +++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php index 4e369ca0307..8031a73d757 100644 --- a/src/Trace/Integrations/Redis.php +++ b/src/Trace/Integrations/Redis.php @@ -1,4 +1,19 @@ [ @@ -45,7 +67,13 @@ public static function handleConstruct($redis, $params) ]; } - public static function handleConnect($redis, $params) + /** + * Trace Connect Options + * + * @param $params + * @return array + */ + public static function handleConnect($params) { return [ 'attributes' => [ @@ -57,20 +85,17 @@ public static function handleConnect($redis, $params) ]; } - public static function handleSet($redis, $key) - { - return [ - 'attributes' => ['setKey' => $key], - 'kind' => Span::KIND_CLIENT - ]; - } - - public static function handleGet($redis, $key) + /** + * Trace Set / Get Operations + * + * @param $key + * @return array + */ + public static function handleIO($key) { return [ - 'attributes' => ['retrievedKey' => $key], + 'attributes' => ['key' => $key], 'kind' => Span::KIND_CLIENT ]; } - -} \ No newline at end of file +} From aeeb1ffd2f75d4ef19053ee7d025abc91588ebd5 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Sat, 13 Apr 2019 01:36:04 +0300 Subject: [PATCH 03/13] Adding Tests (draft) --- tests/integration/redis/composer.json | 17 ++++++++++ tests/integration/redis/phpunit.xml.dist | 21 +++++++++++++ tests/integration/redis/test.sh | 27 ++++++++++++++++ tests/integration/redis/tests/RedisTest.php | 35 +++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/integration/redis/composer.json create mode 100644 tests/integration/redis/phpunit.xml.dist create mode 100755 tests/integration/redis/test.sh create mode 100644 tests/integration/redis/tests/RedisTest.php diff --git a/tests/integration/redis/composer.json b/tests/integration/redis/composer.json new file mode 100644 index 00000000000..ff04dd7b76d --- /dev/null +++ b/tests/integration/redis/composer.json @@ -0,0 +1,17 @@ +{ + "require": { + "php": "^7.2", + "opencensus/opencensus": "dev-master", + "ext-opencensus": "*", + "ext-phpredis": "*" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/census-instrumentation/opencensus-php" + } + ] +} diff --git a/tests/integration/redis/phpunit.xml.dist b/tests/integration/redis/phpunit.xml.dist new file mode 100644 index 00000000000..a73902918cb --- /dev/null +++ b/tests/integration/redis/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + tests + + + + + src + + src/*/V[!a-zA-Z]* + src/*/*/V[!a-zA-Z]* + src/*/*/*/V[!a-zA-Z]* + + + + + + + diff --git a/tests/integration/redis/test.sh b/tests/integration/redis/test.sh new file mode 100755 index 00000000000..a7beaf91bcc --- /dev/null +++ b/tests/integration/redis/test.sh @@ -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 diff --git a/tests/integration/redis/tests/RedisTest.php b/tests/integration/redis/tests/RedisTest.php new file mode 100644 index 00000000000..a587d8f88e0 --- /dev/null +++ b/tests/integration/redis/tests/RedisTest.php @@ -0,0 +1,35 @@ + Date: Tue, 16 Apr 2019 18:17:38 +0300 Subject: [PATCH 04/13] Functional implementation of Predis Client --- src/Trace/Integrations/Redis.php | 37 ++++++++------------------------ 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php index 8031a73d757..746f71f64f7 100644 --- a/src/Trace/Integrations/Redis.php +++ b/src/Trace/Integrations/Redis.php @@ -37,49 +37,30 @@ class Redis implements IntegrationInterface public static function load() { if (!extension_loaded('opencensus')) { - trigger_error('opencensus extension required to load Memcached integrations.', E_USER_WARNING); - return; + trigger_error('opencensus extension required to load Redis integrations.', E_USER_WARNING); } - opencensus_trace_method('Redis', '__construct', [static::class, 'handleConstruct']); - opencensus_trace_method('Redis', 'set', [static::class, 'handleIO']); + opencensus_trace_method('Predis\Client', '__construct', [static::class, 'handleConstruct']); - opencensus_trace_method('Redis', 'get', [static::class, 'handleIO']); + opencensus_trace_method('Predis\Client', 'set', [static::class, 'handleCall']); - opencensus_trace_method('Redis', 'flushDB'); - } + opencensus_trace_method('Predis\Client', 'get', [static::class, 'handleCall']); - /** - * Trace Construct Options - * - * @param $params - * @return array - */ - public static function handleConstruct($params) - { - return [ - 'attributes' => [ - 'host' => $params['host'], - 'port' => $params['port'], - 'db' => $params['database'], - ], - 'kind' => Span::KIND_CLIENT - ]; + opencensus_trace_method('Predis\Client', 'flushDB'); } /** - * Trace Connect Options + * Trace Construct Options * * @param $params * @return array */ - public static function handleConnect($params) + public static function handleConstruct($predis, $params) { return [ 'attributes' => [ 'host' => $params['host'], - 'port' => $params['port'], - 'db' => $params['database'], + 'port' => $params['port'] ], 'kind' => Span::KIND_CLIENT ]; @@ -91,7 +72,7 @@ public static function handleConnect($params) * @param $key * @return array */ - public static function handleIO($key) + public static function handleCall($predis, $key) { return [ 'attributes' => ['key' => $key], From 37b2f13d66b5f258d9551db70237692d4b0b74af Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 00:42:17 +0300 Subject: [PATCH 05/13] Functional Version for Predis-PHP with tests --- composer.json | 1 + src/Trace/Integrations/Redis.php | 2 ++ tests/integration/redis/composer.json | 1 + tests/integration/redis/tests/RedisTest.php | 36 +++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/composer.json b/composer.json index 52c2573828c..c0b673bc461 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "twig/twig": "~2.0 || ~1.35", "symfony/yaml": "~3.3", "guzzlehttp/guzzle": "~5.3", + "predis/predis": "1.1.0", "guzzlehttp/psr7": "~1.4" }, "conflict": { diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php index 746f71f64f7..a2d57951f6d 100644 --- a/src/Trace/Integrations/Redis.php +++ b/src/Trace/Integrations/Redis.php @@ -52,6 +52,7 @@ public static function load() /** * Trace Construct Options * + * @param $predis * @param $params * @return array */ @@ -69,6 +70,7 @@ public static function handleConstruct($predis, $params) /** * Trace Set / Get Operations * + * @param $predis * @param $key * @return array */ diff --git a/tests/integration/redis/composer.json b/tests/integration/redis/composer.json index ff04dd7b76d..49b09b7ff6e 100644 --- a/tests/integration/redis/composer.json +++ b/tests/integration/redis/composer.json @@ -2,6 +2,7 @@ "require": { "php": "^7.2", "opencensus/opencensus": "dev-master", + "predis/predis": "1.1.0", "ext-opencensus": "*", "ext-phpredis": "*" }, diff --git a/tests/integration/redis/tests/RedisTest.php b/tests/integration/redis/tests/RedisTest.php index a587d8f88e0..4e53b49e5f0 100644 --- a/tests/integration/redis/tests/RedisTest.php +++ b/tests/integration/redis/tests/RedisTest.php @@ -17,8 +17,11 @@ 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 { @@ -32,4 +35,37 @@ public static function setUpBeforeClass() 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); + } } From c2929b150d287f5063acf2cb3edda914787699bf Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 00:55:44 +0300 Subject: [PATCH 06/13] Adding Redis on CircleCI pipeline --- .circleci/config.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc347396974..981a9e4af30 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -141,6 +141,10 @@ jobs: environment: POSTGRES_PASSWORD: pgsql POSTGRES_USER: postgres + - image: redis:3.2 + environment: + REDIS_HOST: 127.0.0.1 + REDIS_PORT: 6379 steps: - checkout - run: @@ -175,6 +179,9 @@ jobs: - run: name: Install pdo_mysql extension command: sudo docker-php-ext-install pdo_mysql + - run: + name: Install redis extension + command: sudo docker-php-ext-install redis - run: name: Install mysqli extension command: sudo docker-php-ext-install mysqli @@ -199,6 +206,9 @@ jobs: - run: name: Memcached test command: tests/integration/memcached/test.sh + - run: + name: Redis test + command: tests/integration/redis/test.sh - run: name: Pgsql test command: tests/integration/pgsql/test.sh From 5f63b19c223486a27872189e2122108802d5ef68 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 11:00:21 +0300 Subject: [PATCH 07/13] Fix Redis build step --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 981a9e4af30..ac3a04b0543 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -181,7 +181,9 @@ jobs: command: sudo docker-php-ext-install pdo_mysql - run: name: Install redis extension - command: sudo docker-php-ext-install redis + command: | + pecl install redis + sudo docker-php-ext-enable redis - run: name: Install mysqli extension command: sudo docker-php-ext-install mysqli From 245ed7e018b1ac8f922de9a7f977bcd513b45c03 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 11:10:56 +0300 Subject: [PATCH 08/13] Fix Redis build step --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac3a04b0543..8750928f6a0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,7 +182,7 @@ jobs: - run: name: Install redis extension command: | - pecl install redis + sudo pecl install redis sudo docker-php-ext-enable redis - run: name: Install mysqli extension From 62bdde10d1ac16d46af09c0409fecae422cc4f14 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 11:20:28 +0300 Subject: [PATCH 09/13] Fix Redis test step --- tests/integration/redis/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/redis/composer.json b/tests/integration/redis/composer.json index 49b09b7ff6e..b80ad734129 100644 --- a/tests/integration/redis/composer.json +++ b/tests/integration/redis/composer.json @@ -4,7 +4,7 @@ "opencensus/opencensus": "dev-master", "predis/predis": "1.1.0", "ext-opencensus": "*", - "ext-phpredis": "*" + "ext-redis": "*" }, "require-dev": { "phpunit/phpunit": "^7.0" From 15537d7f502217b27a8c8ce635b2a9d9fa9b07cf Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Wed, 17 Apr 2019 12:03:30 +0300 Subject: [PATCH 10/13] Removed php71-32bit build step (unable to find 32bit binary) --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8750928f6a0..02a722ee198 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -110,7 +110,7 @@ jobs: php71-32bit: <<: *unit-config docker: - - image: gcr.io/php-stackdriver/php71-32bit + - image: gcr.io/php-stackdriver/php71-64bit environment: TEST_PHP_ARGS: -q REPORT_EXIT_STATUS: 1 @@ -238,6 +238,5 @@ workflows: - php72-zts - php73 - php73-zts - - php71-32bit - php71-debug - integration \ No newline at end of file From 2bfe141c65172867114bde059e435b17cd155a31 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Fri, 10 May 2019 15:14:14 +0300 Subject: [PATCH 11/13] corrected comment mistake --- src/Trace/Integrations/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php index a2d57951f6d..4e695e6c007 100644 --- a/src/Trace/Integrations/Redis.php +++ b/src/Trace/Integrations/Redis.php @@ -32,7 +32,7 @@ class Redis implements IntegrationInterface { /** - * Static method to add instrumentation to memcache requests + * Static method to add instrumentation to redis requests */ public static function load() { From 0ccadf26d8514caf3d02fc3aee53916388b4b020 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Mon, 20 May 2019 13:18:31 +0300 Subject: [PATCH 12/13] Removed unupdated/unsupported php71-32bit as Debian 8 Jessie updates are no loger received --- .circleci/config.yml | 10 ---------- .travis.yml | 45 ++++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 02a722ee198..0ee5b37b2b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,16 +107,6 @@ jobs: docker: - image: circleci/php:7.3-zts-node - php71-32bit: - <<: *unit-config - docker: - - image: gcr.io/php-stackdriver/php71-64bit - environment: - TEST_PHP_ARGS: -q - REPORT_EXIT_STATUS: 1 - RUN_EXTENSION_TESTS: 1 - SUDO_CMD: "" - php71-debug: <<: *unit-config docker: diff --git a/.travis.yml b/.travis.yml index e1e103fd1ca..5b7818e0ddc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,28 @@ +dist: trusty language: php php: - '7.1' + - - '7.2' + - '7.3' -install: - - wget -O sami.phar http://get.sensiolabs.org/sami.phar - - wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.30.2/hugo_0.30.2_Linux-64bit.deb - - sudo dpkg -i /tmp/hugo.deb +before_install: + - autoconf -V + - sudo apt-get update -y + - sudo apt-get install -y -q --no-install-recommends + - sudo apt-get install -y build-essential + - sudo apt-get install -y g++ + - sudo apt-get install -y gcc + - sudo apt-get install -y libc-dev + - sudo apt-get install -y make + - sudo apt-get install -y autoconf + - sudo apt-get install -y git + - sudo apt-get install -y unzip + - sudo apt-get install -y pushd ext + - sudo apt-get install -y phpize + - ./configure --enable-opencensus + - make test || ((find . -name '*.diff' | xargs cat) && false) -script: - - pushd docs - - hugo - - popd - - cp config/sami.php config/sami-config.php - - php sami.phar update config/sami-config.php - - touch docs/.nojekyll -branches: - only: - - master - -deploy: - provider: pages - local_dir: docs/public - skip_cleanup: true - email: chingor@google.com # To satisfy the CLA check, replace this with bot email. - github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard - on: - branch: master +before_script: + - composer install -n --prefer-dist + - sudo cp config/php.ini /usr/local/etc/php \ No newline at end of file From 05b6261dfe42e4f4867ec57e1f5bc8f6bcb34b81 Mon Sep 17 00:00:00 2001 From: Angelos Roussakis Date: Mon, 20 May 2019 13:20:18 +0300 Subject: [PATCH 13/13] Reveted change on travis.yml --- .travis.yml | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b7818e0ddc..e1e103fd1ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,29 @@ -dist: trusty language: php php: - '7.1' - - - '7.2' - - '7.3' -before_install: - - autoconf -V - - sudo apt-get update -y - - sudo apt-get install -y -q --no-install-recommends - - sudo apt-get install -y build-essential - - sudo apt-get install -y g++ - - sudo apt-get install -y gcc - - sudo apt-get install -y libc-dev - - sudo apt-get install -y make - - sudo apt-get install -y autoconf - - sudo apt-get install -y git - - sudo apt-get install -y unzip - - sudo apt-get install -y pushd ext - - sudo apt-get install -y phpize - - ./configure --enable-opencensus - - make test || ((find . -name '*.diff' | xargs cat) && false) +install: + - wget -O sami.phar http://get.sensiolabs.org/sami.phar + - wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.30.2/hugo_0.30.2_Linux-64bit.deb + - sudo dpkg -i /tmp/hugo.deb +script: + - pushd docs + - hugo + - popd + - cp config/sami.php config/sami-config.php + - php sami.phar update config/sami-config.php + - touch docs/.nojekyll -before_script: - - composer install -n --prefer-dist - - sudo cp config/php.ini /usr/local/etc/php \ No newline at end of file +branches: + only: + - master + +deploy: + provider: pages + local_dir: docs/public + skip_cleanup: true + email: chingor@google.com # To satisfy the CLA check, replace this with bot email. + github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard + on: + branch: master