From fb5aeb14764e82df41fe2306516cf089195d64de Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 28 Jan 2025 07:19:27 +0000 Subject: [PATCH] skip some metrics override --- src/Appwrite/Platform/Workers/UsageDump.php | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Appwrite/Platform/Workers/UsageDump.php b/src/Appwrite/Platform/Workers/UsageDump.php index 6e7c59d200..0e7103b8c2 100644 --- a/src/Appwrite/Platform/Workers/UsageDump.php +++ b/src/Appwrite/Platform/Workers/UsageDump.php @@ -19,6 +19,51 @@ const METRIC_PROJECT_LEVEL_STORAGE = 2; class UsageDump extends Action { protected array $stats = []; + + /** + * Metrics to skip writing to logsDB + * As these metrics are calculated separately + * by logs DB + * @var array + */ + protected array $skipBaseMetrics = [ + METRIC_DATABASES => true, + METRIC_BUCKETS => true, + METRIC_USERS => true, + METRIC_FUNCTIONS => true, + METRIC_TEAMS => true, + METRIC_MESSAGES => true, + METRIC_USERS_ACTIVE => true, + METRIC_WEBHOOKS => true, + METRIC_PLATFORMS => true, + METRIC_PROVIDERS => true, + METRIC_TOPICS => true, + METRIC_KEYS => true, + METRIC_FILES => true, + METRIC_FILES_STORAGE => true, + METRIC_DEPLOYMENTS_STORAGE => true, + METRIC_BUILDS_STORAGE => true, + METRIC_DEPLOYMENTS => true, + METRIC_BUILDS => true, + METRIC_COLLECTIONS => true, + METRIC_DOCUMENTS => true, + ]; + + /** + * Skip metrics associated with parent IDs + * these need to be checked individually with `str_ends_with` + */ + protected array $skipParentIdMetrics = [ + '.files', + '.files.storage', + '.collections', + '.documents', + '.deployments', + '.deployments.storage', + '.builds', + '.builds.storage', + ]; + protected array $periods = [ '1h' => 'Y-m-d H:00', '1d' => 'Y-m-d 00:00', @@ -116,6 +161,14 @@ class UsageDump extends Action */ $clonedProjectDoucments = []; foreach ($projectDocuments as $document) { + if (array_key_exists($document->getAttribute('metric'), $this->skipBaseMetrics)) { + continue; + } + foreach ($this->skipParentIdMetrics as $skipMetric) { + if (str_ends_with($document->getAttribute('metric'), $skipMetric)) { + continue; + } + } $clonedProjectDoucments[] = new Document($document->getArrayCopy()); }