From c4d64a52d6177f512e94065677b488bf9153a268 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 30 Aug 2024 12:55:25 +0900 Subject: [PATCH] Fix Bandwidth and other metrics not being tracked for custom domain executions --- app/controllers/general.php | 9 +++++++++ .../e2e/Services/Functions/FunctionsCustomServerTest.php | 1 + 2 files changed, 10 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 8defeb72f6..ff670c68ca 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -330,7 +330,16 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo throw $th; } } finally { + $fileSize = 0; + $file = $request->getFiles('file'); + if (!empty($file)) { + $fileSize = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size']; + } + $queueForUsage + ->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('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 576dba3118..c88178c4cc 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2445,6 +2445,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(19, count($response['body'])); $this->assertEquals('24h', $response['body']['range']); + $this->assertEquals(1, $response['body']['executionsTotal']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [