From 8e18af5db1df4190eecf4ec921485a8888ab0879 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 7 Apr 2025 04:45:20 +0000 Subject: [PATCH] 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 - ]) ; }