diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index 5c16ffccca..a4444b1716 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -47,7 +47,8 @@ App::get('/v1/project/usage') METRIC_USERS, METRIC_BUCKETS, METRIC_FILES_STORAGE, - METRIC_DEPLOYMENTS_STORAGE + METRIC_DEPLOYMENTS_STORAGE, + METRIC_BUILDS_STORAGE ], 'period' => [ METRIC_NETWORK_REQUESTS, @@ -181,19 +182,27 @@ App::get('/v1/project/usage') ]; }, $dbForProject->find('buckets')); - $deploymentsStorageBreakdown = array_map(function ($function) use ($dbForProject) { + $functionsStorageBreakdown = 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]), + $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $function->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE); + $deploymentValue = $dbForProject->findOne('stats', [ + Query::equal('metric', [$deploymentMetric]), Query::equal('period', ['inf']) ]); + $buildMetric = str_replace(['{functionInternalId}'], [$function->getInternalId()], METRIC_FUNCTION_ID_BUILDS_STORAGE); + $buildValue = $dbForProject->findOne('stats', [ + Query::equal('metric', [$buildMetric]), + Query::equal('period', ['inf']) + ]); + + $value = ($buildValue['value'] ?? 0) + ($deploymentValue['value'] ?? 0); + return [ 'resourceId' => $id, 'name' => $name, - 'value' => $value['value'] ?? 0, + 'value' => $value, ]; }, $dbForProject->find('functions')); @@ -263,14 +272,14 @@ App::get('/v1/project/usage') 'usersTotal' => $total[METRIC_USERS], 'bucketsTotal' => $total[METRIC_BUCKETS], 'filesStorageTotal' => $total[METRIC_FILES_STORAGE], - 'deploymentsStorageTotal' => $total[METRIC_DEPLOYMENTS_STORAGE], + 'functionsStorageTotal' => $total[METRIC_DEPLOYMENTS_STORAGE] + $total[METRIC_BUILDS_STORAGE], 'executionsBreakdown' => $executionsBreakdown, 'executionsMbSecondsBreakdown' => $executionsMbSecondsBreakdown, 'buildsMbSecondsBreakdown' => $buildsMbSecondsBreakdown, 'bucketsBreakdown' => $bucketsBreakdown, 'executionsMbSecondsBreakdown' => $executionsMbSecondsBreakdown, 'buildsMbSecondsBreakdown' => $buildsMbSecondsBreakdown, - 'deploymentsStorageBreakdown' => $deploymentsStorageBreakdown, + 'functionsStorageBreakdown' => $functionsStorageBreakdown, ]), Response::MODEL_USAGE_PROJECT); }); diff --git a/src/Appwrite/Utopia/Response/Model/UsageProject.php b/src/Appwrite/Utopia/Response/Model/UsageProject.php index c8636add4a..8448951886 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageProject.php +++ b/src/Appwrite/Utopia/Response/Model/UsageProject.php @@ -40,9 +40,9 @@ class UsageProject extends Model 'default' => 0, 'example' => 0, ]) - ->addRule('deploymentsStorageTotal', [ + ->addRule('functionsStorageTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of deployments storage size (in bytes).', + 'description' => 'Total aggregated sum of functions storage size (in bytes).', 'default' => 0, 'example' => 0, ]) @@ -120,9 +120,9 @@ class UsageProject extends Model 'example' => [], 'array' => true ]) - ->addRule('deploymentsStorageBreakdown', [ + ->addRule('functionsStorageBreakdown', [ 'type' => Response::MODEL_METRIC_BREAKDOWN, - 'description' => 'Aggregated breakdown in totals of deployments storage size (in bytes).', + 'description' => 'Aggregated breakdown in totals of functions storage size (in bytes).', 'default' => [], 'example' => [], 'array' => true