From 4befb19c3526e63d844e6360baccbc65716828d6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 8 Nov 2022 13:09:18 +0100 Subject: [PATCH 1/4] feat: add databases and buckets to projects usage --- app/controllers/api/projects.php | 6 ++++-- src/Appwrite/Utopia/Response/Model/UsageProject.php | 11 +++++++++-- .../Services/Projects/ProjectsConsoleClientTest.php | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 9a5f3f001..a5c9177f8 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -295,9 +295,10 @@ App::get('/v1/projects/:projectId/usage') 'project.$all.network.bandwidth', 'project.$all.storage.size', 'users.$all.count.total', - 'collections.$all.count.total', + 'databases.$all.count.total', 'documents.$all.count.total', 'executions.$all.compute.total', + 'buckets.$all.count.total' ]; $stats = []; @@ -346,9 +347,10 @@ App::get('/v1/projects/:projectId/usage') 'network' => $stats[$metrics[1]] ?? [], 'storage' => $stats[$metrics[2]] ?? [], 'users' => $stats[$metrics[3]] ?? [], - 'collections' => $stats[$metrics[4]] ?? [], + 'databases' => $stats[$metrics[4]] ?? [], 'documents' => $stats[$metrics[5]] ?? [], 'executions' => $stats[$metrics[6]] ?? [], + 'buckets' => $stats[$metrics[7]] ?? [], ]); } diff --git a/src/Appwrite/Utopia/Response/Model/UsageProject.php b/src/Appwrite/Utopia/Response/Model/UsageProject.php index 01603fce8..e37bc5928 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageProject.php +++ b/src/Appwrite/Utopia/Response/Model/UsageProject.php @@ -44,9 +44,9 @@ class UsageProject extends Model 'example' => [], 'array' => true ]) - ->addRule('collections', [ + ->addRule('databases', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated stats for number of collections.', + 'description' => 'Aggregated stats for number of databases.', 'default' => [], 'example' => [], 'array' => true @@ -65,6 +65,13 @@ class UsageProject extends Model 'example' => [], 'array' => true ]) + ->addRule('buckets', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated stats for number of buckets.', + 'default' => [], + 'example' => [], + 'array' => true + ]) ; } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 29789a322..6b1d9ccea 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -342,7 +342,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsArray($response['body']['network']); $this->assertIsArray($response['body']['executions']); $this->assertIsArray($response['body']['documents']); - $this->assertIsArray($response['body']['collections']); + $this->assertIsArray($response['body']['databases']); + $this->assertIsArray($response['body']['buckets']); $this->assertIsArray($response['body']['users']); $this->assertIsArray($response['body']['storage']); From 1615121b3e3053b0603f98eb3dac0347bca13e1d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 8 Nov 2022 14:38:43 +0100 Subject: [PATCH 2/4] tests: adapt to new response model --- tests/e2e/General/UsageTest.php | 2 +- tests/e2e/Services/Projects/ProjectsConsoleClientTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 0c42c42ff..1da875c7a 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -102,7 +102,7 @@ class UsageTest extends Scope $res = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/usage?range=30d', $cheaders); $res = $res['body']; - $this->assertEquals(8, count($res)); + $this->assertEquals(9, count($res)); $this->assertEquals(30, count($res['requests'])); $this->assertEquals(30, count($res['users'])); $this->assertEquals($usersCount, $res['users'][array_key_last($res['users'])]['value']); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 6b1d9ccea..d4eea20ae 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -335,7 +335,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(count($response['body']), 8); + $this->assertEquals(count($response['body']), 9); $this->assertNotEmpty($response['body']); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['requests']); From 4041c4964cd28d5875c85a4f53825f3d5b664d84 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 8 Nov 2022 15:16:10 +0100 Subject: [PATCH 3/4] tests: fix remaining tests for usage --- tests/e2e/General/UsageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 1da875c7a..b42696a6c 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -267,7 +267,7 @@ class UsageTest extends Scope $res = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/usage?range=30d', $headers); $res = $res['body']; - $this->assertEquals(8, count($res)); + $this->assertEquals(9, count($res)); $this->assertEquals(30, count($res['requests'])); $this->assertEquals(30, count($res['storage'])); $this->assertEquals($requestsCount, $res['requests'][array_key_last($res['requests'])]['value']); @@ -504,7 +504,7 @@ class UsageTest extends Scope $res = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/usage?range=30d', $headers); $res = $res['body']; - $this->assertEquals(8, count($res)); + $this->assertEquals(9, count($res)); $this->assertEquals(30, count($res['requests'])); $this->assertEquals(30, count($res['storage'])); $this->assertEquals($requestsCount, $res['requests'][array_key_last($res['requests'])]['value']); From e315f5d2ac9d1527cc87af4c9ee7ccb8a75d39a6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 9 Nov 2022 10:29:13 +0100 Subject: [PATCH 4/4] fix: database usage tests --- tests/e2e/General/UsageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index b42696a6c..6f17d940a 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -509,8 +509,8 @@ class UsageTest extends Scope $this->assertEquals(30, count($res['storage'])); $this->assertEquals($requestsCount, $res['requests'][array_key_last($res['requests'])]['value']); $this->validateDates($res['requests']); - $this->assertEquals($collectionsCount, $res['collections'][array_key_last($res['collections'])]['value']); - $this->validateDates($res['collections']); + $this->assertEquals($databasesCount, $res['databases'][array_key_last($res['databases'])]['value']); + $this->validateDates($res['databases']); $this->assertEquals($documentsCount, $res['documents'][array_key_last($res['documents'])]['value']); $this->validateDates($res['documents']);