From f3dcd6a79f145e9e3c0dcc0152f9286989173c9b Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 25 Dec 2022 13:06:25 +0200 Subject: [PATCH] add internalId to collections --- app/config/collections.php | 66 +++++++++++++++++++++++++++++++ app/controllers/api/functions.php | 4 ++ app/workers/builds.php | 4 +- app/workers/functions.php | 3 +- 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index a8c7a46b18..d6c56fac93 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -785,6 +785,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, @@ -2370,6 +2381,17 @@ $collections = [ '$id' => ID::custom('deployments'), 'name' => 'Deployments', 'attributes' => [ + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, @@ -2392,6 +2414,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('buildInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('buildId'), 'type' => Database::VAR_STRING, @@ -2572,6 +2605,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => 'deploymentInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, @@ -2688,6 +2732,17 @@ $collections = [ '$id' => ID::custom('executions'), 'name' => 'Executions', 'attributes' => [ + [ + '$id' => ID::custom('functionInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('functionId'), 'type' => Database::VAR_STRING, @@ -2699,6 +2754,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('deploymentInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 4c84795712..25a4541ca0 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -740,6 +740,7 @@ App::post('/v1/functions/:functionId/deployments') Permission::update(Role::any()), Permission::delete(Role::any()), ], + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -770,6 +771,7 @@ App::post('/v1/functions/:functionId/deployments') Permission::update(Role::any()), Permission::delete(Role::any()), ], + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -1116,7 +1118,9 @@ App::post('/v1/functions/:functionId/executions') $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ '$id' => $executionId, '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], + 'functionInternalId' => $function->getInternalId(), 'functionId' => $function->getId(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'trigger' => 'http', // http / schedule / event 'status' => $async ? 'waiting' : 'processing', // waiting / processing / completed / failed diff --git a/app/workers/builds.php b/app/workers/builds.php index 081537fdfb..fc0d40251c 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -97,6 +97,7 @@ class BuildsV1 extends Worker '$id' => $buildId, '$permissions' => [], 'startTime' => $startTime, + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'status' => 'processing', 'path' => '', @@ -108,7 +109,8 @@ class BuildsV1 extends Worker 'stderr' => '', 'duration' => 0 ])); - $deployment->setAttribute('buildId', $buildId); + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); } else { $build = $dbForProject->getDocument('builds', $buildId); diff --git a/app/workers/functions.php b/app/workers/functions.php index 2e8dccc7aa..07fef99750 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -209,7 +209,8 @@ Server::setResource('execute', function () { $usage ->setParam('projectId', $project->getId()) ->setParam('projectInternalId', $project->getInternalId()) - ->setParam('functionId', $function->getId()) // TODO: We should use functionInternalId in usage stats + ->setParam('functionId', $function->getId()) + ->setParam('functionInternalId', $function->getInternalId()) ->setParam('executions.{scope}.compute', 1) ->setParam('executionStatus', $execution->getAttribute('status', '')) ->setParam('executionTime', $execution->getAttribute('duration'))