Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement deploymentsStorage metric for projects API #8258

Open
wants to merge 5 commits into
base: 1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/config/specs/open-api3-latest-client.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config/specs/open-api3-latest-console.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config/specs/open-api3-latest-server.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config/specs/swagger2-latest-client.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config/specs/swagger2-latest-console.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config/specs/swagger2-latest-server.json

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions app/controllers/api/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
METRIC_DATABASES,
METRIC_USERS,
METRIC_BUCKETS,
METRIC_FILES_STORAGE
METRIC_FILES_STORAGE,
METRIC_DEPLOYMENTS_STORAGE
],
'period' => [
METRIC_NETWORK_REQUESTS,
Expand Down Expand Up @@ -144,6 +145,22 @@
];
}, $dbForProject->find('buckets'));

$deploymentsStorageBreakdown = array_map(function ($function) use ($dbForProject) {
$id = $function->getId();
$name = $function->getAttribute('name');
$metric = str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $function->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE);
$value = $dbForProject->findOne('stats', [
Query::equal('metric', [$metric]),
Query::equal('period', ['inf'])
]);

return [
'resourceId' => $id,
'name' => $name,
'value' => $value['value'] ?? 0,
];
}, $dbForProject->find('functions'));

// merge network inbound + outbound
$projectBandwidth = [];
foreach ($usage[METRIC_NETWORK_INBOUND] as $item) {
Expand Down Expand Up @@ -176,8 +193,10 @@
'usersTotal' => $total[METRIC_USERS],
'bucketsTotal' => $total[METRIC_BUCKETS],
'filesStorageTotal' => $total[METRIC_FILES_STORAGE],
'deploymentsStorageTotal' => $total[METRIC_DEPLOYMENTS_STORAGE],
'executionsBreakdown' => $executionsBreakdown,
'bucketsBreakdown' => $bucketsBreakdown
'bucketsBreakdown' => $bucketsBreakdown,
'deploymentsStorageBreakdown' => $deploymentsStorageBreakdown,
]), Response::MODEL_USAGE_PROJECT);
});

Expand Down
13 changes: 13 additions & 0 deletions src/Appwrite/Utopia/Response/Model/UsageProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public function __construct()
'default' => 0,
'example' => 0,
])
->addRule('deploymentsStorageTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated sum of deployments storage size (in bytes).',
'default' => 0,
'example' => 0,
])
->addRule('bucketsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of buckets.',
Expand Down Expand Up @@ -88,6 +94,13 @@ public function __construct()
'example' => [],
'array' => true
])
->addRule('deploymentsStorageBreakdown', [
'type' => Response::MODEL_METRIC_BREAKDOWN,
'description' => 'Aggregated breakdown in totals of deployments storage size (in bytes).',
'default' => [],
'example' => [],
'array' => true
])
;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/General/UsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testUsersStats(array $data): array
);

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(12, count($response['body']));
$this->assertEquals(14, count($response['body']));
$this->validateDates($response['body']['network']);
$this->validateDates($response['body']['requests']);
$this->validateDates($response['body']['users']);
Expand Down Expand Up @@ -778,6 +778,8 @@ public function testFunctionsStats(array $data): void
$this->assertEquals('30d', $response['body']['range']);
$this->assertIsArray($response['body']['deployments']);
$this->assertIsArray($response['body']['deploymentsStorage']);
$this->assertIsNumeric($response['body']['deploymentsStorageTotal']);
$this->assertIsArray($response['body']['deploymentsStorageBreakdown']);
$this->assertIsArray($response['body']['builds']);
$this->assertIsArray($response['body']['buildsTime']);
$this->assertIsArray($response['body']['executions']);
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Services/Projects/ProjectsConsoleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public function testGetProjectUsage($data): array
$this->assertIsNumeric($response['body']['bucketsTotal']);
$this->assertIsNumeric($response['body']['usersTotal']);
$this->assertIsNumeric($response['body']['filesStorageTotal']);
$this->assertIsNumeric($response['body']['deploymentStorageTotal']);


/**
Expand Down