From a4b31f64726572a4ebfe1bd0405490cffa162018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 15 Mar 2023 09:20:25 +0100 Subject: [PATCH] Fix after merge --- app/config/collections.php | 15 +++- app/controllers/api/functions.php | 2 +- app/workers/builds.php | 12 +-- app/workers/deletes.php | 12 +-- app/workers/functions.php | 2 +- composer.lock | 89 +++++++++++++++++++- src/Appwrite/Migration/Version/V17.php | 12 +++ src/Appwrite/Usage/Stats.php | 2 + src/Appwrite/Utopia/Response/Model/Build.php | 6 ++ 9 files changed, 135 insertions(+), 17 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index d042dd17c1..454ed006eb 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2695,7 +2695,18 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deploymentInternalId', + '$id' => ID::custom('size'), + 'type' => Database::VAR_INTEGER, + 'format' => '', + 'size' => 0, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('deploymentInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2739,7 +2750,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => ID::custom('outputPath'), + '$id' => ID::custom('path'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 93db930783..74a2865043 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1311,7 +1311,7 @@ App::post('/v1/functions/:functionId/executions') variables: $vars, timeout: $function->getAttribute('timeout', 0), image: $runtime['image'], - source: $build->getAttribute('outputPath', ''), + source: $build->getAttribute('path', ''), entrypoint: $deployment->getAttribute('entrypoint', ''), path: $path, method: $method, diff --git a/app/workers/builds.php b/app/workers/builds.php index ddaf4f1b6d..b3a9974c92 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -100,14 +100,15 @@ class BuildsV1 extends Worker 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'status' => 'processing', - 'outputPath' => '', + 'path' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path'), 'sourceType' => $device, 'stdout' => '', 'stderr' => '', 'endTime' => null, - 'duration' => 0 + 'duration' => 0, + 'size' => 0 ])); $deployment->setAttribute('buildId', $build->getId()); $deployment->setAttribute('buildInternalId', $build->getInternalId()); @@ -189,15 +190,14 @@ class BuildsV1 extends Worker ] ); - $endTime = new \DateTime(); - $endTime->setTimestamp($response['endTimeUnix']); + $endTime = DateTime::now(); /** Update the build document */ $build->setAttribute('startTime', DateTime::format((new \DateTime())->setTimestamp($response['startTime']))); - $build->setAttribute('endTime', DateTime::format($endTime)); + $build->setAttribute('endTime', $endTime); $build->setAttribute('duration', \intval(\ceil($response['duration']))); $build->setAttribute('status', 'ready'); - $build->setAttribute('outputPath', $response['path']); + $build->setAttribute('path', $response['path']); $build->setAttribute('size', $response['size']); $build->setAttribute('stderr', $response['stderr']); $build->setAttribute('stdout', $response['stdout']); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index f296231187..904824b596 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -501,10 +501,10 @@ class DeletesV1 extends Worker $this->deleteByGroup('builds', [ Query::equal('deploymentId', [$deploymentId]) ], $dbForProject, function (Document $document) use ($storageBuilds, $deploymentId) { - if ($storageBuilds->delete($document->getAttribute('outputPath', ''), true)) { - Console::success('Deleted build files: ' . $document->getAttribute('outputPath', '')); + if ($storageBuilds->delete($document->getAttribute('path', ''), true)) { + Console::success('Deleted build files: ' . $document->getAttribute('path', '')); } else { - Console::error('Failed to delete build files: ' . $document->getAttribute('outputPath', '')); + Console::error('Failed to delete build files: ' . $document->getAttribute('path', '')); } }); } @@ -554,10 +554,10 @@ class DeletesV1 extends Worker $this->deleteByGroup('builds', [ Query::equal('deploymentId', [$deploymentId]) ], $dbForProject, function (Document $document) use ($storageBuilds) { - if ($storageBuilds->delete($document->getAttribute('outputPath', ''), true)) { - Console::success('Deleted build files: ' . $document->getAttribute('outputPath', '')); + if ($storageBuilds->delete($document->getAttribute('path', ''), true)) { + Console::success('Deleted build files: ' . $document->getAttribute('path', '')); } else { - Console::error('Failed to delete build files: ' . $document->getAttribute('outputPath', '')); + Console::error('Failed to delete build files: ' . $document->getAttribute('path', '')); } }); diff --git a/app/workers/functions.php b/app/workers/functions.php index a1c924b72d..2a1894baa7 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -173,7 +173,7 @@ Server::setResource('execute', function () { variables: $vars, timeout: $function->getAttribute('timeout', 0), image: $runtime['image'], - source: $build->getAttribute('outputPath', ''), + source: $build->getAttribute('path', ''), entrypoint: $deployment->getAttribute('entrypoint', ''), path: $path, method: $method, diff --git a/composer.lock b/composer.lock index 24fb668be4..4bdf4a404d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e8e64d67c559b26264b6a89ebab1ab72", + "content-hash": "d388807afe22fb473b5136a75cb3d7e7", "packages": [ { "name": "adhocore/jwt", @@ -870,6 +870,93 @@ }, "time": "2022-11-29T16:25:20+00:00" }, + { + "name": "league/csv", + "version": "9.9.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "b4418ede47fbd88facc34e40a16c8ce9153b961b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/b4418ede47fbd88facc34e40a16c8ce9153b961b", + "reference": "b4418ede47fbd88facc34e40a16c8ce9153b961b", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.1.2" + }, + "require-dev": { + "doctrine/collections": "^2.1.2", + "ext-dom": "*", + "ext-xdebug": "*", + "friendsofphp/php-cs-fixer": "^v3.14.3", + "phpbench/phpbench": "^1.2.8", + "phpstan/phpstan": "^1.10.4", + "phpstan/phpstan-deprecation-rules": "^1.1.2", + "phpstan/phpstan-phpunit": "^1.3.10", + "phpstan/phpstan-strict-rules": "^1.5.0", + "phpunit/phpunit": "^10.0.14" + }, + "suggest": { + "ext-dom": "Required to use the XMLConverter and the HTMLConverter classes", + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "League\\Csv\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "CSV data manipulation made easy in PHP", + "homepage": "https://csv.thephpleague.com", + "keywords": [ + "convert", + "csv", + "export", + "filter", + "import", + "read", + "transform", + "write" + ], + "support": { + "docs": "https://csv.thephpleague.com", + "issues": "https://github.com/thephpleague/csv/issues", + "rss": "https://github.com/thephpleague/csv/releases.atom", + "source": "https://github.com/thephpleague/csv" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2023-03-11T15:57:12+00:00" + }, { "name": "matomo/device-detector", "version": "6.0.0", diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index c96c9e08a4..dac6b740c6 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -46,6 +46,18 @@ class V17 extends Migration $this->projectDB->setNamespace("_{$this->project->getInternalId()}"); switch ($id) { + case 'builds': + try { + /** + * Create 'size' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'size'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'size' from {$id}: {$th->getMessage()}"); + } + + break; case 'files': try { /** diff --git a/src/Appwrite/Usage/Stats.php b/src/Appwrite/Usage/Stats.php index e6e0056664..38fdc123cf 100644 --- a/src/Appwrite/Usage/Stats.php +++ b/src/Appwrite/Usage/Stats.php @@ -184,6 +184,7 @@ class Stats $functionBuild = $this->params['builds.{scope}.compute'] ?? 0; $functionBuildTime = ($this->params['buildTime'] ?? 0) * 1000; // ms + $functionBuildSize = ($this->params['buildSize'] ?? 0); // bytes $functionBuildStatus = $this->params['buildStatus'] ?? ''; $functionCompute = $functionExecutionTime + $functionBuildTime; $functionTags = $tags . ',functionId=' . $functionId; @@ -207,6 +208,7 @@ class Stats if ($functionBuild >= 1) { $this->statsd->increment('builds.{scope}.compute' . $functionTags . ',functionBuildStatus=' . $functionBuildStatus); $this->statsd->count('builds.{scope}.compute.time' . $functionTags, $functionBuildTime); + $this->statsd->count('builds.{scope}.storage.size' . $functionTags, $functionBuildSize); } if ($functionBuild + $functionExecution >= 1) { $this->statsd->count('project.{scope}.compute.time' . $functionTags, $functionCompute); diff --git a/src/Appwrite/Utopia/Response/Model/Build.php b/src/Appwrite/Utopia/Response/Model/Build.php index b76f0ee083..d80c17645a 100644 --- a/src/Appwrite/Utopia/Response/Model/Build.php +++ b/src/Appwrite/Utopia/Response/Model/Build.php @@ -63,6 +63,12 @@ class Build extends Model 'default' => 0, 'example' => 0, ]) + ->addRule('size', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'The code size in bytes.', + 'default' => 0, + 'example' => 128, + ]) ; }