From bf8994fa3aabfba8bd37b4b20268408e71c0766a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 May 2021 13:55:01 +0200 Subject: [PATCH] Revert "feat(influxdb): introduce official client SDK" This reverts commit 15522c2cb98128e4c27bef6ae6b3a70f7f843a36. --- app/controllers/api/functions.php | 14 +++++---- app/controllers/api/projects.php | 12 ++++---- app/init.php | 11 ++----- composer.json | 4 +-- composer.lock | 48 +------------------------------ 5 files changed, 21 insertions(+), 68 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 9e1d2d97a..ff8b7d5bc 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -192,8 +192,7 @@ App::get('/v1/functions/:functionId/usage') 'group' => '1d', ], ]; - - /** @var InfluxDB2\Client $client */ + $client = $register->get('influxdb'); $executions = []; @@ -203,12 +202,13 @@ App::get('/v1/functions/:functionId/usage') if ($client) { $start = $period[$range]['start']->format(DateTime::RFC3339); $end = $period[$range]['end']->format(DateTime::RFC3339); - $database = $client->createQueryApi(); + $database = $client->selectDB('telegraf'); // Executions $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $executions[] = [ 'value' => (!empty($point['value'])) ? $point['value'] : 0, 'date' => \strtotime($point['time']), @@ -217,8 +217,9 @@ App::get('/v1/functions/:functionId/usage') // Failures $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' AND "functionStatus"=\'failed\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $failures[] = [ 'value' => (!empty($point['value'])) ? $point['value'] : 0, 'date' => \strtotime($point['time']), @@ -227,8 +228,9 @@ App::get('/v1/functions/:functionId/usage') // Compute $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_time" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $compute[] = [ 'value' => round((!empty($point['value'])) ? $point['value'] / 1000 : 0, 2), // minutes 'date' => \strtotime($point['time']), diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 3a14c94c8..0b9eb64ff 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -206,7 +206,6 @@ App::get('/v1/projects/:projectId/usage') ], ]; - /** @var InfluxDB2\Client $client */ $client = $register->get('influxdb'); $requests = []; @@ -216,12 +215,13 @@ App::get('/v1/projects/:projectId/usage') if ($client) { $start = $period[$range]['start']->format(DateTime::RFC3339); $end = $period[$range]['end']->format(DateTime::RFC3339); - $database = $client->createQueryApi(); + $database = $client->selectDB('telegraf'); // Requests $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_requests_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $requests[] = [ 'value' => (!empty($point['value'])) ? $point['value'] : 0, 'date' => \strtotime($point['time']), @@ -230,8 +230,9 @@ App::get('/v1/projects/:projectId/usage') // Network $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_network_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $network[] = [ 'value' => (!empty($point['value'])) ? $point['value'] : 0, 'date' => \strtotime($point['time']), @@ -240,8 +241,9 @@ App::get('/v1/projects/:projectId/usage') // Functions $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)'); + $points = $result->getPoints(); - foreach ($result as $point) { + foreach ($points as $point) { $functions[] = [ 'value' => (!empty($point['value'])) ? $point['value'] : 0, 'date' => \strtotime($point['time']), diff --git a/app/init.php b/app/init.php index 5ec434688..bc5e37d28 100644 --- a/app/init.php +++ b/app/init.php @@ -170,12 +170,7 @@ $register->set('influxdb', function () { // Register DB connection return; } - $client = new InfluxDB2\Client([ - 'url' => "http://{$host}:{$port}", - 'bucket' => 'telegraf/autogen', - 'timeout' => 5, - 'verifySSL' => false - ]); + $client = new InfluxDB\Client($host, $port, '', '', false, false, 5); return $client; }); @@ -195,10 +190,10 @@ $register->set('cache', function () { // Register cache connection $pass = App::getEnv('_APP_REDIS_PASS',''); $auth = []; if(!empty($user)) { - $auth['user'] = $user; + $auth["user"] = $user; } if(!empty($pass)) { - $auth['pass'] = $pass; + $auth["pass"] = $pass; } if(!empty($auth)) { $redis->auth($auth); diff --git a/composer.json b/composer.json index 920d4ccd5..4b68a5f1c 100644 --- a/composer.json +++ b/composer.json @@ -55,11 +55,11 @@ "resque/php-resque": "1.3.6", "matomo/device-detector": "4.2.2", "dragonmantank/cron-expression": "3.1.0", + "influxdb/influxdb-php": "1.15.2", "phpmailer/phpmailer": "6.4.0", "chillerlan/php-qrcode": "4.3.0", "adhocore/jwt": "1.1.2", - "slickdeals/statsd": "3.0.2", - "influxdata/influxdb-client-php": "^1.12" + "slickdeals/statsd": "3.0.2" }, "require-dev": { "appwrite/sdk-generator": "dev-feat-preps-for-0.8", diff --git a/composer.lock b/composer.lock index 3b8283e4d..8e54ef9bb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ea8c94c961eb9a64a93d87114fbc74cc", + "content-hash": "32ceddda707fb8f625f84eec08dc3871", "packages": [ { "name": "adhocore/jwt", @@ -647,52 +647,6 @@ }, "time": "2021-04-26T09:17:50+00:00" }, - { - "name": "influxdata/influxdb-client-php", - "version": "1.12.0", - "source": { - "type": "git", - "url": "https://github.com/influxdata/influxdb-client-php.git", - "reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/influxdata/influxdb-client-php/zipball/e04f802a4d9c52b5b497077673269e8463fdb6ea", - "reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "guzzlehttp/guzzle": "^6.2|^7.0.1", - "php": ">=7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.4|^9.1", - "squizlabs/php_codesniffer": "~2.6" - }, - "type": "library", - "autoload": { - "psr-4": { - "InfluxDB2\\": "src/InfluxDB2" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "InfluxDB (v2+) Client Library for PHP", - "homepage": "https://www.github.com/influxdata/influxdb-client-php", - "keywords": [ - "influxdb" - ], - "support": { - "issues": "https://github.com/influxdata/influxdb-client-php/issues", - "source": "https://github.com/influxdata/influxdb-client-php/tree/1.12.0" - }, - "time": "2021-04-01T06:28:57+00:00" - }, { "name": "influxdb/influxdb-php", "version": "1.15.2",