From 5ffb81df43f6384c14bc9fbb81f0092f6a6b621e Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 9 Dec 2024 17:42:05 +0200 Subject: [PATCH 1/2] update usage project attr --- src/Appwrite/Platform/Workers/Usage.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 034e558d5d..ce2cb3ff52 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -15,9 +15,10 @@ class Usage extends Action { private array $stats = []; private int $lastTriggeredTime = 0; + private int $aggregationInterval = 20; private int $keys = 0; private const INFINITY_PERIOD = '_inf_'; - private const KEYS_THRESHOLD = 10000; + private const KEYS_THRESHOLD = 12000; public static function getName(): string { @@ -39,6 +40,7 @@ class Usage extends Action $this->action($message, $getProjectDB, $queueForUsageDump); }); + $this->aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20'); $this->lastTriggeredTime = time(); } @@ -56,9 +58,7 @@ class Usage extends Action if (empty($payload)) { throw new Exception('Missing payload'); } - //Todo Figure out way to preserve keys when the container is being recreated @shimonewman - $aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20'); $project = new Document($payload['project'] ?? []); $projectId = $project->getInternalId(); foreach ($payload['reduce'] ?? [] as $document) { @@ -74,7 +74,11 @@ class Usage extends Action ); } - $this->stats[$projectId]['project'] = $project; + $this->stats[$projectId]['project'] = [ + '$uid' => $project->getId(), + '$internalId' => $project->getInternalId(), + 'database' => $project->getAttribute('database'), + ]; $this->stats[$projectId]['receivedAt'] = DateTime::now(); foreach ($payload['metrics'] ?? [] as $metric) { $this->keys++; @@ -89,7 +93,7 @@ class Usage extends Action // If keys crossed threshold or X time passed since the last send and there are some keys in the array ($this->stats) if ( $this->keys >= self::KEYS_THRESHOLD || - (time() - $this->lastTriggeredTime > $aggregationInterval && $this->keys > 0) + (time() - $this->lastTriggeredTime > $this->aggregationInterval && $this->keys > 0) ) { Console::warning('[' . DateTime::now() . '] Aggregated ' . $this->keys . ' keys'); From 834c237cd5e5f1c03a46d256ae671c9392b95200 Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 10 Dec 2024 15:18:21 +0200 Subject: [PATCH 2/2] handling map size --- src/Appwrite/Platform/Workers/Usage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index ce2cb3ff52..3f24210cea 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -18,7 +18,7 @@ class Usage extends Action private int $aggregationInterval = 20; private int $keys = 0; private const INFINITY_PERIOD = '_inf_'; - private const KEYS_THRESHOLD = 12000; + private const KEYS_THRESHOLD = 20000; public static function getName(): string {