diff --git a/app/workers/functions.php b/app/workers/functions.php index 1df776383..efd6ebb41 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -368,6 +368,7 @@ class FunctionsV1 extends Worker $usage = new Stats($statsd); $usage ->setParam('projectId', $project->getId()) + ->setParam('projectInternalId', $project->getInternalId()) ->setParam('functionId', $function->getId()) ->setParam('executions.{scope}.compute', 1) ->setParam('executionStatus', $execution->getAttribute('status', '')) diff --git a/src/Appwrite/Usage/Calculators/TimeSeries.php b/src/Appwrite/Usage/Calculators/TimeSeries.php index 7b9497e66..2ef3d77ca 100644 --- a/src/Appwrite/Usage/Calculators/TimeSeries.php +++ b/src/Appwrite/Usage/Calculators/TimeSeries.php @@ -492,7 +492,7 @@ class TimeSeries extends Calculator $value = (!empty($point['value'])) ? $point['value'] : 0; if (empty($point['projectInternalId'] ?? null)) { - return; + continue; } $this->createOrUpdateMetric( $point['projectInternalId'], diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index e5f02837b..cbe90c91f 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -684,6 +684,25 @@ class UsageTest extends Scope } $executionTime += (int) ($execution['body']['duration'] * 1000); + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', $headers, [ + 'async' => true, + ]); + + $this->assertEquals(202, $execution['headers']['status-code']); + $this->assertNotEmpty($execution['body']['$id']); + $this->assertEquals($functionId, $execution['body']['functionId']); + + sleep(10); + + $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $execution['body']['$id'], $headers); + + if ($execution['body']['status'] == 'failed') { + $failures++; + } elseif ($execution['body']['status'] == 'completed') { + $executions++; + } + $executionTime += (int) ($execution['body']['duration'] * 1000); + $data = array_merge($data, [ 'functionId' => $functionId, 'executionTime' => $executionTime,