From 789d5d33abaac20fcaa9ade7b959e90e1029d7e3 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 24 Feb 2022 07:28:49 +0000 Subject: [PATCH 1/3] fix usage for tags -> deployments --- app/tasks/usage.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/tasks/usage.php b/app/tasks/usage.php index 0ee28f5cb6..18e3ed8271 100644 --- a/app/tasks/usage.php +++ b/app/tasks/usage.php @@ -416,17 +416,17 @@ $cli // Get total storage $dbForProject->setNamespace('_project_' . $projectId); - $storageTotal = $dbForProject->sum('tags', 'size'); + $storageTotal = $dbForProject->sum('deployments', 'size'); $time = (int) (floor(time() / 1800) * 1800); // Time rounded to nearest 30 minutes - $id = \md5($time . '_30m_storage.tags.total'); //Construct unique id for each metric using time, period and metric + $id = \md5($time . '_30m_storage.deployments.total'); //Construct unique id for each metric using time, period and metric $document = $dbForProject->getDocument('stats', $id); if ($document->isEmpty()) { $dbForProject->createDocument('stats', new Document([ '$id' => $id, 'period' => '30m', 'time' => $time, - 'metric' => 'storage.tags.total', + 'metric' => 'storage.deployments.total', 'value' => $storageTotal, 'type' => 1, ])); @@ -439,14 +439,14 @@ $cli } $time = (int) (floor(time() / 86400) * 86400); // Time rounded to nearest day - $id = \md5($time . '_1d_storage.tags.total'); //Construct unique id for each metric using time, period and metric + $id = \md5($time . '_1d_storage.deployments.total'); //Construct unique id for each metric using time, period and metric $document = $dbForProject->getDocument('stats', $id); if ($document->isEmpty()) { $dbForProject->createDocument('stats', new Document([ '$id' => $id, 'period' => '1d', 'time' => $time, - 'metric' => 'storage.tags.total', + 'metric' => 'storage.deployments.total', 'value' => $storageTotal, 'type' => 1, ])); From 5ba0635017d4f93e4afb7b70dfd765c8906ffc16 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 24 Feb 2022 07:28:59 +0000 Subject: [PATCH 2/3] send entrypoint --- app/workers/builds.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/workers/builds.php b/app/workers/builds.php index 2301e3d6d3..a213cfdec4 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -116,6 +116,7 @@ class BuildsV1 extends Worker projectId: $projectId, functionId: $functionId, deploymentId: $deploymentId, + entrypoint: $deployment->getAttribute('entrypoint'), source: $source, destination: APP_STORAGE_BUILDS . "/app-$projectId", vars: $vars, From 1fb3be5a2937bc3c010e435e98babc1809e4c429 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 24 Feb 2022 07:40:12 +0000 Subject: [PATCH 3/3] fix type error --- app/tasks/usage.php | 80 +++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/app/tasks/usage.php b/app/tasks/usage.php index 18e3ed8271..aa8c42bcb8 100644 --- a/app/tasks/usage.php +++ b/app/tasks/usage.php @@ -361,11 +361,13 @@ $cli $latestTime[$metric][$period['key']] = $time; } catch (\Exception $e) { // if projects are deleted this might fail Console::warning("Failed to save data for project {$projectId} and metric {$metricUpdated}: {$e->getMessage()}"); + Console::warning($e->getTraceAsString()); } } } } catch (\Exception $e) { Console::warning("Failed to Query: {$e->getMessage()}"); + Console::warning($e->getTraceAsString()); } } } @@ -375,6 +377,7 @@ $cli $loopTook = microtime(true) - $loopStart; $now = date('d-m-Y H:i:s', time()); Console::info("[{$now}] Aggregation took {$loopTook} seconds"); + Console::warning($e->getTraceAsString()); return; } @@ -416,47 +419,53 @@ $cli // Get total storage $dbForProject->setNamespace('_project_' . $projectId); - $storageTotal = $dbForProject->sum('deployments', 'size'); + $storageTotal = (int) $dbForProject->sum('deployments', 'size'); $time = (int) (floor(time() / 1800) * 1800); // Time rounded to nearest 30 minutes $id = \md5($time . '_30m_storage.deployments.total'); //Construct unique id for each metric using time, period and metric $document = $dbForProject->getDocument('stats', $id); - if ($document->isEmpty()) { - $dbForProject->createDocument('stats', new Document([ - '$id' => $id, - 'period' => '30m', - 'time' => $time, - 'metric' => 'storage.deployments.total', - 'value' => $storageTotal, - 'type' => 1, - ])); - } else { - $dbForProject->updateDocument( - 'stats', - $document->getId(), - $document->setAttribute('value', $storageTotal) - ); + try { + + if ($document->isEmpty()) { + $dbForProject->createDocument('stats', new Document([ + '$id' => $id, + 'period' => '30m', + 'time' => $time, + 'metric' => 'storage.deployments.total', + 'value' => $storageTotal, + 'type' => 1, + ])); + } else { + $dbForProject->updateDocument( + 'stats', + $document->getId(), + $document->setAttribute('value', $storageTotal) + ); + } + $time = (int) (floor(time() / 86400) * 86400); // Time rounded to nearest day + $id = \md5($time . '_1d_storage.deployments.total'); //Construct unique id for each metric using time, period and metric + $document = $dbForProject->getDocument('stats', $id); + if ($document->isEmpty()) { + $dbForProject->createDocument('stats', new Document([ + '$id' => $id, + 'period' => '1d', + 'time' => $time, + 'metric' => 'storage.deployments.total', + 'value' => $storageTotal, + 'type' => 1, + ])); + } else { + $dbForProject->updateDocument( + 'stats', + $document->getId(), + $document->setAttribute('value', $storageTotal) + ); + } + } catch(\Exception $e) { + Console::warning("Failed to save data for project {$projectId} and metric storage.deployments.total: {$e->getMessage()}"); + Console::warning($e->getTraceAsString()); } - $time = (int) (floor(time() / 86400) * 86400); // Time rounded to nearest day - $id = \md5($time . '_1d_storage.deployments.total'); //Construct unique id for each metric using time, period and metric - $document = $dbForProject->getDocument('stats', $id); - if ($document->isEmpty()) { - $dbForProject->createDocument('stats', new Document([ - '$id' => $id, - 'period' => '1d', - 'time' => $time, - 'metric' => 'storage.deployments.total', - 'value' => $storageTotal, - 'type' => 1, - ])); - } else { - $dbForProject->updateDocument( - 'stats', - $document->getId(), - $document->setAttribute('value', $storageTotal) - ); - } $collections = [ 'users' => [ @@ -749,6 +758,7 @@ $cli } } catch (\Exception$e) { Console::warning("Failed to save database counters data for project {$collection}: {$e->getMessage()}"); + Console::warning($e->getTraceAsString()); } } }