Merge pull request #4649 from appwrite/feat-new-usage-stats
feat: add databases and buckets to projects usage
This commit is contained in:
commit
5011820f67
|
@ -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]] ?? [],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -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']);
|
||||
|
@ -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,13 +504,13 @@ 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']);
|
||||
$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']);
|
||||
|
||||
|
|
|
@ -335,14 +335,15 @@ 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']);
|
||||
$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']);
|
||||
|
||||
|
|
Loading…
Reference in a new issue