diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 044a63ad12..a3922072df 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -899,8 +899,6 @@ App::post('/v1/functions/:functionId/executions') ->desc('Create Execution') ->label('scope', 'execution.write') ->label('event', 'functions.[functionId].executions.[executionId].create') - ->label('usage.metric', 'executions.{scope}.compute') - ->label('usage.params', ['functionId' => 'request.functionId','executionStatus' => 'response.status', 'executionTime', 'response.time']) ->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'createExecution') @@ -918,7 +916,8 @@ App::post('/v1/functions/:functionId/executions') ->inject('dbForProject') ->inject('user') ->inject('events') - ->action(function (string $functionId, string $data, bool $async, Response $response, Document $project, Database $dbForProject, Document $user, Event $events) { + ->inject('usage') + ->action(function (string $functionId, string $data, bool $async, Response $response, Document $project, Database $dbForProject, Document $user, Event $events, Stats $usage) { $function = Authorization::skip(fn () => $dbForProject->getDocument('functions', $functionId)); @@ -1070,6 +1069,13 @@ App::post('/v1/functions/:functionId/executions') Authorization::skip(fn () => $dbForProject->updateDocument('executions', $executionId, $execution)); + // TODO revise this later using route label + $usage + ->setParam('functionId', $function->getId()) + ->setParam('functionExecution', 1) + ->setParam('functionStatus', $execution->getAttribute('status', '')) + ->setParam('functionExecutionTime', $execution->getAttribute('time')); // ms + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($execution, Response::MODEL_EXECUTION); diff --git a/app/workers/builds.php b/app/workers/builds.php index 55fd9e4826..d7e3e66c6e 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -224,7 +224,7 @@ class BuildsV1 extends Worker ->setParam('functionId', $function->getId()) ->setParam('builds.{scope}.compute', 1) ->setParam('buildStatus', $build->getAttribute('status', '')) - ->setParam('buildTime', $build->getAttribute('duration') * 1000) // ms + ->setParam('buildTime', $build->getAttribute('duration')) ->setParam('networkRequestSize', 0) ->setParam('networkResponseSize', 0) ->submit(); diff --git a/app/workers/functions.php b/app/workers/functions.php index 0fe8fb3fa6..e5d94e335e 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -361,7 +361,7 @@ class FunctionsV1 extends Worker ->setParam('functionId', $function->getId()) ->setParam('executions.{scope}.compute', 1) ->setParam('executionStatus', $execution->getAttribute('status', '')) - ->setParam('executionTime', $execution->getAttribute('time') * 1000) // ms + ->setParam('executionTime', $execution->getAttribute('time')) ->setParam('networkRequestSize', 0) ->setParam('networkResponseSize', 0) ->submit();