1
0
Fork 0
mirror of synced 2024-08-28 08:31:22 +12:00

add internalId to collections

This commit is contained in:
shimon 2022-12-22 19:18:54 +02:00
parent 20f9b0c655
commit b89e04f561
5 changed files with 69 additions and 10 deletions

View file

@ -61,7 +61,6 @@ $collections = [
], ],
], ],
], ],
'collections' => [ 'collections' => [
'$collection' => ID::custom('databases'), '$collection' => ID::custom('databases'),
'$id' => ID::custom('collections'), '$id' => ID::custom('collections'),
@ -2371,6 +2370,17 @@ $collections = [
'$id' => ID::custom('deployments'), '$id' => ID::custom('deployments'),
'name' => 'Deployments', 'name' => 'Deployments',
'attributes' => [ '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'), '$id' => ID::custom('resourceId'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,
@ -2393,6 +2403,17 @@ $collections = [
'array' => false, 'array' => false,
'filters' => [], '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'), '$id' => ID::custom('buildId'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,
@ -2573,6 +2594,17 @@ $collections = [
'array' => false, 'array' => false,
'filters' => [], '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'), '$id' => ID::custom('deploymentId'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,
@ -2689,6 +2721,17 @@ $collections = [
'$id' => ID::custom('executions'), '$id' => ID::custom('executions'),
'name' => 'Executions', 'name' => 'Executions',
'attributes' => [ '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'), '$id' => ID::custom('functionId'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,
@ -2700,6 +2743,17 @@ $collections = [
'array' => false, 'array' => false,
'filters' => [], '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'), '$id' => ID::custom('deploymentId'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,
@ -3318,7 +3372,6 @@ $collections = [
], ],
], ],
], ],
'files' => [ 'files' => [
'$collection' => ID::custom('buckets'), '$collection' => ID::custom('buckets'),
'$id' => ID::custom('files'), '$id' => ID::custom('files'),

View file

@ -526,6 +526,7 @@ App::post('/v1/functions/:functionId/deployments')
Permission::update(Role::any()), Permission::update(Role::any()),
Permission::delete(Role::any()), Permission::delete(Role::any()),
], ],
'resourceInternalId' => $function->getInternalId(),
'resourceId' => $function->getId(), 'resourceId' => $function->getId(),
'resourceType' => 'functions', 'resourceType' => 'functions',
'entrypoint' => $entrypoint, 'entrypoint' => $entrypoint,
@ -556,6 +557,7 @@ App::post('/v1/functions/:functionId/deployments')
Permission::update(Role::any()), Permission::update(Role::any()),
Permission::delete(Role::any()), Permission::delete(Role::any()),
], ],
'resourceInternalId' => $function->getInternalId(),
'resourceId' => $function->getId(), 'resourceId' => $function->getId(),
'resourceType' => 'functions', 'resourceType' => 'functions',
'entrypoint' => $entrypoint, 'entrypoint' => $entrypoint,
@ -902,7 +904,9 @@ App::post('/v1/functions/:functionId/executions')
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([
'$id' => $executionId, '$id' => $executionId,
'$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [],
'functionInternalId' => $function->getInternalId(),
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'deploymentInternalId' => $deployment->getInternalId(),
'deploymentId' => $deployment->getId(), 'deploymentId' => $deployment->getId(),
'trigger' => 'http', // http / schedule / event 'trigger' => 'http', // http / schedule / event
'status' => $async ? 'waiting' : 'processing', // waiting / processing / completed / failed 'status' => $async ? 'waiting' : 'processing', // waiting / processing / completed / failed

View file

@ -194,14 +194,14 @@ $databaseListener = function (string $event, Document $document, Document $proje
$queueForUsage $queueForUsage
->addMetric("deployments", $value) // per project ->addMetric("deployments", $value) // per project
->addMetric("deployments.storage", $document->getAttribute('size') * $value) // per project ->addMetric("deployments.storage", $document->getAttribute('size') * $value) // per project
->addMetric("{$document->getAttribute('resourceType')}" . "." . "{$document->getAttribute('resourceId')}" . ".deployments", $value)// per function ->addMetric("{$document->getAttribute('resourceType')}" . "." . "{$document->getAttribute('resourceInternalId')}" . ".deployments", $value)// per function
->addMetric("{$document->getAttribute('resourceType')}" . "." . "{$document->getAttribute('resourceId')}" . ".deployments.storage", $document->getAttribute('size') * $value) // per function ->addMetric("{$document->getAttribute('resourceType')}" . "." . "{$document->getAttribute('resourceInternalId')}" . ".deployments.storage", $document->getAttribute('size') * $value) // per function
; ;
break; break;
case $document->getCollection() === 'executions': case $document->getCollection() === 'executions':
$queueForUsage $queueForUsage
->addMetric("executions", $value) // per project ->addMetric("executions", $value) // per project
->addMetric("{$document->getAttribute('functionId')}" . ".executions", $value) // per function ->addMetric("{$document->getAttribute('functionInternalId')}" . ".executions", $value) // per function
; ;
break; break;
default: default:

View file

@ -96,6 +96,7 @@ class BuildsV1 extends Worker
'$id' => $buildId, '$id' => $buildId,
'$permissions' => [], '$permissions' => [],
'startTime' => $startTime, 'startTime' => $startTime,
'deploymentInternalId' => $deployment->getInternalId(),
'deploymentId' => $deployment->getId(), 'deploymentId' => $deployment->getId(),
'status' => 'processing', 'status' => 'processing',
'path' => '', 'path' => '',
@ -107,7 +108,8 @@ class BuildsV1 extends Worker
'stderr' => '', 'stderr' => '',
'duration' => 0 'duration' => 0
])); ]));
$deployment->setAttribute('buildId', $buildId); $deployment->setAttribute('buildId', $build->getId());
$deployment->setAttribute('buildInternalId', $build->getInternalId());
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
} else { } else {
$build = $dbForProject->getDocument('builds', $buildId); $build = $dbForProject->getDocument('builds', $buildId);
@ -254,9 +256,9 @@ class BuildsV1 extends Worker
->addMetric("builds", 1) // per project ->addMetric("builds", 1) // per project
->addMetric("builds.storage", $build->getAttribute('size', 0)) ->addMetric("builds.storage", $build->getAttribute('size', 0))
->addMetric("builds.compute", $build->getAttribute('duration', 0)) ->addMetric("builds.compute", $build->getAttribute('duration', 0))
->addMetric("{$function->getId()}" . ".builds", 1) // per function ->addMetric("{$function->getInternalId()}" . ".builds", 1) // per function
->addMetric("{$function->getId()}" . ".builds.storage", $build->getAttribute('size', 0)) ->addMetric("{$function->getInternalId()}" . ".builds.storage", $build->getAttribute('size', 0))
->addMetric("{$function->getId()}" . ".builds.compute", $build->getAttribute('duration', 0)) ->addMetric("{$function->getInternalId()}" . ".builds.compute", $build->getAttribute('duration', 0))
->trigger() ->trigger()
; ;
} }

View file

@ -215,7 +215,7 @@ Server::setResource('execute', function () {
$queueForUsage $queueForUsage
->setProject($project) ->setProject($project)
->addMetric('executions.compute', (int)($execution->getAttribute('duration') * 1000))// per project ->addMetric('executions.compute', (int)($execution->getAttribute('duration') * 1000))// per project
->addMetric("{$function->getId()}" . ".executions.compute", (int)($execution->getAttribute('duration') * 1000))// per function ->addMetric("{$function->getInternalId()}" . ".executions.compute", (int)($execution->getAttribute('duration') * 1000))// per function
->trigger() ->trigger()
; ;
}; };