From ac152a76b5427c31cc83e86427c548364b68cab5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 31 Mar 2025 06:28:58 +0000 Subject: [PATCH 01/41] Fix: usage stats changes --- app/controllers/api/project.php | 14 +++--- app/controllers/general.php | 6 +-- app/controllers/shared/api.php | 4 +- app/init/constants.php | 44 ++++++------------ .../Functions/Http/Executions/Create.php | 6 +-- .../Modules/Functions/Http/Usage/Get.php | 18 ++++---- .../Modules/Functions/Workers/Builds.php | 45 ++++--------------- src/Appwrite/Platform/Workers/Functions.php | 6 +-- src/Appwrite/Platform/Workers/StatsUsage.php | 16 +++---- 9 files changed, 56 insertions(+), 103 deletions(-) diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index a991565c5d..4c7b21c0f8 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -149,7 +149,7 @@ App::get('/v1/project/usage') $executionsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -165,7 +165,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -181,7 +181,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -230,13 +230,13 @@ App::get('/v1/project/usage') $functionsStorageBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $function->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE); + $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_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); + $buildMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE); $buildValue = $dbForProject->findOne('stats', [ Query::equal('metric', [$buildMetric]), Query::equal('period', ['inf']) @@ -254,7 +254,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -270,7 +270,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) diff --git a/app/controllers/general.php b/app/controllers/general.php index 5ce0a03471..d98c16fedf 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -587,11 +587,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_NETWORK_OUTBOUND, $response->getSize()) ->addMetric(METRIC_EXECUTIONS, 1) - ->addMetric(str_replace('{functionInternalId}', $resource->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project - ->addMetric(str_replace('{functionInternalId}', $resource->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace('{functionInternalId}', $resource->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3f87de8fa5..e0a2a4e5d1 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -175,8 +175,8 @@ $usageDatabaseListener = function (string $event, Document $document, StatsUsage $queueForStatsUsage ->addMetric(METRIC_DEPLOYMENTS, $value) // per project ->addMetric(METRIC_DEPLOYMENTS_STORAGE, $document->getAttribute('size') * $value) // per project - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_FUNCTION_ID_DEPLOYMENTS), $value) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE), $document->getAttribute('size') * $value); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $value) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $document->getAttribute('size') * $value); break; default: break; diff --git a/app/init/constants.php b/app/init/constants.php index e5e7b5900d..3fe972da1c 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -195,36 +195,22 @@ const METRIC_BUILDS_COMPUTE = 'builds.compute'; const METRIC_BUILDS_COMPUTE_SUCCESS = 'builds.compute.success'; const METRIC_BUILDS_COMPUTE_FAILED = 'builds.compute.failed'; const METRIC_BUILDS_MB_SECONDS = 'builds.mbSeconds'; -const METRIC_FUNCTION_ID_BUILDS = '{functionInternalId}.builds'; -const METRIC_FUNCTION_ID_BUILDS_SUCCESS = '{functionInternalId}.builds.success'; -const METRIC_FUNCTION_ID_BUILDS_FAILED = '{functionInternalId}.builds.failed'; -const METRIC_FUNCTION_ID_BUILDS_STORAGE = '{functionInternalId}.builds.storage'; -const METRIC_FUNCTION_ID_BUILDS_COMPUTE = '{functionInternalId}.builds.compute'; -const METRIC_FUNCTION_ID_BUILDS_COMPUTE_SUCCESS = '{functionInternalId}.builds.compute.success'; -const METRIC_FUNCTION_ID_BUILDS_COMPUTE_FAILED = '{functionInternalId}.builds.compute.failed'; -const METRIC_FUNCTION_ID_BUILDS_MB_SECONDS = '{functionInternalId}.builds.mbSeconds'; -const METRIC_SITES_ID_BUILDS = 'sites.{siteInternalId}.builds'; -const METRIC_SITES_ID_BUILDS_SUCCESS = 'sites.{siteInternalId}.builds.success'; -const METRIC_SITES_ID_BUILDS_FAILED = 'sites.{siteInternalId}.builds.failed'; -const METRIC_SITES_ID_BUILDS_STORAGE = 'sites.{siteInternalId}.builds.storage'; -const METRIC_SITES_ID_BUILDS_COMPUTE = 'sites.{siteInternalId}.builds.compute'; -const METRIC_SITES_ID_BUILDS_COMPUTE_SUCCESS = 'sites.{siteInternalId}.builds.compute.success'; -const METRIC_SITES_ID_BUILDS_COMPUTE_FAILED = 'sites.{siteInternalId}.builds.compute.failed'; -const METRIC_SITES_ID_BUILDS_MB_SECONDS = 'sites.{siteInternalId}.builds.mbSeconds'; -const METRIC_FUNCTION_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; -const METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; const METRIC_EXECUTIONS = 'executions'; const METRIC_EXECUTIONS_COMPUTE = 'executions.compute'; const METRIC_EXECUTIONS_MB_SECONDS = 'executions.mbSeconds'; -const METRIC_FUNCTION_ID_EXECUTIONS = '{functionInternalId}.executions'; -const METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE = '{functionInternalId}.executions.compute'; -const METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS = '{functionInternalId}.executions.mbSeconds'; -const METRIC_SITE_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; -const METRIC_SITE_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; -const METRIC_SITE_ID_BUILDS = '{siteInternalId}.builds'; -const METRIC_SITE_ID_BUILDS_STORAGE = '{siteInternalId}.builds.storage'; -const METRIC_SITE_ID_BUILDS_COMPUTE = '{siteInternalId}.builds.compute'; -const METRIC_SITE_ID_BUILDS_MB_SECONDS = '{siteInternalId}.builds.mbSeconds'; +const METRIC_RESOURCE_TYPE_ID_EXECUTIONS = '{resourceType}.{resourceInternalId}.executions'; +const METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE = '{resourceType}.{resourceInternalId}.executions.compute'; +const METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS = '{resourceType}.{resourceInternalId}.executions.mbSeconds'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS = '{resourceType}.{resourceInternalId}.builds.success'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED = '{resourceType}.{resourceInternalId}.builds.failed'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE = '{resourceType}.{resourceInternalId}.builds.compute'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS = '{resourceType}.{resourceInternalId}.builds.compute.success'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED = '{resourceType}.{resourceInternalId}.builds.compute.failed'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS = '{resourceType}.{resourceInternalId}.builds.mbSeconds'; +const METRIC_RESOURCE_TYPE_ID_BUILDS = '{resourceType}.{resourceInternalId}.builds'; +const METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE = '{resourceType}.{resourceInternalId}.builds.storage'; +const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; +const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; const METRIC_NETWORK_REQUESTS = 'network.requests'; const METRIC_NETWORK_INBOUND = 'network.inbound'; const METRIC_NETWORK_OUTBOUND = 'network.outbound'; @@ -239,10 +225,6 @@ const METRIC_TARGETS = 'targets'; const METRIC_PROVIDER_TYPE_TARGETS = '{providerType}.targets'; const METRIC_KEYS = 'keys'; const METRIC_DOMAINS = 'domains'; -const METRIC_RESOURCE_TYPE_ID_BUILDS = '{resourceType}.{resourceInternalId}.builds'; -const METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE = '{resourceType}.{resourceInternalId}.builds.storage'; -const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; -const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; // Resource types diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 7e89196a5b..45d33963a5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -437,11 +437,11 @@ class Create extends Base } finally { $queueForStatsUsage ->addMetric(METRIC_EXECUTIONS, 1) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index cf06282038..9a2387283e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -69,15 +69,15 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $function->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $function->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS), - str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS) + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS) ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 18e52e7e16..9d7ee8614a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1148,49 +1148,20 @@ class Builds extends Action protected function sendUsage(Document $resource, Document $deployment, Document $project, StatsUsage $queue): void { - $key = match($resource->getCollection()) { - 'functions' => 'functionInternalId', - 'sites' => 'siteInternalId', - default => throw new \Exception('Invalid resource type') - }; - - $metrics = match($resource->getCollection()) { - 'functions' => [ - 'builds' => METRIC_FUNCTION_ID_BUILDS, - 'buildsSuccess' => METRIC_FUNCTION_ID_BUILDS_SUCCESS, - 'buildsFailed' => METRIC_FUNCTION_ID_BUILDS_FAILED, - 'buildsComputeSuccess' => METRIC_FUNCTION_ID_BUILDS_COMPUTE_SUCCESS, - 'buildsComputeFailed' => METRIC_FUNCTION_ID_BUILDS_COMPUTE_FAILED, - 'buildsStorage' => METRIC_FUNCTION_ID_BUILDS_STORAGE, - 'buildsCompute' => METRIC_FUNCTION_ID_BUILDS_COMPUTE, - 'buildsMbSeconds' => METRIC_FUNCTION_ID_BUILDS_MB_SECONDS - ], - 'sites' => [ - 'builds' => METRIC_SITES_ID_BUILDS, - 'buildsSuccess' => METRIC_SITES_ID_BUILDS_SUCCESS, - 'buildsFailed' => METRIC_SITES_ID_BUILDS_FAILED, - 'buildsComputeSuccess' => METRIC_SITES_ID_BUILDS_COMPUTE_SUCCESS, - 'buildsComputeFailed' => METRIC_SITES_ID_BUILDS_COMPUTE_FAILED, - 'buildsStorage' => METRIC_SITES_ID_BUILDS_STORAGE, - 'buildsCompute' => METRIC_SITES_ID_BUILDS_COMPUTE, - 'buildsMbSeconds' => METRIC_SITES_ID_BUILDS_MB_SECONDS - ] - }; - switch ($deployment->getAttribute('status')) { case 'ready': $queue ->addMetric(METRIC_BUILDS_SUCCESS, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS_SUCCESS), 1) // per function - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; case 'failed': $queue ->addMetric(METRIC_BUILDS_FAILED, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace($key, $resource->getInternalId(), $metrics['buildsFailed']), 1) // per function - ->addMetric(str_replace($key, $resource->getInternalId(), $metrics['buildsComputeFailed']), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; } @@ -1199,10 +1170,10 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_STORAGE, $deployment->getAttribute('buildSize', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(METRIC_BUILDS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS), 1) // per function - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace($key, $resource->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); } diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 99dbea43b2..0ef468df9b 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -565,11 +565,11 @@ class Functions extends Action $queueForStatsUsage ->setProject($project) ->addMetric(METRIC_EXECUTIONS, 1) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000))// per project - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->trigger() ; } diff --git a/src/Appwrite/Platform/Workers/StatsUsage.php b/src/Appwrite/Platform/Workers/StatsUsage.php index 1d270fcd04..23cd631df7 100644 --- a/src/Appwrite/Platform/Workers/StatsUsage.php +++ b/src/Appwrite/Platform/Workers/StatsUsage.php @@ -189,14 +189,14 @@ class StatsUsage extends Action } break; - case $document->getCollection() === 'functions': - $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS))); - $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE))); - $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS))); - $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE))); - $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE))); - $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS))); - $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE))); + case $document->getCollection() === 'functions' || $document->getCollection() === 'sites': + $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); + $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); + $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS))); + $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); + $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); + $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); + $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); if (!empty($deployments['value'])) { $metrics[] = [ From 11bd9e63f05ce7f18e24e419f6ea00b863077303 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 31 Mar 2025 06:45:16 +0000 Subject: [PATCH 02/41] update constants --- .../Platform/Modules/Sites/Http/Usage/Get.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index 3269062d6d..8da2e9d86d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -73,12 +73,12 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], ['sites', $site->getInternalId()], METRIC_SITE_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], ['sites', $site->getInternalId()], METRIC_SITE_ID_DEPLOYMENTS_STORAGE), - str_replace('{siteInternalId}', $site->getInternalId(), METRIC_SITE_ID_BUILDS), - str_replace('{siteInternalId}', $site->getInternalId(), METRIC_SITE_ID_BUILDS_STORAGE), - str_replace('{siteInternalId}', $site->getInternalId(), METRIC_SITE_ID_BUILDS_COMPUTE), - str_replace('{siteInternalId}', $site->getInternalId(), METRIC_SITE_ID_BUILDS_MB_SECONDS) + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS) ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { From ad9d953e1093ffae34286be18400c49a3aa6858d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 31 Mar 2025 07:51:37 +0000 Subject: [PATCH 03/41] fix missing resource type --- .../Modules/Functions/Workers/Builds.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 9d7ee8614a..357b290258 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1153,15 +1153,15 @@ class Builds extends Action $queue ->addMetric(METRIC_BUILDS_SUCCESS, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; case 'failed': $queue ->addMetric(METRIC_BUILDS_FAILED, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; } @@ -1170,10 +1170,10 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_STORAGE, $deployment->getAttribute('buildSize', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(METRIC_BUILDS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$resource->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); } From e629037da29a5d1d1ab76529bbf150843fcc4fa4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 31 Mar 2025 07:56:26 +0000 Subject: [PATCH 04/41] use proper resource type --- app/controllers/general.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index d98c16fedf..1e3063fe17 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -587,11 +587,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_NETWORK_OUTBOUND, $response->getSize()) ->addMetric(METRIC_EXECUTIONS, 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); From 1af638deef449960e568321ded41b2f0e7170540 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 02:21:52 +0000 Subject: [PATCH 05/41] new resource type metrics --- app/controllers/general.php | 3 +++ app/controllers/shared/api.php | 2 ++ app/init/constants.php | 14 ++++++++++++++ .../Modules/Functions/Http/Executions/Create.php | 3 +++ .../Platform/Modules/Functions/Workers/Builds.php | 8 ++++++++ src/Appwrite/Platform/Workers/Functions.php | 3 +++ 6 files changed, 33 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 1e3063fe17..a351800bfd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -587,10 +587,13 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_NETWORK_OUTBOUND, $response->getSize()) ->addMetric(METRIC_EXECUTIONS, 1) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index e0a2a4e5d1..8c4a15a50d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -175,6 +175,8 @@ $usageDatabaseListener = function (string $event, Document $document, StatsUsage $queueForStatsUsage ->addMetric(METRIC_DEPLOYMENTS, $value) // per project ->addMetric(METRIC_DEPLOYMENTS_STORAGE, $document->getAttribute('size') * $value) // per project + ->addMetric(str_replace(['{resourceType}'], [$document->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_DEPLOYMENTS), $value) // per function + ->addMetric(str_replace(['{resourceType}'], [$document->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), $document->getAttribute('size') * $value) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $value) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getAttribute('resourceInternalId')], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $document->getAttribute('size') * $value); break; diff --git a/app/init/constants.php b/app/init/constants.php index 3fe972da1c..8c016b953a 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -211,6 +211,20 @@ const METRIC_RESOURCE_TYPE_ID_BUILDS = '{resourceType}.{resourceInternalId}.bui const METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE = '{resourceType}.{resourceInternalId}.builds.storage'; const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; + +const METRIC_RESOURCE_TYPE_EXECUTIONS = '{resourceType}.executions'; +const METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE = '{resourceType}.executions.compute'; +const METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS = '{resourceType}.executions.mbSeconds'; +const METRIC_RESOURCE_TYPE_BUILDS_SUCCESS = '{resourceType}.builds.success'; +const METRIC_RESOURCE_TYPE_BUILDS_FAILED = '{resourceType}.builds.failed'; +const METRIC_RESOURCE_TYPE_BUILDS_COMPUTE = '{resourceType}.builds.compute'; +const METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_SUCCESS = '{resourceType}.builds.compute.success'; +const METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_FAILED = '{resourceType}.builds.compute.failed'; +const METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS = '{resourceType}.builds.mbSeconds'; +const METRIC_RESOURCE_TYPE_BUILDS = '{resourceType}.builds'; +const METRIC_RESOURCE_TYPE_BUILDS_STORAGE = '{resourceType}.builds.storage'; +const METRIC_RESOURCE_TYPE_DEPLOYMENTS = '{resourceType}.deployments'; +const METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE = '{resourceType}.deployments.storage'; const METRIC_NETWORK_REQUESTS = 'network.requests'; const METRIC_NETWORK_INBOUND = 'network.inbound'; const METRIC_NETWORK_OUTBOUND = 'network.outbound'; diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 45d33963a5..b44cf804e3 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -437,10 +437,13 @@ class Create extends Base } finally { $queueForStatsUsage ->addMetric(METRIC_EXECUTIONS, 1) + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 357b290258..82b250a7c3 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1153,6 +1153,8 @@ class Builds extends Action $queue ->addMetric(METRIC_BUILDS_SUCCESS, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_SUCCESS), 1) // per function + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; @@ -1160,6 +1162,8 @@ class Builds extends Action $queue ->addMetric(METRIC_BUILDS_FAILED, 1) // per project ->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_FAILED), 1) // per function + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; @@ -1170,6 +1174,10 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_STORAGE, $deployment->getAttribute('buildSize', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(METRIC_BUILDS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS), 1) // per function + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 0ef468df9b..3f362ad85e 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -565,10 +565,13 @@ class Functions extends Action $queueForStatsUsage ->setProject($project) ->addMetric(METRIC_EXECUTIONS, 1) + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000))// per project + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->trigger() ; From 7ecba8e5bbe6f01ba00973a5ecee741055ad272e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 02:41:27 +0000 Subject: [PATCH 06/41] add disabled metrics --- .../Platform/Modules/Functions/Workers/Builds.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 82b250a7c3..0b4a41ba99 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -837,6 +837,14 @@ class Builds extends Action $jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 0); $apiKey = $jwtObj->encode([ 'hostnameOverride' => true, + 'disabledMetrics' => [ + METRIC_EXECUTIONS, + METRIC_EXECUTIONS_COMPUTE, + METRIC_EXECUTIONS_MB_SECONDS, + METRIC_NETWORK_REQUESTS, + METRIC_NETWORK_INBOUND, + METRIC_NETWORK_OUTBOUND, + ], 'bannerDisabled' => true, 'projectCheckDisabled' => true, 'previewAuthDisabled' => true, From 3a3e9cc2816e549c40045f409873939c9f263977 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 03:59:40 +0000 Subject: [PATCH 07/41] Fix get usage - sites and functions --- .../Modules/Functions/Http/Usage/XList.php | 18 +++++++++--------- .../Modules/Sites/Http/Usage/XList.php | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php index ca94b59a96..0e652e23b2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php @@ -61,15 +61,15 @@ class XList extends Base $days = $periods[$range]; $metrics = [ METRIC_FUNCTIONS, - METRIC_DEPLOYMENTS, - METRIC_DEPLOYMENTS_STORAGE, - METRIC_BUILDS, - METRIC_BUILDS_STORAGE, - METRIC_BUILDS_COMPUTE, - METRIC_EXECUTIONS, - METRIC_EXECUTIONS_COMPUTE, - METRIC_BUILDS_MB_SECONDS, - METRIC_EXECUTIONS_MB_SECONDS, + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_DEPLOYMENTS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_STORAGE), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_EXECUTIONS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php index ee522114bf..6faf16e82f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php @@ -61,12 +61,12 @@ class XList extends Base $days = $periods[$range]; $metrics = [ METRIC_SITES, - METRIC_DEPLOYMENTS, - METRIC_DEPLOYMENTS_STORAGE, - METRIC_BUILDS, - METRIC_BUILDS_STORAGE, - METRIC_BUILDS_COMPUTE, - METRIC_BUILDS_MB_SECONDS, + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_DEPLOYMENTS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_STORAGE), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { From 3fd42d3fc6f4298bbb79fdd7db1e5050416c29fa Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 05:02:54 +0000 Subject: [PATCH 08/41] sites metrics in stats resources --- .../Platform/Workers/StatsResources.php | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index dae2967264..618cd8d39a 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -303,7 +303,7 @@ class StatsResources extends Action return [$databaseDocuments, $databaseStorage]; } - protected function countForFunctions(Database $dbForProject, Database $dbForLogs, string $region) + protected function countForSitesAndFunctions(Database $dbForProject, string $region): void { $deploymentsStorage = $dbForProject->sum('deployments', 'size'); $buildsStorage = $dbForProject->sum('deployments', 'buildSize'); @@ -314,7 +314,29 @@ class StatsResources extends Action $this->createStatsDocuments($region, METRIC_DEPLOYMENTS, $deployments); $this->createStatsDocuments($region, METRIC_BUILDS, $deployments); - $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $dbForLogs, $region) { + $this->countForFunctions($dbForProject, $region); + $this->countForSites($dbForProject, $region); + } + + protected function countForFunctions(Database $dbForProject, string $region) + { + + $deploymentsStorage = $dbForProject->sum('deployments', 'size', [ + Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]) + ]); + $buildsStorage = $dbForProject->sum('deployments', 'buildSize', [ + Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]) + ]); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), $deploymentsStorage); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_STORAGE), $buildsStorage); + + $deployments = $dbForProject->count('deployments', [ + Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]) + ]); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_DEPLOYMENTS), $deployments); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS), $deployments); + + $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region) { $functionDeploymentsStorage = $dbForProject->sum('deployments', 'size', [ Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), @@ -346,6 +368,56 @@ class StatsResources extends Action }); } + protected function countForSites(Database $dbForProject, string $region) + { + + $deploymentsStorage = $dbForProject->sum('deployments', 'size', [ + Query::equal('resourceType', [RESOURCE_TYPE_SITES]) + ]); + $buildsStorage = $dbForProject->sum('deployments', 'buildSize', [ + Query::equal('resourceType', [RESOURCE_TYPE_SITES]) + ]); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), $deploymentsStorage); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_STORAGE), $buildsStorage); + + $deployments = $dbForProject->count('deployments', [ + Query::equal('resourceType', [RESOURCE_TYPE_SITES]) + ]); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_DEPLOYMENTS), $deployments); + $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS), $deployments); + + $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region) { + $siteDeploymentsStorage = $dbForProject->sum('deployments', 'size', [ + Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceType', [RESOURCE_TYPE_SITES]), + ]); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $siteDeploymentsStorage); + + $siteDeployments = $dbForProject->count('deployments', [ + Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceType', [RESOURCE_TYPE_SITES]), + ]); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $siteDeployments); + + /** + * As deployments and builds have 1-1 relationship, + * the count for one should match the other + */ + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); + + $siteBuildsStorage = 0; + + $this->foreachDocument($dbForProject, 'deployments', [ + Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceType', [RESOURCE_TYPE_SITES]), + ], function (Document $deployment) use (&$siteBuildsStorage): void { + $siteBuildsStorage += $deployment->getAttribute('buildSize', 0); + }); + + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); + }); + } + protected function createStatsDocuments(string $region, string $metric, int $value) { foreach ($this->periods as $period => $format) { From 840eb1776ee7c2cdbbf2c05e03c3ae07440e0320 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 05:07:44 +0000 Subject: [PATCH 09/41] fix typo --- src/Appwrite/Platform/Workers/StatsResources.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 618cd8d39a..e462d4c404 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -199,7 +199,7 @@ class StatsResources extends Action } try { - $this->countForFunctions($dbForProject, $dbForLogs, $region); + $this->countForSitesAndFunctions($dbForProject, $region); } catch (Throwable $th) { call_user_func_array($this->logError, [$th, "StatsResources", "count_for_functions_{$project->getId()}"]); } From 04010ca205d54f25fee1b359d2059496ab4ae4b4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 05:08:58 +0000 Subject: [PATCH 10/41] fix missing param --- app/worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/worker.php b/app/worker.php index 9b13ff07b0..8a6188f4d5 100644 --- a/app/worker.php +++ b/app/worker.php @@ -372,7 +372,7 @@ Server::setResource('certificates', function () { }); Server::setResource('logError', function (Registry $register, Document $project) { - return function (Throwable $error, string $namespace, string $action, ?array $extras) use ($register, $project) { + return function (Throwable $error, string $namespace, string $action, ?array $extras = null) use ($register, $project) { $logger = $register->get('logger'); if ($logger) { From a36adbd68b38a0df5a2e3b719d63933118b98351 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 07:31:53 +0000 Subject: [PATCH 11/41] Fix: skipped metrics --- app/controllers/general.php | 6 ++++++ src/Appwrite/Platform/Workers/StatsResources.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index a351800bfd..8171ac5163 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -582,6 +582,12 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $fileSize = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size']; } + if (!empty($apiKey) && !empty($apiKey->getDisabledMetrics())) { + foreach ($apiKey->getDisabledMetrics() as $key) { + $queueForStatsUsage->disableMetric($key); + } + } + $queueForStatsUsage ->addMetric(METRIC_NETWORK_REQUESTS, 1) ->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index e462d4c404..e68e3555a7 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -305,7 +305,7 @@ class StatsResources extends Action protected function countForSitesAndFunctions(Database $dbForProject, string $region): void { - $deploymentsStorage = $dbForProject->sum('deployments', 'size'); + $deploymentsStorage = $dbForProject->sum('deployments', 'sourceSize'); $buildsStorage = $dbForProject->sum('deployments', 'buildSize'); $this->createStatsDocuments($region, METRIC_DEPLOYMENTS_STORAGE, $deploymentsStorage); $this->createStatsDocuments($region, METRIC_BUILDS_STORAGE, $buildsStorage); @@ -321,7 +321,7 @@ class StatsResources extends Action protected function countForFunctions(Database $dbForProject, string $region) { - $deploymentsStorage = $dbForProject->sum('deployments', 'size', [ + $deploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]) ]); $buildsStorage = $dbForProject->sum('deployments', 'buildSize', [ From feb5d5cbf127a741f8938e32751623532f1b9397 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 1 Apr 2025 08:07:47 +0000 Subject: [PATCH 12/41] fix counts --- src/Appwrite/Platform/Workers/StatsResources.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index e68e3555a7..8b7c6df1ca 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -337,7 +337,7 @@ class StatsResources extends Action $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS), $deployments); $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region) { - $functionDeploymentsStorage = $dbForProject->sum('deployments', 'size', [ + $functionDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ]); @@ -371,7 +371,7 @@ class StatsResources extends Action protected function countForSites(Database $dbForProject, string $region) { - $deploymentsStorage = $dbForProject->sum('deployments', 'size', [ + $deploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceType', [RESOURCE_TYPE_SITES]) ]); $buildsStorage = $dbForProject->sum('deployments', 'buildSize', [ @@ -387,7 +387,7 @@ class StatsResources extends Action $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS), $deployments); $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region) { - $siteDeploymentsStorage = $dbForProject->sum('deployments', 'size', [ + $siteDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); @@ -405,14 +405,10 @@ class StatsResources extends Action */ $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); - $siteBuildsStorage = 0; - - $this->foreachDocument($dbForProject, 'deployments', [ + $siteBuildsStorage = $dbForProject->sum('deployments', 'buildSize', [ Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), - ], function (Document $deployment) use (&$siteBuildsStorage): void { - $siteBuildsStorage += $deployment->getAttribute('buildSize', 0); - }); + ]); $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); }); From 0d7187a5cc758c010a99c83eb2211e8f543a31e7 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 2 Apr 2025 04:48:22 +0000 Subject: [PATCH 13/41] Skip metrics when sites executed during build --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 0b4a41ba99..706ab33dbc 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -844,6 +844,12 @@ class Builds extends Action METRIC_NETWORK_REQUESTS, METRIC_NETWORK_INBOUND, METRIC_NETWORK_OUTBOUND, + str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS), + str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), + str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), ], 'bannerDisabled' => true, 'projectCheckDisabled' => true, From d1e083338e4bdac395e6685bb6f0850bf7daf009 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 2 Apr 2025 05:05:24 +0000 Subject: [PATCH 14/41] fix disable metrics for static sites --- app/controllers/general.php | 44 ++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 8171ac5163..b76649f5e1 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -588,19 +588,47 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } } + $metricTypeExecutions = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS); + $metricTypeIdExecutions = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); + $metricTypeExecutionsCompute = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE); + $metricTypeIdExecutionsCompute = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE); + $metricTypeExecutionsMbSeconds = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS); + $metricTypeIdExecutionsMBSeconds = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + if ($deployment->getAttribute('resourceType') === 'sites') { + $queueForStatsUsage + ->disableMetric(METRIC_NETWORK_REQUESTS) + ->disableMetric(METRIC_NETWORK_INBOUND) + ->disableMetric(METRIC_NETWORK_OUTBOUND); + if ($resource->getAttribute('adapter') !== 'ssr') { + $queueForStatsUsage + ->disableMetric(METRIC_EXECUTIONS) + ->disableMetric(METRIC_EXECUTIONS_COMPUTE) + ->disableMetric(METRIC_EXECUTIONS_MB_SECONDS) + ->disableMetric($metricTypeExecutions) + ->disableMetric($metricTypeIdExecutions) + ->disableMetric($metricTypeExecutionsCompute) + ->disableMetric($metricTypeIdExecutionsCompute) + ->disableMetric($metricTypeExecutionsMbSeconds) + ->disableMetric($metricTypeIdExecutionsMBSeconds); + } + } + + + $compute = (int)($execution->getAttribute('duration') * 1000); + $mbSeconds = (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT)); $queueForStatsUsage ->addMetric(METRIC_NETWORK_REQUESTS, 1) ->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_NETWORK_OUTBOUND, $response->getSize()) ->addMetric(METRIC_EXECUTIONS, 1) - ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) - ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project - ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function - ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric($metricTypeExecutions, 1) + ->addMetric($metricTypeIdExecutions, 1) + ->addMetric(METRIC_EXECUTIONS_COMPUTE, $compute) // per project + ->addMetric($metricTypeExecutionsCompute, $compute) // per function + ->addMetric($metricTypeIdExecutionsCompute, $compute) // per function + ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, $mbSeconds) + ->addMetric($metricTypeExecutionsMbSeconds, $mbSeconds) + ->addMetric($metricTypeIdExecutionsMBSeconds, $mbSeconds) ->setProject($project) ->trigger(); From 0d9743c8cba045e916021e7f988450c402ab19e2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 2 Apr 2025 05:10:12 +0000 Subject: [PATCH 15/41] separate sites network metrics --- app/controllers/general.php | 6 ++++++ app/init/constants.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index b76649f5e1..8beb0a6e45 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -611,6 +611,12 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->disableMetric($metricTypeExecutionsMbSeconds) ->disableMetric($metricTypeIdExecutionsMBSeconds); } + + $queueForStatsUsage + ->addMetric(METRIC_SITES_REQUESTS, 1) + ->addMetric(METRIC_SITES_INBOUND, $request->getSize() + $fileSize) + ->addMetric(METRIC_SITES_OUTBOUND, $response->getSize()) + ; } diff --git a/app/init/constants.php b/app/init/constants.php index 8c016b953a..0e148ea2fa 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -211,7 +211,6 @@ const METRIC_RESOURCE_TYPE_ID_BUILDS = '{resourceType}.{resourceInternalId}.bui const METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE = '{resourceType}.{resourceInternalId}.builds.storage'; const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS = '{resourceType}.{resourceInternalId}.deployments'; const METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE = '{resourceType}.{resourceInternalId}.deployments.storage'; - const METRIC_RESOURCE_TYPE_EXECUTIONS = '{resourceType}.executions'; const METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE = '{resourceType}.executions.compute'; const METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS = '{resourceType}.executions.mbSeconds'; @@ -239,6 +238,9 @@ const METRIC_TARGETS = 'targets'; const METRIC_PROVIDER_TYPE_TARGETS = '{providerType}.targets'; const METRIC_KEYS = 'keys'; const METRIC_DOMAINS = 'domains'; +const METRIC_SITES_REQUESTS = 'sites.requests'; +const METRIC_SITES_INBOUND = 'sites.inbound'; +const METRIC_SITES_OUTBOUND = 'sites.outbound'; // Resource types From 13510ffcb5c0b5186d39c5e8d9cced922c47c928 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 2 Apr 2025 05:15:33 +0000 Subject: [PATCH 16/41] new sites metrics --- app/controllers/general.php | 3 +++ app/init/constants.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 8beb0a6e45..bcfb0d052b 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -616,6 +616,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_SITES_REQUESTS, 1) ->addMetric(METRIC_SITES_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_SITES_OUTBOUND, $response->getSize()) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_REQUESTS), 1) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_INBOUND), $request->getSize() + $fileSize) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_OUTBOUND), $response->getSize()) ; } diff --git a/app/init/constants.php b/app/init/constants.php index 0e148ea2fa..4d57c63ef5 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -241,6 +241,9 @@ const METRIC_DOMAINS = 'domains'; const METRIC_SITES_REQUESTS = 'sites.requests'; const METRIC_SITES_INBOUND = 'sites.inbound'; const METRIC_SITES_OUTBOUND = 'sites.outbound'; +const METRIC_SITES_ID_REQUESTS = 'sites.{siteInternalId}.requests'; +const METRIC_SITES_ID_INBOUND = 'sites.{siteInternalId}.inbound'; +const METRIC_SITES_ID_OUTBOUND = 'sites.{siteInternalId}.outbound'; // Resource types From 5d2b0c38d908ce0e1db3cf0f479f0dd0c35eadf8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 3 Apr 2025 04:16:27 +0000 Subject: [PATCH 17/41] Fix reduce for functions and sites --- src/Appwrite/Platform/Workers/StatsUsage.php | 42 ++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Workers/StatsUsage.php b/src/Appwrite/Platform/Workers/StatsUsage.php index 23cd631df7..b4f54db285 100644 --- a/src/Appwrite/Platform/Workers/StatsUsage.php +++ b/src/Appwrite/Platform/Workers/StatsUsage.php @@ -190,19 +190,23 @@ class StatsUsage extends Action break; case $document->getCollection() === 'functions' || $document->getCollection() === 'sites': - $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); - $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); - $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS))); - $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); - $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); - $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); - $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getAttribute('resourceType'), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); + $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); + $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); + $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS))); + $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); + $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); + $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); + $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); if (!empty($deployments['value'])) { $metrics[] = [ 'key' => METRIC_DEPLOYMENTS, 'value' => ($deployments['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_DEPLOYMENTS), + 'value' => ($deployments['value'] * -1), + ]; } if (!empty($deploymentsStorage['value'])) { @@ -210,6 +214,10 @@ class StatsUsage extends Action 'key' => METRIC_DEPLOYMENTS_STORAGE, 'value' => ($deploymentsStorage['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_DEPLOYMENTS_STORAGE), + 'value' => ($deploymentsStorage['value'] * -1), + ]; } if (!empty($builds['value'])) { @@ -217,6 +225,10 @@ class StatsUsage extends Action 'key' => METRIC_BUILDS, 'value' => ($builds['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_BUILDS), + 'value' => ($builds['value'] * -1), + ]; } if (!empty($buildsStorage['value'])) { @@ -224,6 +236,10 @@ class StatsUsage extends Action 'key' => METRIC_BUILDS_STORAGE, 'value' => ($buildsStorage['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_BUILDS_STORAGE), + 'value' => ($buildsStorage['value'] * -1), + ]; } if (!empty($buildsCompute['value'])) { @@ -231,6 +247,10 @@ class StatsUsage extends Action 'key' => METRIC_BUILDS_COMPUTE, 'value' => ($buildsCompute['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), + 'value' => ($buildsCompute['value'] * -1), + ]; } if (!empty($executions['value'])) { @@ -238,6 +258,10 @@ class StatsUsage extends Action 'key' => METRIC_EXECUTIONS, 'value' => ($executions['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_EXECUTIONS), + 'value' => ($executions['value'] * -1), + ]; } if (!empty($executionsCompute['value'])) { @@ -245,6 +269,10 @@ class StatsUsage extends Action 'key' => METRIC_EXECUTIONS_COMPUTE, 'value' => ($executionsCompute['value'] * -1), ]; + $metrics[] = [ + 'key' => str_replace("{resourceType}", $document->getCollection(), METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), + 'value' => ($executionsCompute['value'] * -1), + ]; } break; default: From 793565822226531ed4cefd3e2f537e32e7c60845 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 3 Apr 2025 06:11:44 +0000 Subject: [PATCH 18/41] dev interval to 30s --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index a292a8197a..5615a8d435 100644 --- a/.env +++ b/.env @@ -89,7 +89,7 @@ _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 _APP_MAINTENANCE_RETENTION_AUDIT=1209600 _APP_USAGE_AGGREGATION_INTERVAL=30 -_APP_STATS_RESOURCES_INTERVAL=3600 +_APP_STATS_RESOURCES_INTERVAL=30 _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 _APP_MAINTENANCE_RETENTION_SCHEDULES=86400 _APP_USAGE_STATS=enabled From b6550c88ef26f6eb73547cfcf1d99768d1249f63 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 03:52:17 +0000 Subject: [PATCH 19/41] new metrics in functions usage response --- src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index 9a2387283e..f7ea55a6dc 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -77,7 +77,9 @@ class Get extends Base str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS) + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -129,8 +131,11 @@ class Get extends Base 'deploymentsTotal' => $usage[$metrics[0]]['total'], 'deploymentsStorageTotal' => $usage[$metrics[1]]['total'], 'buildsTotal' => $usage[$metrics[2]]['total'], + 'buildsSuccess' => $usage[$metrics[9]]['total'], + 'buildsFailed' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $usage[$metrics[4]]['total'], + 'buildsTimeAverage' => $usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total'], 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], 'deployments' => $usage[$metrics[0]]['data'], From 8e18af5db1df4190eecf4ec921485a8888ab0879 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 04:45:20 +0000 Subject: [PATCH 20/41] update get usage and response model --- .../Modules/Functions/Http/Usage/Get.php | 2 +- .../Platform/Modules/Sites/Http/Usage/Get.php | 19 +++- .../Utopia/Response/Model/UsageFunction.php | 18 ++++ .../Utopia/Response/Model/UsageSite.php | 90 +------------------ .../Utopia/Response/Model/UsageSites.php | 89 +----------------- 5 files changed, 40 insertions(+), 178 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index f7ea55a6dc..8c6a2bc741 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -135,7 +135,7 @@ class Get extends Base 'buildsFailed' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $usage[$metrics[4]]['total'], - 'buildsTimeAverage' => $usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total'], + 'buildsTimeAverage' => (int) ($usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total']), 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], 'deployments' => $usage[$metrics[0]]['data'], diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index 8da2e9d86d..9845170251 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -78,7 +78,12 @@ class Get extends Base str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS) + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -130,16 +135,24 @@ class Get extends Base 'deploymentsTotal' => $usage[$metrics[0]]['total'], 'deploymentsStorageTotal' => $usage[$metrics[1]]['total'], 'buildsTotal' => $usage[$metrics[2]]['total'], + 'buildsSuccess' => $usage[$metrics[9]]['total'], + 'buildsFailed' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $usage[$metrics[4]]['total'], + 'buildsTimeAverage' => (int) ($usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total']), + 'executionsTotal' => $usage[$metrics[5]]['total'], + 'executionsTimeTotal' => $usage[$metrics[6]]['total'], 'deployments' => $usage[$metrics[0]]['data'], 'deploymentsStorage' => $usage[$metrics[1]]['data'], 'builds' => $usage[$metrics[2]]['data'], 'buildsStorage' => $usage[$metrics[3]]['data'], 'buildsTime' => $usage[$metrics[4]]['data'], + 'executions' => $usage[$metrics[5]]['data'], + 'executionsTime' => $usage[$metrics[6]]['data'], 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], - 'buildsMbSeconds' => $usage[$metrics[7]]['data'] - // TODO: Add more metrics for requests, bandwidth, etc. + 'buildsMbSeconds' => $usage[$metrics[7]]['data'], + 'executionsMbSeconds' => $usage[$metrics[8]]['data'], + 'executionsMbSecondsTotal' => $usage[$metrics[8]]['total'] ]), Response::MODEL_USAGE_SITE); } } diff --git a/src/Appwrite/Utopia/Response/Model/UsageFunction.php b/src/Appwrite/Utopia/Response/Model/UsageFunction.php index ac21c5ae0d..5066b74eec 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageFunction.php +++ b/src/Appwrite/Utopia/Response/Model/UsageFunction.php @@ -34,6 +34,18 @@ class UsageFunction extends Model 'default' => 0, 'example' => 0, ]) + ->addRule('buildsSuccess', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of successful function builds.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('buildsFailed', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of failed function builds.', + 'default' => 0, + 'example' => 0, + ]) ->addRule('buildsStorageTotal', [ 'type' => self::TYPE_INTEGER, 'description' => 'total aggregated sum of function builds storage.', @@ -46,6 +58,12 @@ class UsageFunction extends Model 'default' => 0, 'example' => 0, ]) + ->addRule('buildsTimeAverage', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Average builds compute time.', + 'default' => 0, + 'example' => 0, + ]) ->addRule('buildsMbSecondsTotal', [ 'type' => self::TYPE_INTEGER, 'description' => 'Total aggregated sum of function builds mbSeconds.', diff --git a/src/Appwrite/Utopia/Response/Model/UsageSite.php b/src/Appwrite/Utopia/Response/Model/UsageSite.php index 266cc4cade..b4cd45950c 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSite.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSite.php @@ -3,98 +3,12 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -use Appwrite\Utopia\Response\Model; -class UsageSite extends Model +class UsageSite extends UsageFunction { public function __construct() { - $this - ->addRule('range', [ - 'type' => self::TYPE_STRING, - 'description' => 'The time range of the usage stats.', - 'default' => '', - 'example' => '30d', - ]) - ->addRule('deploymentsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of site deployments.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('deploymentsStorageTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of site deployments storage.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of site builds.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsStorageTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'total aggregated sum of site builds storage.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsTimeTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of site builds compute time.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsMbSecondsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of site builds mbSeconds.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('deployments', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of site deployments per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('deploymentsStorage', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of site deployments storage per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('builds', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of site builds per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsStorage', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated sum of site builds storage per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsTime', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated sum of site builds compute time per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsMbSeconds', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of site builds mbSeconds per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ; + parent::__construct(); } /** diff --git a/src/Appwrite/Utopia/Response/Model/UsageSites.php b/src/Appwrite/Utopia/Response/Model/UsageSites.php index 8425b8cb74..78c8f22d62 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSites.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSites.php @@ -3,61 +3,20 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -use Appwrite\Utopia\Response\Model; -class UsageSites extends Model +class UsageSites extends UsageFunctions { public function __construct() { $this - ->addRule('range', [ - 'type' => self::TYPE_STRING, - 'description' => 'Time range of the usage stats.', - 'default' => '', - 'example' => '30d', - ]) + ->removeRule('functionsTotal') + ->removeRule('functions') ->addRule('sitesTotal', [ 'type' => self::TYPE_INTEGER, 'description' => 'Total aggregated number of sites.', 'default' => 0, 'example' => 0, ]) - ->addRule('deploymentsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites deployments.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('deploymentsStorageTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of sites deployment storage.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites build.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsStorageTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'total aggregated sum of sites build storage.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsTimeTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of sites build compute time.', - 'default' => 0, - 'example' => 0, - ]) - ->addRule('buildsMbSecondsTotal', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated sum of sites build mbSeconds.', - 'default' => 0, - 'example' => 0, - ]) ->addRule('sites', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', @@ -65,48 +24,6 @@ class UsageSites extends Model 'example' => 0, 'array' => true ]) - ->addRule('deployments', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites deployment per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('deploymentsStorage', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites deployment storage per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('builds', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites build per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsStorage', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated sum of sites build storage per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsTime', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated sum of sites build compute time per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) - ->addRule('buildsMbSeconds', [ - 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated sum of sites build mbSeconds per period.', - 'default' => [], - 'example' => [], - 'array' => true - ]) ; } From 23ed68502f723104ec4420f4a0ffbf6d4d8a87e5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 06:27:56 +0000 Subject: [PATCH 21/41] Sites usage test --- tests/e2e/General/UsageTest.php | 165 ++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index a58209e746..cc592df7f7 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -12,6 +12,7 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Tests\E2E\Services\Functions\FunctionsBase; +use Utopia\CLI\Console; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; @@ -1058,6 +1059,170 @@ class UsageTest extends Scope return $data; } + protected function packageSite(string $site): CURLFile + { + $folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site"; + $tarPath = "$folderPath/code.tar.gz"; + + Console::execute("cd $folderPath && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); + + if (filesize($tarPath) > 1024 * 1024 * 5) { + throw new \Exception('Code package is too large. Use the chunked upload method instead.'); + } + + return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + } + + protected function setupSite(mixed $params): string + { + $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $params); + + $this->assertEquals($site['headers']['status-code'], 201, 'Setup site failed with status code: ' . $site['headers']['status-code'] . ' and response: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); + + $siteId = $site['body']['$id']; + + return $siteId; + } + + protected function getSite(string $siteId): mixed + { + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + return $site; + } + + public function testPrepareSitesStats(): array + { + $data = []; + + $siteId = $this->setupSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Site', + 'outputDirectory' => './', + 'providerBranch' => 'main', + 'providerRootDirectory' => './', + 'siteId' => ID::unique() + ]); + + $this->assertNotNull($siteId); + + $deployment = $this->createDeployment($siteId, [ + 'siteId' => $siteId, + 'code' => $this->packageSite('static'), + 'activate' => true, + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + $this->assertEquals('waiting', $deployment['body']['status']); + $this->assertEquals(true, (new DatetimeValidator())->isValid($deployment['body']['$createdAt'])); + + $deploymentIdActive = $deployment['body']['$id'] ?? ''; + + $this->assertEventually(function () use ($siteId, $deploymentIdActive) { + $deployment = $this->getDeployment($siteId, $deploymentIdActive); + + $this->assertEquals('ready', $deployment['body']['status']); + }, 50000, 500); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('static'), + 'activate' => 'false' + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + + $deploymentIdInactive = $deployment['body']['$id'] ?? ''; + + $this->assertEventually(function () use ($siteId, $deploymentIdInactive) { + $deployment = $this->getDeployment($siteId, $deploymentIdInactive); + + $this->assertEquals('ready', $deployment['body']['status']); + }, 50000, 500); + + $site = $this->getSite($siteId); + + $this->assertEquals(200, $site['headers']['status-code']); + $this->assertEquals($deploymentIdActive, $site['body']['deploymentId']); + $this->assertNotEquals($deploymentIdInactive, $site['body']['deploymentId']); + + $data = [ + 'siteId' => $siteId, + 'deployments' => 2, + 'deploymentsSuccess' => 1, + 'deploymentsFailed' => 1 + ]; + + return $data; + } + + /** @depends testPrepareSitesStats */ + public function testSitesStats(array $data) + { + $siteId = $data['siteId']; + $executionTime = $data['executionTime'] ?? 0; + $executions = $data['executions'] ?? 0; + $response = $this->client->call( + Client::METHOD_GET, + '/sites/' . $siteId . '/usage?range=30d', + $this->getConsoleHeaders() + ); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(19, count($response['body'])); + $this->assertEquals('30d', $response['body']['range']); + $this->assertIsArray($response['body']['deployments']); + $this->assertIsArray($response['body']['deploymentsStorage']); + $this->assertIsNumeric($response['body']['deploymentsStorageTotal']); + $this->assertIsNumeric($response['body']['buildsMbSecondsTotal']); + $this->assertIsNumeric($response['body']['executionsMbSecondsTotal']); + $this->assertIsArray($response['body']['builds']); + $this->assertIsArray($response['body']['buildsTime']); + $this->assertIsArray($response['body']['buildsMbSeconds']); + $this->assertIsArray($response['body']['executions']); + $this->assertIsArray($response['body']['executionsTime']); + $this->assertIsArray($response['body']['executionsMbSeconds']); + $this->assertEquals($executions, $response['body']['executions'][array_key_last($response['body']['executions'])]['value']); + $this->validateDates($response['body']['executions']); + $this->assertEquals($executionTime, $response['body']['executionsTime'][array_key_last($response['body']['executionsTime'])]['value']); + $this->validateDates($response['body']['executionsTime']); + + $response = $this->client->call( + Client::METHOD_GET, + '/sites/usage?range=30d', + $this->getConsoleHeaders() + ); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(21, count($response['body'])); + $this->assertEquals($response['body']['range'], '30d'); + $this->assertIsArray($response['body']['functions']); + $this->assertIsArray($response['body']['deployments']); + $this->assertIsArray($response['body']['deploymentsStorage']); + $this->assertIsArray($response['body']['builds']); + $this->assertIsArray($response['body']['buildsTime']); + $this->assertIsArray($response['body']['buildsMbSeconds']); + $this->assertIsArray($response['body']['executions']); + $this->assertIsArray($response['body']['executionsTime']); + $this->assertIsArray($response['body']['executionsMbSeconds']); + $this->assertEquals($executions, $response['body']['executions'][array_key_last($response['body']['executions'])]['value']); + $this->validateDates($response['body']['executions']); + $this->assertEquals($executionTime, $response['body']['executionsTime'][array_key_last($response['body']['executionsTime'])]['value']); + $this->validateDates($response['body']['executionsTime']); + $this->assertGreaterThan(0, $response['body']['buildsTime'][array_key_last($response['body']['buildsTime'])]['value']); + $this->validateDates($response['body']['buildsTime']); + } + /** @depends testFunctionsStats */ public function testCustomDomainsFunctionStats(array $data): void { From 1b88aa855cad0f90609fcfee9507333f1f021e32 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 06:28:21 +0000 Subject: [PATCH 22/41] fix typo --- tests/e2e/General/UsageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index cc592df7f7..8dc20f4908 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1206,7 +1206,7 @@ class UsageTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(21, count($response['body'])); $this->assertEquals($response['body']['range'], '30d'); - $this->assertIsArray($response['body']['functions']); + $this->assertIsArray($response['body']['sites']); $this->assertIsArray($response['body']['deployments']); $this->assertIsArray($response['body']['deploymentsStorage']); $this->assertIsArray($response['body']['builds']); From 49a514a206ad62b4b8f8f187c9f830d98432c464 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 06:35:20 +0000 Subject: [PATCH 23/41] separate metric test --- tests/e2e/General/UsageTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 8dc20f4908..172c2378ba 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1172,6 +1172,8 @@ class UsageTest extends Scope $siteId = $data['siteId']; $executionTime = $data['executionTime'] ?? 0; $executions = $data['executions'] ?? 0; + $deploymentsSuccess = $data['deploymentsSucces']; + $deploymentsFailed = $data['deploymentsFailed']; $response = $this->client->call( Client::METHOD_GET, '/sites/' . $siteId . '/usage?range=30d', @@ -1182,6 +1184,8 @@ class UsageTest extends Scope $this->assertEquals(19, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['deployments']); + $this->assertEquals($deploymentsSuccess, $response['body']['buildsSuccess']); + $this->assertEquals($deploymentsFailed, $response['body']['buildsFailed']); $this->assertIsArray($response['body']['deploymentsStorage']); $this->assertIsNumeric($response['body']['deploymentsStorageTotal']); $this->assertIsNumeric($response['body']['buildsMbSecondsTotal']); From af7c5f9f4067dcacf6b8e90d63a4e5b0c007a058 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 06:36:38 +0000 Subject: [PATCH 24/41] retry sites state test --- tests/e2e/General/UsageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 172c2378ba..8f95061a13 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1167,6 +1167,7 @@ class UsageTest extends Scope } /** @depends testPrepareSitesStats */ + #[Retry(count: 1)] public function testSitesStats(array $data) { $siteId = $data['siteId']; From 092bb1adacb884a662a67b8eef93b3ac4dd41f6e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 06:41:13 +0000 Subject: [PATCH 25/41] fix possible division by zero --- src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index 9845170251..b14f981064 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -130,16 +130,18 @@ class Get extends Base } } + $buildsTimeTotal = $usage[$metrics[4]]['total'] ?? 0; + $buildsTotal = $usage[$metrics[2]]['total'] ?? 0; $response->dynamic(new Document([ 'range' => $range, 'deploymentsTotal' => $usage[$metrics[0]]['total'], 'deploymentsStorageTotal' => $usage[$metrics[1]]['total'], - 'buildsTotal' => $usage[$metrics[2]]['total'], + 'buildsTotal' => $buildsTotal, 'buildsSuccess' => $usage[$metrics[9]]['total'], 'buildsFailed' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], - 'buildsTimeTotal' => $usage[$metrics[4]]['total'], - 'buildsTimeAverage' => (int) ($usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total']), + 'buildsTimeTotal' => $buildsTimeTotal, + 'buildsTimeAverage' => $buildsTotal === 0 ? 0 : (int) ($buildsTimeTotal / $buildsTotal), 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], 'deployments' => $usage[$metrics[0]]['data'], From e46ee904e0884b6eb1129ff551fe6118c6bd8bb0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 07:07:17 +0000 Subject: [PATCH 26/41] reuse code --- tests/e2e/General/UsageTest.php | 94 +++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 8f95061a13..d42a06fb13 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -12,6 +12,7 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Tests\E2E\Services\Functions\FunctionsBase; +use Tests\E2E\Services\Sites\SitesBase; use Utopia\CLI\Console; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; @@ -25,6 +26,57 @@ class UsageTest extends Scope use ProjectCustom; use SideServer; use FunctionsBase; + use SitesBase { + FunctionsBase::createDeployment insteadof SitesBase; + FunctionsBase::setupDeployment insteadof SitesBase; + FunctionsBase::createVariable insteadof SitesBase; + FunctionsBase::getVariable insteadof SitesBase; + FunctionsBase::listVariables insteadof SitesBase; + FunctionsBase::updateVariable insteadof SitesBase; + FunctionsBase::deleteVariable insteadof SitesBase; + FunctionsBase::getDeployment insteadof SitesBase; + FunctionsBase::listDeployments insteadof SitesBase; + FunctionsBase::deleteDeployment insteadof SitesBase; + FunctionsBase::setupDuplicateDeployment insteadof SitesBase; + FunctionsBase::createDuplicateDeployment insteadof SitesBase; + FunctionsBase::createTemplateDeployment insteadof SitesBase; + FunctionsBase::getUsage insteadof SitesBase; + FunctionsBase::getTemplate insteadof SitesBase; + FunctionsBase::getDeploymentDownload insteadof SitesBase; + FunctionsBase::cancelDeployment insteadof SitesBase; + FunctionsBase::listSpecifications insteadof SitesBase; + SitesBase::createDeployment as createDeploymentSite; + SitesBase::setupDeployment as setupDeploymentSite; + SitesBase::createVariable as createVariableSite; + SitesBase::getVariable as getVariableSite; + SitesBase::listVariables as listVariablesSite; + SitesBase::listVariables as listVariablesSite; + SitesBase::updateVariable as updateVariableSite; + SitesBase::updateVariable as updateVariableSite; + SitesBase::deleteVariable as deleteVariableSite; + SitesBase::deleteVariable as deleteVariableSite; + SitesBase::getDeployment as getDeploymentSite; + SitesBase::getDeployment as getDeploymentSite; + SitesBase::listDeployments as listDeploymentsSite; + SitesBase::listDeployments as listDeploymentsSite; + SitesBase::deleteDeployment as deleteDeploymentSite; + SitesBase::deleteDeployment as deleteDeploymentSite; + SitesBase::setupDuplicateDeployment as setupDuplicateDeploymentSite; + SitesBase::setupDuplicateDeployment as setupDuplicateDeploymentSite; + SitesBase::createDuplicateDeployment as createDuplicateDeploymentSite; + SitesBase::createDuplicateDeployment as createDuplicateDeploymentSite; + SitesBase::createTemplateDeployment as createTemplateDeploymentSite; + SitesBase::createTemplateDeployment as createTemplateDeploymentSite; + SitesBase::getUsage as getUsageSite; + SitesBase::getUsage as getUsageSite; + SitesBase::getTemplate as getTemplateSite; + SitesBase::getTemplate as getTemplateSite; + SitesBase::getDeploymentDownload as getDeploymentDownloadSite; + SitesBase::getDeploymentDownload as getDeploymentDownloadSite; + SitesBase::cancelDeployment as cancelDeploymentSite; + SitesBase::cancelDeployment as cancelDeploymentSite; + SitesBase::listSpecifications as listSpecificationsSite; + } private const WAIT = 5; private const CREATE = 20; @@ -1059,44 +1111,6 @@ class UsageTest extends Scope return $data; } - protected function packageSite(string $site): CURLFile - { - $folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site"; - $tarPath = "$folderPath/code.tar.gz"; - - Console::execute("cd $folderPath && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); - - if (filesize($tarPath) > 1024 * 1024 * 5) { - throw new \Exception('Code package is too large. Use the chunked upload method instead.'); - } - - return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); - } - - protected function setupSite(mixed $params): string - { - $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), $params); - - $this->assertEquals($site['headers']['status-code'], 201, 'Setup site failed with status code: ' . $site['headers']['status-code'] . ' and response: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); - - $siteId = $site['body']['$id']; - - return $siteId; - } - - protected function getSite(string $siteId): mixed - { - $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - return $site; - } public function testPrepareSitesStats(): array { @@ -1115,7 +1129,7 @@ class UsageTest extends Scope $this->assertNotNull($siteId); - $deployment = $this->createDeployment($siteId, [ + $deployment = $this->createDeploymentSite($siteId, [ 'siteId' => $siteId, 'code' => $this->packageSite('static'), 'activate' => true, @@ -1134,7 +1148,7 @@ class UsageTest extends Scope $this->assertEquals('ready', $deployment['body']['status']); }, 50000, 500); - $deployment = $this->createDeployment($siteId, [ + $deployment = $this->createDeploymentSite($siteId, [ 'code' => $this->packageSite('static'), 'activate' => 'false' ]); From cb2905c83756e40ff261e425e644ded7b9bc814d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 07:09:32 +0000 Subject: [PATCH 27/41] fix use correct method --- tests/e2e/General/UsageTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index d42a06fb13..3c42eca11f 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -13,7 +13,6 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Tests\E2E\Services\Functions\FunctionsBase; use Tests\E2E\Services\Sites\SitesBase; -use Utopia\CLI\Console; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; @@ -1114,8 +1113,6 @@ class UsageTest extends Scope public function testPrepareSitesStats(): array { - $data = []; - $siteId = $this->setupSite([ 'buildRuntime' => 'node-22', 'fallbackFile' => '', @@ -1143,7 +1140,7 @@ class UsageTest extends Scope $deploymentIdActive = $deployment['body']['$id'] ?? ''; $this->assertEventually(function () use ($siteId, $deploymentIdActive) { - $deployment = $this->getDeployment($siteId, $deploymentIdActive); + $deployment = $this->getDeploymentSite($siteId, $deploymentIdActive); $this->assertEquals('ready', $deployment['body']['status']); }, 50000, 500); @@ -1159,7 +1156,7 @@ class UsageTest extends Scope $deploymentIdInactive = $deployment['body']['$id'] ?? ''; $this->assertEventually(function () use ($siteId, $deploymentIdInactive) { - $deployment = $this->getDeployment($siteId, $deploymentIdInactive); + $deployment = $this->getDeploymentSite($siteId, $deploymentIdInactive); $this->assertEquals('ready', $deployment['body']['status']); }, 50000, 500); From 14e740e62dbc7d67f7adc73fa86e905973e88de8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 07:10:52 +0000 Subject: [PATCH 28/41] fix typo --- tests/e2e/General/UsageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 3c42eca11f..f83da50019 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1184,7 +1184,7 @@ class UsageTest extends Scope $siteId = $data['siteId']; $executionTime = $data['executionTime'] ?? 0; $executions = $data['executions'] ?? 0; - $deploymentsSuccess = $data['deploymentsSucces']; + $deploymentsSuccess = $data['deploymentsSuccess']; $deploymentsFailed = $data['deploymentsFailed']; $response = $this->client->call( Client::METHOD_GET, From 76fb59fd738804ff5b419e57f7519846d78c6708 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 07:11:46 +0000 Subject: [PATCH 29/41] fix --- tests/e2e/General/UsageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index f83da50019..4206e96b1d 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1193,7 +1193,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(19, count($response['body'])); + $this->assertEquals(22, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['deployments']); $this->assertEquals($deploymentsSuccess, $response['body']['buildsSuccess']); From c07c1479f7dec6c7b949a434577bf3de0515ea72 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 07:15:49 +0000 Subject: [PATCH 30/41] fix --- 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 4206e96b1d..67351e7465 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1170,8 +1170,8 @@ class UsageTest extends Scope $data = [ 'siteId' => $siteId, 'deployments' => 2, - 'deploymentsSuccess' => 1, - 'deploymentsFailed' => 1 + 'deploymentsSuccess' => 2, + 'deploymentsFailed' => 0 ]; return $data; From 327cb671a1cc64f55dfa038eee7fc7c90fdd4127 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 04:49:42 +0000 Subject: [PATCH 31/41] fix sites usage --- src/Appwrite/Utopia/Response/Model/UsageSites.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Utopia/Response/Model/UsageSites.php b/src/Appwrite/Utopia/Response/Model/UsageSites.php index 78c8f22d62..bc730b43dd 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSites.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSites.php @@ -8,6 +8,7 @@ class UsageSites extends UsageFunctions { public function __construct() { + parent::__construct(); $this ->removeRule('functionsTotal') ->removeRule('functions') From a6d15d032fd9c60906cbdf1e44e40e097dd7c61d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 05:06:03 +0000 Subject: [PATCH 32/41] improve sites usage --- .../Platform/Modules/Sites/Http/Usage/XList.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php index 6faf16e82f..4f0d051cff 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php @@ -66,7 +66,10 @@ class XList extends Base str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS), str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_STORAGE), str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_EXECUTIONS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -120,14 +123,20 @@ class XList extends Base 'buildsTotal' => $usage[$metrics[3]]['total'], 'buildsStorageTotal' => $usage[$metrics[4]]['total'], 'buildsTimeTotal' => $usage[$metrics[5]]['total'], + 'executionsTotal' => $usage[$metrics[6]]['total'], + 'executionsTimeTotal' => $usage[$metrics[7]]['total'], 'sites' => $usage[$metrics[0]]['data'], 'deployments' => $usage[$metrics[1]]['data'], 'deploymentsStorage' => $usage[$metrics[2]]['data'], 'builds' => $usage[$metrics[3]]['data'], 'buildsStorage' => $usage[$metrics[4]]['data'], 'buildsTime' => $usage[$metrics[5]]['data'], + 'executions' => $usage[$metrics[6]]['data'], + 'executionsTime' => $usage[$metrics[7]]['data'], 'buildsMbSecondsTotal' => $usage[$metrics[8]]['total'], - 'buildsMbSeconds' => $usage[$metrics[8]]['data'] + 'buildsMbSeconds' => $usage[$metrics[8]]['data'], + 'executionsMbSeconds' => $usage[$metrics[9]]['data'], + 'executionsMbSecondsTotal' => $usage[$metrics[9]]['total'], ]), Response::MODEL_USAGE_SITES); } } From ed332a776f4d413c15c2d898624ae6a42bdf809c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 08:42:55 +0000 Subject: [PATCH 33/41] More stats in usage endpoints --- .../Platform/Modules/Sites/Http/Usage/Get.php | 20 +++++++-- .../Modules/Sites/Http/Usage/XList.php | 19 ++++++++- .../Utopia/Response/Model/UsageFunction.php | 18 +++++++- .../Utopia/Response/Model/UsageFunctions.php | 26 ++++++++++++ .../Utopia/Response/Model/UsageSite.php | 41 +++++++++++++++++++ .../Utopia/Response/Model/UsageSites.php | 39 ++++++++++++++++++ tests/e2e/General/UsageTest.php | 22 +++++++--- 7 files changed, 171 insertions(+), 14 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index b14f981064..158674aeba 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -84,6 +84,10 @@ class Get extends Base str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_REQUESTS), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_INBOUND), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_OUTBOUND), + ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -137,13 +141,18 @@ class Get extends Base 'deploymentsTotal' => $usage[$metrics[0]]['total'], 'deploymentsStorageTotal' => $usage[$metrics[1]]['total'], 'buildsTotal' => $buildsTotal, - 'buildsSuccess' => $usage[$metrics[9]]['total'], - 'buildsFailed' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $buildsTimeTotal, 'buildsTimeAverage' => $buildsTotal === 0 ? 0 : (int) ($buildsTimeTotal / $buildsTotal), 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], + 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], + 'executionsMbSecondsTotal' => $usage[$metrics[8]]['total'], + 'buildsSuccessTotal' => $usage[$metrics[9]]['total'], + 'buildsFailedTotal' => $usage[$metrics[10]]['total'], + 'requestsTotal' => $usage[$metrics[11]]['total'], + 'inboundTotal' => $usage[$metrics[12]]['total'], + 'outboundTotal' => $usage[$metrics[13]]['total'], 'deployments' => $usage[$metrics[0]]['data'], 'deploymentsStorage' => $usage[$metrics[1]]['data'], 'builds' => $usage[$metrics[2]]['data'], @@ -151,10 +160,13 @@ class Get extends Base 'buildsTime' => $usage[$metrics[4]]['data'], 'executions' => $usage[$metrics[5]]['data'], 'executionsTime' => $usage[$metrics[6]]['data'], - 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], 'buildsMbSeconds' => $usage[$metrics[7]]['data'], 'executionsMbSeconds' => $usage[$metrics[8]]['data'], - 'executionsMbSecondsTotal' => $usage[$metrics[8]]['total'] + 'buildsSuccess' => $usage[$metrics[9]]['data'], + 'buildsFailed' => $usage[$metrics[10]]['data'], + 'requests' => $usage[$metrics[11]]['data'], + 'inbound' => $usage[$metrics[12]]['data'], + 'outbound' => $usage[$metrics[13]]['data'], ]), Response::MODEL_USAGE_SITE); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php index 4f0d051cff..6f830b665e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/XList.php @@ -70,6 +70,11 @@ class XList extends Base str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_SUCCESS), + str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS_FAILED), + METRIC_SITES_REQUESTS, + METRIC_SITES_INBOUND, + METRIC_SITES_OUTBOUND, ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -125,6 +130,13 @@ class XList extends Base 'buildsTimeTotal' => $usage[$metrics[5]]['total'], 'executionsTotal' => $usage[$metrics[6]]['total'], 'executionsTimeTotal' => $usage[$metrics[7]]['total'], + 'buildsMbSecondsTotal' => $usage[$metrics[8]]['total'], + 'executionsMbSecondsTotal' => $usage[$metrics[9]]['total'], + 'buildsSuccessTotal' => $usage[$metrics[10]]['total'], + 'buildsFailedTotal' => $usage[$metrics[11]]['total'], + 'requestsTotal' => $usage[$metrics[12]]['total'], + 'inboundTotal' => $usage[$metrics[13]]['total'], + 'outboundTotal' => $usage[$metrics[14]]['total'], 'sites' => $usage[$metrics[0]]['data'], 'deployments' => $usage[$metrics[1]]['data'], 'deploymentsStorage' => $usage[$metrics[2]]['data'], @@ -133,10 +145,13 @@ class XList extends Base 'buildsTime' => $usage[$metrics[5]]['data'], 'executions' => $usage[$metrics[6]]['data'], 'executionsTime' => $usage[$metrics[7]]['data'], - 'buildsMbSecondsTotal' => $usage[$metrics[8]]['total'], 'buildsMbSeconds' => $usage[$metrics[8]]['data'], 'executionsMbSeconds' => $usage[$metrics[9]]['data'], - 'executionsMbSecondsTotal' => $usage[$metrics[9]]['total'], + 'buildsSuccess' => $usage[$metrics[10]]['data'], + 'buildsFailed' => $usage[$metrics[11]]['data'], + 'requests' => $usage[$metrics[12]]['data'], + 'inbound' => $usage[$metrics[13]]['data'], + 'outbound' => $usage[$metrics[14]]['data'], ]), Response::MODEL_USAGE_SITES); } } diff --git a/src/Appwrite/Utopia/Response/Model/UsageFunction.php b/src/Appwrite/Utopia/Response/Model/UsageFunction.php index 5066b74eec..6a63076c8d 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageFunction.php +++ b/src/Appwrite/Utopia/Response/Model/UsageFunction.php @@ -34,13 +34,13 @@ class UsageFunction extends Model 'default' => 0, 'example' => 0, ]) - ->addRule('buildsSuccess', [ + ->addRule('buildsSuccessTotal', [ 'type' => self::TYPE_INTEGER, 'description' => 'Total aggregated number of successful function builds.', 'default' => 0, 'example' => 0, ]) - ->addRule('buildsFailed', [ + ->addRule('buildsFailedTotal', [ 'type' => self::TYPE_INTEGER, 'description' => 'Total aggregated number of failed function builds.', 'default' => 0, @@ -151,6 +151,20 @@ class UsageFunction extends Model 'example' => [], 'array' => true ]) + ->addRule('buildsSuccess', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of function mbSeconds per period.', + 'default' => [], + 'example' => [], + 'array' => true + ]) + ->addRule('buildsFailed', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of function mbSeconds per period.', + 'default' => [], + 'example' => [], + 'array' => true + ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/UsageFunctions.php b/src/Appwrite/Utopia/Response/Model/UsageFunctions.php index 90327a7e8a..2c1eb9bd7f 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageFunctions.php +++ b/src/Appwrite/Utopia/Response/Model/UsageFunctions.php @@ -97,6 +97,18 @@ class UsageFunctions extends Model 'example' => [], 'array' => true ]) + ->addRule('buildsSuccessTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of successful function builds.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('buildsFailedTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of failed function builds.', + 'default' => 0, + 'example' => 0, + ]) ->addRule('builds', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of functions build per period.', @@ -146,6 +158,20 @@ class UsageFunctions extends Model 'example' => [], 'array' => true ]) + ->addRule('buildsSuccess', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of function mbSeconds per period.', + 'default' => [], + 'example' => [], + 'array' => true + ]) + ->addRule('buildsFailed', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of function mbSeconds per period.', + 'default' => [], + 'example' => [], + 'array' => true + ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/UsageSite.php b/src/Appwrite/Utopia/Response/Model/UsageSite.php index b4cd45950c..594513cf63 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSite.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSite.php @@ -9,6 +9,47 @@ class UsageSite extends UsageFunction public function __construct() { parent::__construct(); + $this + ->addRule('requestsTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('requests', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) + ->addRule('inboundTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('inbound', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) + ->addRule('outboundTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('outbound', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) + ; } /** diff --git a/src/Appwrite/Utopia/Response/Model/UsageSites.php b/src/Appwrite/Utopia/Response/Model/UsageSites.php index bc730b43dd..b3de95cb82 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSites.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSites.php @@ -25,6 +25,45 @@ class UsageSites extends UsageFunctions 'example' => 0, 'array' => true ]) + ->addRule('requestsTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('requests', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) + ->addRule('inboundTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('inbound', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) + ->addRule('outboundTotal', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total aggregated number of sites.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('outbound', [ + 'type' => Response::MODEL_METRIC, + 'description' => 'Aggregated number of sites per period.', + 'default' => 0, + 'example' => 0, + 'array' => true + ]) ; } diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 67351e7465..88fd78de70 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1064,7 +1064,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(19, count($response['body'])); + $this->assertEquals(22, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['deployments']); $this->assertIsArray($response['body']['deploymentsStorage']); @@ -1089,7 +1089,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(21, count($response['body'])); + $this->assertEquals(31, count($response['body'])); $this->assertEquals($response['body']['range'], '30d'); $this->assertIsArray($response['body']['functions']); $this->assertIsArray($response['body']['deployments']); @@ -1193,11 +1193,11 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(22, count($response['body'])); + $this->assertEquals(30, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['deployments']); - $this->assertEquals($deploymentsSuccess, $response['body']['buildsSuccess']); - $this->assertEquals($deploymentsFailed, $response['body']['buildsFailed']); + $this->assertEquals($deploymentsSuccess, $response['body']['buildsSuccessTotal']); + $this->assertEquals($deploymentsFailed, $response['body']['buildsFailedTotal']); $this->assertIsArray($response['body']['deploymentsStorage']); $this->assertIsNumeric($response['body']['deploymentsStorageTotal']); $this->assertIsNumeric($response['body']['buildsMbSecondsTotal']); @@ -1208,6 +1208,11 @@ class UsageTest extends Scope $this->assertIsArray($response['body']['executions']); $this->assertIsArray($response['body']['executionsTime']); $this->assertIsArray($response['body']['executionsMbSeconds']); + $this->assertIsArray($response['body']['buildsSuccess']); + $this->assertIsArray($response['body']['buildsFailed']); + $this->assertIsArray($response['body']['requests']); + $this->assertIsArray($response['body']['inbound']); + $this->assertIsArray($response['body']['outbound']); $this->assertEquals($executions, $response['body']['executions'][array_key_last($response['body']['executions'])]['value']); $this->validateDates($response['body']['executions']); $this->assertEquals($executionTime, $response['body']['executionsTime'][array_key_last($response['body']['executionsTime'])]['value']); @@ -1220,7 +1225,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(21, count($response['body'])); + $this->assertEquals(31, count($response['body'])); $this->assertEquals($response['body']['range'], '30d'); $this->assertIsArray($response['body']['sites']); $this->assertIsArray($response['body']['deployments']); @@ -1231,6 +1236,11 @@ class UsageTest extends Scope $this->assertIsArray($response['body']['executions']); $this->assertIsArray($response['body']['executionsTime']); $this->assertIsArray($response['body']['executionsMbSeconds']); + $this->assertIsArray($response['body']['buildsSuccess']); + $this->assertIsArray($response['body']['buildsFailed']); + $this->assertIsArray($response['body']['requests']); + $this->assertIsArray($response['body']['inbound']); + $this->assertIsArray($response['body']['outbound']); $this->assertEquals($executions, $response['body']['executions'][array_key_last($response['body']['executions'])]['value']); $this->validateDates($response['body']['executions']); $this->assertEquals($executionTime, $response['body']['executionsTime'][array_key_last($response['body']['executionsTime'])]['value']); From 080350f7ad350b709291c481550ff1b1a825d278 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 08:52:12 +0000 Subject: [PATCH 34/41] Fix data types and response --- .../Modules/Functions/Http/Usage/Get.php | 10 ++++++---- .../Modules/Functions/Http/Usage/XList.php | 10 ++++++++-- src/Appwrite/Utopia/Response/Model/UsageSite.php | 12 ++++++------ .../Utopia/Response/Model/UsageSites.php | 16 ++++++++-------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index 8c6a2bc741..94eed94a17 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -131,13 +131,15 @@ class Get extends Base 'deploymentsTotal' => $usage[$metrics[0]]['total'], 'deploymentsStorageTotal' => $usage[$metrics[1]]['total'], 'buildsTotal' => $usage[$metrics[2]]['total'], - 'buildsSuccess' => $usage[$metrics[9]]['total'], - 'buildsFailed' => $usage[$metrics[10]]['total'], + 'buildsSuccessTotal' => $usage[$metrics[9]]['total'], + 'buildsFailedTotal' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $usage[$metrics[4]]['total'], 'buildsTimeAverage' => (int) ($usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total']), 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], + 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], + 'executionsMbSecondsTotal' => $usage[$metrics[8]]['total'], 'deployments' => $usage[$metrics[0]]['data'], 'deploymentsStorage' => $usage[$metrics[1]]['data'], 'builds' => $usage[$metrics[2]]['data'], @@ -145,10 +147,10 @@ class Get extends Base 'buildsTime' => $usage[$metrics[4]]['data'], 'executions' => $usage[$metrics[5]]['data'], 'executionsTime' => $usage[$metrics[6]]['data'], - 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], 'buildsMbSeconds' => $usage[$metrics[7]]['data'], 'executionsMbSeconds' => $usage[$metrics[8]]['data'], - 'executionsMbSecondsTotal' => $usage[$metrics[8]]['total'] + 'buildsSuccess' => $usage[$metrics[9]]['data'], + 'buildsFailed' => $usage[$metrics[10]]['data'], ]), Response::MODEL_USAGE_FUNCTION); } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php index 0e652e23b2..e4a7c01bdf 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/XList.php @@ -70,6 +70,8 @@ class XList extends Base str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_SUCCESS), + str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS_FAILED), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -125,6 +127,10 @@ class XList extends Base 'buildsTimeTotal' => $usage[$metrics[5]]['total'], 'executionsTotal' => $usage[$metrics[6]]['total'], 'executionsTimeTotal' => $usage[$metrics[7]]['total'], + 'buildsMbSecondsTotal' => $usage[$metrics[8]]['total'], + 'executionsMbSecondsTotal' => $usage[$metrics[9]]['total'], + 'buildsSuccessTotal' => $usage[$metrics[10]]['total'], + 'buildsFailedTotal' => $usage[$metrics[11]]['total'], 'functions' => $usage[$metrics[0]]['data'], 'deployments' => $usage[$metrics[1]]['data'], 'deploymentsStorage' => $usage[$metrics[2]]['data'], @@ -133,10 +139,10 @@ class XList extends Base 'buildsTime' => $usage[$metrics[5]]['data'], 'executions' => $usage[$metrics[6]]['data'], 'executionsTime' => $usage[$metrics[7]]['data'], - 'buildsMbSecondsTotal' => $usage[$metrics[8]]['total'], 'buildsMbSeconds' => $usage[$metrics[8]]['data'], 'executionsMbSeconds' => $usage[$metrics[9]]['data'], - 'executionsMbSecondsTotal' => $usage[$metrics[9]]['total'], + 'buildsSuccess' => $usage[$metrics[10]]['data'], + 'buildsFailed' => $usage[$metrics[11]]['data'], ]), Response::MODEL_USAGE_FUNCTIONS); } } diff --git a/src/Appwrite/Utopia/Response/Model/UsageSite.php b/src/Appwrite/Utopia/Response/Model/UsageSite.php index 594513cf63..b945032b6b 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSite.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSite.php @@ -19,8 +19,8 @@ class UsageSite extends UsageFunction ->addRule('requests', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ->addRule('inboundTotal', [ @@ -32,8 +32,8 @@ class UsageSite extends UsageFunction ->addRule('inbound', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ->addRule('outboundTotal', [ @@ -45,8 +45,8 @@ class UsageSite extends UsageFunction ->addRule('outbound', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ; diff --git a/src/Appwrite/Utopia/Response/Model/UsageSites.php b/src/Appwrite/Utopia/Response/Model/UsageSites.php index b3de95cb82..d983982937 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSites.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSites.php @@ -21,8 +21,8 @@ class UsageSites extends UsageFunctions ->addRule('sites', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ->addRule('requestsTotal', [ @@ -34,8 +34,8 @@ class UsageSites extends UsageFunctions ->addRule('requests', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ->addRule('inboundTotal', [ @@ -47,8 +47,8 @@ class UsageSites extends UsageFunctions ->addRule('inbound', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ->addRule('outboundTotal', [ @@ -60,8 +60,8 @@ class UsageSites extends UsageFunctions ->addRule('outbound', [ 'type' => Response::MODEL_METRIC, 'description' => 'Aggregated number of sites per period.', - 'default' => 0, - 'example' => 0, + 'default' => [], + 'example' => [], 'array' => true ]) ; From ad72805fd6b0ae6df7318fba1d29b0e23b2fdf51 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 08:53:36 +0000 Subject: [PATCH 35/41] Fix test --- 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 88fd78de70..1f447a8e04 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1064,7 +1064,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(22, count($response['body'])); + $this->assertEquals(24, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $this->assertIsArray($response['body']['deployments']); $this->assertIsArray($response['body']['deploymentsStorage']); @@ -1089,7 +1089,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(31, count($response['body'])); + $this->assertEquals(25, count($response['body'])); $this->assertEquals($response['body']['range'], '30d'); $this->assertIsArray($response['body']['functions']); $this->assertIsArray($response['body']['deployments']); From 8d239b7dc817a68aa6a0dd1181076c07186c7c63 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 08:55:22 +0000 Subject: [PATCH 36/41] Fix test --- tests/e2e/General/UsageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 1f447a8e04..9d94a15669 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1332,7 +1332,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(19, count($response['body'])); + $this->assertEquals(24, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); // Check if the new values are greater than the old values From a1a6b40277e2cf513cae39821783a079338544c1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 08:59:20 +0000 Subject: [PATCH 37/41] fix description --- src/Appwrite/Utopia/Response/Model/UsageFunction.php | 4 ++-- .../Utopia/Response/Model/UsageFunctions.php | 4 ++-- src/Appwrite/Utopia/Response/Model/UsageSite.php | 12 ++++++------ src/Appwrite/Utopia/Response/Model/UsageSites.php | 12 ++++++------ tests/e2e/General/UsageTest.php | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/UsageFunction.php b/src/Appwrite/Utopia/Response/Model/UsageFunction.php index 6a63076c8d..32a23250d4 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageFunction.php +++ b/src/Appwrite/Utopia/Response/Model/UsageFunction.php @@ -153,14 +153,14 @@ class UsageFunction extends Model ]) ->addRule('buildsSuccess', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of function mbSeconds per period.', + 'description' => 'Aggregated number of successful builds per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('buildsFailed', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of function mbSeconds per period.', + 'description' => 'Aggregated number of failed builds per period.', 'default' => [], 'example' => [], 'array' => true diff --git a/src/Appwrite/Utopia/Response/Model/UsageFunctions.php b/src/Appwrite/Utopia/Response/Model/UsageFunctions.php index 2c1eb9bd7f..6dc03c6293 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageFunctions.php +++ b/src/Appwrite/Utopia/Response/Model/UsageFunctions.php @@ -160,14 +160,14 @@ class UsageFunctions extends Model ]) ->addRule('buildsSuccess', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of function mbSeconds per period.', + 'description' => 'Aggregated number of successful function builds per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('buildsFailed', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of function mbSeconds per period.', + 'description' => 'Aggregated number of failed function builds per period.', 'default' => [], 'example' => [], 'array' => true diff --git a/src/Appwrite/Utopia/Response/Model/UsageSite.php b/src/Appwrite/Utopia/Response/Model/UsageSite.php index b945032b6b..c45dc831cd 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSite.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSite.php @@ -12,39 +12,39 @@ class UsageSite extends UsageFunction $this ->addRule('requestsTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated number of requests.', 'default' => 0, 'example' => 0, ]) ->addRule('requests', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of requests per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('inboundTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated inbound bandwidth.', 'default' => 0, 'example' => 0, ]) ->addRule('inbound', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of inbound bandwidth per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('outboundTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated outbound bandwidth.', 'default' => 0, 'example' => 0, ]) ->addRule('outbound', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of outbound bandwidth per period.', 'default' => [], 'example' => [], 'array' => true diff --git a/src/Appwrite/Utopia/Response/Model/UsageSites.php b/src/Appwrite/Utopia/Response/Model/UsageSites.php index d983982937..74435b332c 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageSites.php +++ b/src/Appwrite/Utopia/Response/Model/UsageSites.php @@ -27,39 +27,39 @@ class UsageSites extends UsageFunctions ]) ->addRule('requestsTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated number of requests.', 'default' => 0, 'example' => 0, ]) ->addRule('requests', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of requests per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('inboundTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated inbound bandwidth.', 'default' => 0, 'example' => 0, ]) ->addRule('inbound', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of inbound bandwidth per period.', 'default' => [], 'example' => [], 'array' => true ]) ->addRule('outboundTotal', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total aggregated number of sites.', + 'description' => 'Total aggregated outbound bandwidth.', 'default' => 0, 'example' => 0, ]) ->addRule('outbound', [ 'type' => Response::MODEL_METRIC, - 'description' => 'Aggregated number of sites per period.', + 'description' => 'Aggregated number of outbound bandwidth per period.', 'default' => [], 'example' => [], 'array' => true diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 9d94a15669..72bf747576 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1290,7 +1290,7 @@ class UsageTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(19, count($response['body'])); + $this->assertEquals(24, count($response['body'])); $this->assertEquals('30d', $response['body']['range']); $functionsMetrics = $response['body']; From 12bf434f6aad1a82efdc75bc0a5ff5fa32ddfa1e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 09:08:00 +0000 Subject: [PATCH 38/41] fix division by 0 --- src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index 94eed94a17..7f64fa8d8c 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -126,6 +126,8 @@ class Get extends Base } } + $buildsTimeTotal = $usage[$metrics[4]]['total'] ?? 0; + $buildsTotal = $usage[$metrics[2]]['total'] ?? 0; $response->dynamic(new Document([ 'range' => $range, 'deploymentsTotal' => $usage[$metrics[0]]['total'], @@ -135,7 +137,7 @@ class Get extends Base 'buildsFailedTotal' => $usage[$metrics[10]]['total'], 'buildsStorageTotal' => $usage[$metrics[3]]['total'], 'buildsTimeTotal' => $usage[$metrics[4]]['total'], - 'buildsTimeAverage' => (int) ($usage[$metrics[4]]['total'] / $usage[$metrics[2]]['total']), + 'buildsTimeAverage' => $buildsTotal === 0 ? 0 : (int) ($buildsTimeTotal / $buildsTotal), 'executionsTotal' => $usage[$metrics[5]]['total'], 'executionsTimeTotal' => $usage[$metrics[6]]['total'], 'buildsMbSecondsTotal' => $usage[$metrics[7]]['total'], From c7a97a16dfe8ec59bb80f6c4fd8896330c5b6272 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 8 Apr 2025 09:08:04 +0000 Subject: [PATCH 39/41] fix test --- tests/e2e/Services/Functions/FunctionsConsoleClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index 5e2310f2d7..24215f5352 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -62,7 +62,7 @@ class FunctionsConsoleClientTest extends Scope 'range' => '24h' ]); $this->assertEquals(200, $usage['headers']['status-code']); - $this->assertEquals(19, count($usage['body'])); + $this->assertEquals(24, count($usage['body'])); $this->assertEquals('24h', $usage['body']['range']); $this->assertIsNumeric($usage['body']['deploymentsTotal']); $this->assertIsNumeric($usage['body']['deploymentsStorageTotal']); From 387ef142cceecb24bfb0dec138ceeb3977936b5e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 9 Apr 2025 02:16:03 +0000 Subject: [PATCH 40/41] fix test --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index caa5bc6d9a..28af469d3d 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1736,7 +1736,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(19, count($response['body'])); + $this->assertEquals(2419, count($response['body'])); $this->assertEquals('24h', $response['body']['range']); $this->assertEquals(1, $response['body']['executionsTotal']); }, 25000, 1000); From be939c6598e1bfbaab26abdb1509f592e5b81bba Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 9 Apr 2025 02:57:49 +0000 Subject: [PATCH 41/41] Fix typo --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 28af469d3d..bee774be08 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1736,7 +1736,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(2419, count($response['body'])); + $this->assertEquals(24, count($response['body'])); $this->assertEquals('24h', $response['body']['range']); $this->assertEquals(1, $response['body']['executionsTotal']); }, 25000, 1000);