From 0da3f870f9a8bb12e67977ad1b5f1369f1cf1018 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 30 Jan 2025 04:43:16 +0000 Subject: [PATCH] refactor: rename --- Dockerfile | 2 +- app/controllers/api/health.php | 10 +++++----- app/views/install/compose.phtml | 6 +++--- app/worker.php | 6 +++--- bin/worker-stats-usage-dump | 3 +++ bin/worker-usage-dump | 3 --- docker-compose.yml | 6 +++--- src/Appwrite/Event/Event.php | 4 ++-- .../Event/{UsageDump.php => StatsUsageDump.php} | 6 +++--- src/Appwrite/Platform/Services/Workers.php | 4 ++-- src/Appwrite/Platform/Workers/StatsResources.php | 1 - .../Workers/{UsageDump.php => StatsUsageDump.php} | 4 ++-- src/Appwrite/Platform/Workers/Usage.php | 14 +++++++------- .../e2e/Services/Health/HealthCustomServerTest.php | 6 +++--- 14 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 bin/worker-stats-usage-dump delete mode 100644 bin/worker-usage-dump rename src/Appwrite/Event/{UsageDump.php => StatsUsageDump.php} (81%) rename src/Appwrite/Platform/Workers/{UsageDump.php => StatsUsageDump.php} (99%) diff --git a/Dockerfile b/Dockerfile index 1d50684535..f764e16055 100755 --- a/Dockerfile +++ b/Dockerfile @@ -86,7 +86,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-migrations && \ chmod +x /usr/local/bin/worker-webhooks && \ chmod +x /usr/local/bin/worker-usage && \ - chmod +x /usr/local/bin/worker-usage-dump && \ + chmod +x /usr/local/bin/worker-stats-usage-dump && \ chmod +x /usr/local/bin/stats-resources && \ chmod +x /usr/local/bin/worker-stats-resources diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 1db4713311..ab3551fcd9 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -798,15 +798,15 @@ App::get('/v1/health/queue/usage') $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }); -App::get('/v1/health/queue/usage-dump') +App::get('/v1/health/queue/stats-usage-dump') ->desc('Get usage dump queue') ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk', new Method( auth: [AuthType::KEY], namespace: 'health', - name: 'getQueueUsageDump', - description: '/docs/references/health/get-queue-usage-dump.md', + name: 'getQueueStatsUsageDump', + description: '/docs/references/health/get-queue-stats-usage-dump.md', responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, @@ -821,7 +821,7 @@ App::get('/v1/health/queue/usage-dump') ->action(function (int|string $threshold, Connection $queue, Response $response) { $threshold = \intval($threshold); - $client = new Client(Event::USAGE_DUMP_QUEUE_NAME, $queue); + $client = new Client(Event::STATS_USAGE_DUMP_QUEUE_NAME, $queue); $size = $client->getQueueSize(); if ($size >= $threshold) { @@ -996,7 +996,7 @@ App::get('/v1/health/queue/failed/:name') Event::MAILS_QUEUE_NAME, Event::FUNCTIONS_QUEUE_NAME, Event::USAGE_QUEUE_NAME, - Event::USAGE_DUMP_QUEUE_NAME, + Event::STATS_USAGE_DUMP_QUEUE_NAME, Event::WEBHOOK_QUEUE_NAME, Event::CERTIFICATES_QUEUE_NAME, Event::BUILDS_QUEUE_NAME, diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index ad6d883c4c..ff6da07c78 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -677,11 +677,11 @@ $image = $this->getParam('image', ''); - _APP_LOGGING_CONFIG - _APP_USAGE_AGGREGATION_INTERVAL - appwrite-worker-usage-dump: + appwrite-worker-stats-usage-dump: image: /: - entrypoint: worker-usage-dump + entrypoint: worker-stats-usage-dump <<: *x-logging - container_name: appwrite-worker-usage-dump + container_name: appwrite-worker-stats-usage-dump restart: unless-stopped networks: - appwrite diff --git a/app/worker.php b/app/worker.php index 81b1367873..9658202a41 100644 --- a/app/worker.php +++ b/app/worker.php @@ -14,7 +14,7 @@ use Appwrite\Event\Mail; use Appwrite\Event\Messaging; use Appwrite\Event\Migration; use Appwrite\Event\Usage; -use Appwrite\Event\UsageDump; +use Appwrite\Event\StatsUsageDump; use Appwrite\Platform\Appwrite; use Swoole\Runtime; use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; @@ -261,8 +261,8 @@ Server::setResource('queueForUsage', function (Connection $queue) { return new Usage($queue); }, ['queue']); -Server::setResource('queueForUsageDump', function (Connection $queue) { - return new UsageDump($queue); +Server::setResource('queueForStatsUsageDump', function (Connection $queue) { + return new StatsUsageDump($queue); }, ['queue']); Server::setResource('queue', function (Group $pools) { diff --git a/bin/worker-stats-usage-dump b/bin/worker-stats-usage-dump new file mode 100644 index 0000000000..98e3c2cac7 --- /dev/null +++ b/bin/worker-stats-usage-dump @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/worker.php stats-usage-dump $@ \ No newline at end of file diff --git a/bin/worker-usage-dump b/bin/worker-usage-dump deleted file mode 100644 index 43ca87fcb3..0000000000 --- a/bin/worker-usage-dump +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -php /usr/src/code/app/worker.php usage-dump $@ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4ea4336485..7d04871061 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -816,10 +816,10 @@ services: - _APP_USAGE_AGGREGATION_INTERVAL - _APP_DATABASE_SHARED_TABLES - appwrite-worker-usage-dump: - entrypoint: worker-usage-dump + appwrite-worker-stats-usage-dump: + entrypoint: worker-stats-usage-dump <<: *x-logging - container_name: appwrite-worker-usage-dump + container_name: appwrite-worker-stats-usage-dump image: appwrite-dev networks: - appwrite diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 9c9244c056..a1c5abd1d8 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -30,8 +30,8 @@ class Event public const STATS_RESOURCES_QUEUE_NAME = 'v1-stats-resources'; public const STATS_RESOURCES_CLASS_NAME = 'StatsResources'; - public const USAGE_DUMP_QUEUE_NAME = 'v1-usage-dump'; - public const USAGE_DUMP_CLASS_NAME = 'UsageDumpV1'; + public const STATS_USAGE_DUMP_QUEUE_NAME = 'v1-stats-usage-dump'; + public const STATS_USAGE_DUMP_CLASS_NAME = 'StatsUsageDumpV1'; public const WEBHOOK_QUEUE_NAME = 'v1-webhooks'; public const WEBHOOK_CLASS_NAME = 'WebhooksV1'; diff --git a/src/Appwrite/Event/UsageDump.php b/src/Appwrite/Event/StatsUsageDump.php similarity index 81% rename from src/Appwrite/Event/UsageDump.php rename to src/Appwrite/Event/StatsUsageDump.php index 6f44de4eda..3cd38eca92 100644 --- a/src/Appwrite/Event/UsageDump.php +++ b/src/Appwrite/Event/StatsUsageDump.php @@ -4,7 +4,7 @@ namespace Appwrite\Event; use Utopia\Queue\Connection; -class UsageDump extends Event +class StatsUsageDump extends Event { protected array $stats; @@ -13,8 +13,8 @@ class UsageDump extends Event parent::__construct($connection); $this - ->setQueue(Event::USAGE_DUMP_QUEUE_NAME) - ->setClass(Event::USAGE_DUMP_CLASS_NAME); + ->setQueue(Event::STATS_USAGE_DUMP_QUEUE_NAME) + ->setClass(Event::STATS_USAGE_DUMP_CLASS_NAME); } /** diff --git a/src/Appwrite/Platform/Services/Workers.php b/src/Appwrite/Platform/Services/Workers.php index 150c8cfd23..c1198231f9 100644 --- a/src/Appwrite/Platform/Services/Workers.php +++ b/src/Appwrite/Platform/Services/Workers.php @@ -13,7 +13,7 @@ use Appwrite\Platform\Workers\Messaging; use Appwrite\Platform\Workers\Migrations; use Appwrite\Platform\Workers\StatsResources; use Appwrite\Platform\Workers\Usage; -use Appwrite\Platform\Workers\UsageDump; +use Appwrite\Platform\Workers\StatsUsageDump; use Appwrite\Platform\Workers\Webhooks; use Utopia\Platform\Service; @@ -32,7 +32,7 @@ class Workers extends Service ->addAction(Mails::getName(), new Mails()) ->addAction(Messaging::getName(), new Messaging()) ->addAction(Webhooks::getName(), new Webhooks()) - ->addAction(UsageDump::getName(), new UsageDump()) + ->addAction(StatsUsageDump::getName(), new StatsUsageDump()) ->addAction(Usage::getName(), new Usage()) ->addAction(Migrations::getName(), new Migrations()) ->addAction(StatsResources::getName(), new StatsResources()) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index e4ba59c464..4f6855a6a1 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -47,7 +47,6 @@ class StatsResources extends Action * @param Message $message * @param Document $project * @param callable $getProjectDB - * @param UsageDump $queueForUsageDump * @return void * @throws \Utopia\Database\Exception * @throws Exception diff --git a/src/Appwrite/Platform/Workers/UsageDump.php b/src/Appwrite/Platform/Workers/StatsUsageDump.php similarity index 99% rename from src/Appwrite/Platform/Workers/UsageDump.php rename to src/Appwrite/Platform/Workers/StatsUsageDump.php index 0e7103b8c2..fa31691a18 100644 --- a/src/Appwrite/Platform/Workers/UsageDump.php +++ b/src/Appwrite/Platform/Workers/StatsUsageDump.php @@ -16,7 +16,7 @@ const METRIC_COLLECTION_LEVEL_STORAGE = 4; const METRIC_DATABASE_LEVEL_STORAGE = 3; const METRIC_PROJECT_LEVEL_STORAGE = 2; -class UsageDump extends Action +class StatsUsageDump extends Action { protected array $stats = []; @@ -72,7 +72,7 @@ class UsageDump extends Action public static function getName(): string { - return 'usage-dump'; + return 'stats-usage-dump'; } /** diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 1b5abd4443..176a9fea2f 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -2,7 +2,7 @@ namespace Appwrite\Platform\Workers; -use Appwrite\Event\UsageDump; +use Appwrite\Event\StatsUsageDump; use Exception; use Utopia\CLI\Console; use Utopia\Database\DateTime; @@ -34,9 +34,9 @@ class Usage extends Action ->desc('Usage worker') ->inject('message') ->inject('getProjectDB') - ->inject('queueForUsageDump') - ->callback(function (Message $message, callable $getProjectDB, UsageDump $queueForUsageDump) { - $this->action($message, $getProjectDB, $queueForUsageDump); + ->inject('queueForStatsUsageDump') + ->callback(function (Message $message, callable $getProjectDB, StatsUsageDump $queueForStatsUsageDump) { + $this->action($message, $getProjectDB, $queueForStatsUsageDump); }); $this->lastTriggeredTime = time(); @@ -45,12 +45,12 @@ class Usage extends Action /** * @param Message $message * @param callable $getProjectDB - * @param UsageDump $queueForUsageDump + * @param StatsUsageDump $queueForStatsUsageDump * @return void * @throws \Utopia\Database\Exception * @throws Exception */ - public function action(Message $message, callable $getProjectDB, UsageDump $queueForUsageDump): void + public function action(Message $message, callable $getProjectDB, StatsUsageDump $queueForStatsUsageDump): void { $payload = $message->getPayload() ?? []; if (empty($payload)) { @@ -93,7 +93,7 @@ class Usage extends Action ) { Console::warning('[' . DateTime::now() . '] Aggregated ' . $this->keys . ' keys'); - $queueForUsageDump + $queueForStatsUsageDump ->setStats($this->stats) ->trigger(); diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 9d6a04abe6..b05351dce5 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -536,12 +536,12 @@ class HealthCustomServerTest extends Scope $this->assertEquals(503, $response['headers']['status-code']); } - public function testUsageDumpSuccess() + public function testStatsUsageDumpSuccess() { /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/usage-dump', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-usage-dump', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -553,7 +553,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/usage-dump?threshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-usage-dump?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []);