From 88568b932920f3a75544cbae9e8ba3050b531ac7 Mon Sep 17 00:00:00 2001 From: Sotiris Poulias Date: Mon, 20 May 2019 12:07:57 +0300 Subject: [PATCH 1/4] Opencensus - Elastica Integration --- .circleci/config.yml | 8 ++ composer.json | 1 + src/Trace/Integrations/Elastica.php | 88 +++++++++++++++++++ .../unit/Trace/Integrations/ElasticaTest.php | 73 +++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 src/Trace/Integrations/Elastica.php create mode 100644 tests/unit/Trace/Integrations/ElasticaTest.php diff --git a/.circleci/config.yml b/.circleci/config.yml index bc3473969..a511f0d4a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -141,6 +141,14 @@ jobs: environment: POSTGRES_PASSWORD: pgsql POSTGRES_USER: postgres + - image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4 + environment: + - cluster.name: group-project-test-cluster + - xpack.security.enabled: false + - transport.host: localhost + - network.host: 127.0.0.1 + - http.port: 9210 + - discovery.type: single-node steps: - checkout - run: diff --git a/composer.json b/composer.json index 52c257382..9d1821eff 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "squizlabs/php_codesniffer": "2.*", "twig/twig": "~2.0 || ~1.35", "symfony/yaml": "~3.3", + "ruflin/elastica": "6.0.2", "guzzlehttp/guzzle": "~5.3", "guzzlehttp/psr7": "~1.4" }, diff --git a/src/Trace/Integrations/Elastica.php b/src/Trace/Integrations/Elastica.php new file mode 100644 index 000000000..d00e4b01a --- /dev/null +++ b/src/Trace/Integrations/Elastica.php @@ -0,0 +1,88 @@ + $param) { + $attributes[$key] = $param; + } + + return [ + 'attributes' => $attributes, + 'kind' => Span::KIND_CLIENT, + ]; + } + + /** + * @param $elastica + * @param $path + * @param $method + * @param $data + * @param $query + * + * @return array + */ + public static function handleRequest($elastica, $path, $method, $data, $query) + { + return [ + 'attributes' => [ + 'path' => $path, + 'method' => $method, + 'data' => json_encode($data), + 'query' => json_encode($query), + ], + 'kind' => Span::KIND_CLIENT, + ]; + } +} diff --git a/tests/unit/Trace/Integrations/ElasticaTest.php b/tests/unit/Trace/Integrations/ElasticaTest.php new file mode 100644 index 000000000..4a5d0e5cf --- /dev/null +++ b/tests/unit/Trace/Integrations/ElasticaTest.php @@ -0,0 +1,73 @@ + 'http', + 'host' => 'elastic', + 'port' => '9200', + ]; + + $spanOptions = Elastica::handleConstruct($scope, $config); + $expected = [ + 'attributes' => [ + 'transport' => 'http', + 'host' => 'elastic', + 'port' => '9200', + ], + 'kind' => Span::KIND_CLIENT + ]; + + $this->assertEquals($expected, $spanOptions); + } + + public function testHandleRequest() + { + $scope = null; + $path = '/test/path'; + $method = 'GET'; + $data = []; + $query = []; + + $spanOptions = Elastica::handleRequest($scope, $path, $method, $data, $query); + $expected = [ + 'attributes' => [ + 'path' => $path, + 'method' => $method, + 'data' => json_encode($data), + 'query' => json_encode($query), + ], + 'kind' => Span::KIND_CLIENT + ]; + + $this->assertEquals($expected, $spanOptions); + } +} \ No newline at end of file From c4490f9bd9e277fddd1e0e3653ef6a25ebe981a5 Mon Sep 17 00:00:00 2001 From: Sotiris Poulias Date: Mon, 20 May 2019 12:15:28 +0300 Subject: [PATCH 2/4] Fix circleci elasticsearch image --- .circleci/config.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a511f0d4a..bc3473969 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -141,14 +141,6 @@ jobs: environment: POSTGRES_PASSWORD: pgsql POSTGRES_USER: postgres - - image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4 - environment: - - cluster.name: group-project-test-cluster - - xpack.security.enabled: false - - transport.host: localhost - - network.host: 127.0.0.1 - - http.port: 9210 - - discovery.type: single-node steps: - checkout - run: From 26fe5eca4f8d6d293c8755e99da9895b63ae342a Mon Sep 17 00:00:00 2001 From: Sotiris Poulias Date: Mon, 20 May 2019 12:27:35 +0300 Subject: [PATCH 3/4] Fix circleci php71-32bit --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc3473969..be828538a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,10 +107,10 @@ jobs: docker: - image: circleci/php:7.3-zts-node - php71-32bit: + php71-64bit: <<: *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 @@ -226,6 +226,6 @@ workflows: - php72-zts - php73 - php73-zts - - php71-32bit + - php71-64bit - php71-debug - integration \ No newline at end of file From a1ab08306db97e3fc11b54c77d0e77ff812a2948 Mon Sep 17 00:00:00 2001 From: Sotiris Poulias Date: Mon, 20 May 2019 12:33:31 +0300 Subject: [PATCH 4/4] Circleci php71-32bit --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index be828538a..bc3473969 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,10 +107,10 @@ jobs: docker: - image: circleci/php:7.3-zts-node - php71-64bit: + php71-32bit: <<: *unit-config docker: - - image: gcr.io/php-stackdriver/php71-64bit + - image: gcr.io/php-stackdriver/php71-32bit environment: TEST_PHP_ARGS: -q REPORT_EXIT_STATUS: 1 @@ -226,6 +226,6 @@ workflows: - php72-zts - php73 - php73-zts - - php71-64bit + - php71-32bit - php71-debug - integration \ No newline at end of file