From 512015236987f5a3be999d2b25217eb2f00187ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 24 Sep 2023 14:07:37 +0200 Subject: [PATCH] Add all worker health endpoints --- app/controllers/api/health.php | 111 ++++++++++++- ...{get-queue-logs.md => get-queue-audits.md} | 0 docs/references/health/get-queue-builds.md | 1 + docs/references/health/get-queue-databases.md | 1 + docs/references/health/get-queue-deletes.md | 1 + docs/references/health/get-queue-mails.md | 1 + docs/references/health/get-queue-messaging.md | 1 + .../references/health/get-queue-migrations.md | 1 + .../Health/HealthCustomServerTest.php | 157 ++++++++++++++++++ 9 files changed, 270 insertions(+), 4 deletions(-) rename docs/references/health/{get-queue-logs.md => get-queue-audits.md} (100%) create mode 100644 docs/references/health/get-queue-builds.md create mode 100644 docs/references/health/get-queue-databases.md create mode 100644 docs/references/health/get-queue-deletes.md create mode 100644 docs/references/health/get-queue-mails.md create mode 100644 docs/references/health/get-queue-messaging.md create mode 100644 docs/references/health/get-queue-migrations.md diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index afab8ab587..0660b26990 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -353,14 +353,15 @@ App::get('/v1/health/queue/webhooks') $response->dynamic(new Document([ 'size' => Resque::size(Event::WEBHOOK_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); -App::get('/v1/health/queue/logs') - ->desc('Get logs queue') +App::get('/v1/health/queue/audits') + ->alias('/v1/health/queue/logs') + ->desc('Get Audits Queue') ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'health') - ->label('sdk.method', 'getQueueLogs') - ->label('sdk.description', '/docs/references/health/get-queue-logs.md') + ->label('sdk.method', 'getQueueAudits') + ->label('sdk.description', '/docs/references/health/get-queue-audits.md') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) @@ -387,6 +388,108 @@ App::get('/v1/health/queue/certificates') $response->dynamic(new Document([ 'size' => Resque::size(Event::CERTIFICATES_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); +App::get('/v1/health/queue/builds') + ->desc('Get Builds Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueBuilds') + ->label('sdk.description', '/docs/references/health/get-queue-builds.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::BUILDS_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + +App::get('/v1/health/queue/databases') + ->desc('Get Databases Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueDatabases') + ->label('sdk.description', '/docs/references/health/get-queue-databases.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::DATABASE_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + +App::get('/v1/health/queue/deletes') + ->desc('Get Deletes Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueDeletes') + ->label('sdk.description', '/docs/references/health/get-queue-deletes.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::DELETE_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + +App::get('/v1/health/queue/mails') + ->desc('Get Mails Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueMails') + ->label('sdk.description', '/docs/references/health/get-queue-mails.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::MAILS_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + +App::get('/v1/health/queue/messaging') + ->desc('Get Messaging Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueMessaging') + ->label('sdk.description', '/docs/references/health/get-queue-messaging.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::MESSAGING_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + +App::get('/v1/health/queue/migrations') + ->desc('Get Migrations Queue') + ->groups(['api', 'health']) + ->label('scope', 'health.read') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'health') + ->label('sdk.method', 'getQueueMigrations') + ->label('sdk.description', '/docs/references/health/get-queue-migrations.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->inject('response') + ->action(function (Response $response) { + + $response->dynamic(new Document([ 'size' => Resque::size(Event::MIGRATIONS_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); + }, ['response']); + App::get('/v1/health/queue/functions') ->desc('Get functions queue') ->groups(['api', 'health']) diff --git a/docs/references/health/get-queue-logs.md b/docs/references/health/get-queue-audits.md similarity index 100% rename from docs/references/health/get-queue-logs.md rename to docs/references/health/get-queue-audits.md diff --git a/docs/references/health/get-queue-builds.md b/docs/references/health/get-queue-builds.md new file mode 100644 index 0000000000..fcd5fcf478 --- /dev/null +++ b/docs/references/health/get-queue-builds.md @@ -0,0 +1 @@ +Get the number of builds that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/docs/references/health/get-queue-databases.md b/docs/references/health/get-queue-databases.md new file mode 100644 index 0000000000..064e6095ce --- /dev/null +++ b/docs/references/health/get-queue-databases.md @@ -0,0 +1 @@ +Get the number of database changes that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/docs/references/health/get-queue-deletes.md b/docs/references/health/get-queue-deletes.md new file mode 100644 index 0000000000..884b83dd07 --- /dev/null +++ b/docs/references/health/get-queue-deletes.md @@ -0,0 +1 @@ +Get the number of background destructive changes that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/docs/references/health/get-queue-mails.md b/docs/references/health/get-queue-mails.md new file mode 100644 index 0000000000..6270f64f7a --- /dev/null +++ b/docs/references/health/get-queue-mails.md @@ -0,0 +1 @@ +Get the number of mails that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/docs/references/health/get-queue-messaging.md b/docs/references/health/get-queue-messaging.md new file mode 100644 index 0000000000..8bc994923f --- /dev/null +++ b/docs/references/health/get-queue-messaging.md @@ -0,0 +1 @@ +Get the number of messages that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/docs/references/health/get-queue-migrations.md b/docs/references/health/get-queue-migrations.md new file mode 100644 index 0000000000..8645c80379 --- /dev/null +++ b/docs/references/health/get-queue-migrations.md @@ -0,0 +1 @@ +Get the number of migrations that are waiting to be processed in the Appwrite internal queue server. \ No newline at end of file diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 96c9bde5c7..22c869fdef 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -183,6 +183,16 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + + $response = $this->client->call(Client::METHOD_GET, '/health/queue/audits', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + /** * Test for FAILURE */ @@ -211,6 +221,153 @@ class HealthCustomServerTest extends Scope return []; } + public function testFunctionsSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testBuildsSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/builds', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testDatabasesSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/databases', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testDeletesSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testMailsSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/mails', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testMessagingSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testMigrationsSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + + return []; + } + public function testStorageLocalSuccess(): array { /**