Skip to content

Commit a0d4e47

Browse files
authored
Merge pull request #9524 from appwrite/feat-deployment-total-size
Feat: totalSize attribute
2 parents 3f1c4c2 + fd4b435 commit a0d4e47

11 files changed

Lines changed: 134 additions & 8 deletions

File tree

.coderabbit.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
reviews:
2+
auto_review:
3+
base_branches:
4+
- main
5+
- 1.6.x
6+
- 1.7.x
7+
- feat-sites # temporary until merged to 1.7.x

app/config/collections/projects.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,17 @@
15501550
'array' => false,
15511551
'filters' => [],
15521552
],
1553+
[
1554+
'$id' => ID::custom('totalSize'),
1555+
'type' => Database::VAR_INTEGER,
1556+
'format' => '',
1557+
'size' => 0,
1558+
'signed' => true,
1559+
'required' => false,
1560+
'default' => null,
1561+
'array' => false,
1562+
'filters' => [],
1563+
],
15531564
[
15541565
'$id' => ID::custom('status'),
15551566
'type' => Database::VAR_STRING,
@@ -1620,6 +1631,13 @@
16201631
'lengths' => [],
16211632
'orders' => [Database::ORDER_ASC],
16221633
],
1634+
[
1635+
'$id' => ID::custom('_key_totalSize'),
1636+
'type' => Database::INDEX_KEY,
1637+
'attributes' => ['totalSize'],
1638+
'lengths' => [],
1639+
'orders' => [Database::ORDER_ASC],
1640+
],
16231641
[
16241642
'$id' => ID::custom('_key_buildDuration'),
16251643
'type' => Database::INDEX_KEY,

src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function action(
234234
'buildCommands' => $commands,
235235
'sourcePath' => $path,
236236
'sourceSize' => $fileSize,
237+
'totalSize' => $fileSize,
237238
'search' => implode(' ', [$deploymentId, $entrypoint]),
238239
'activate' => $activate,
239240
'sourceMetadata' => $metadata,
@@ -264,6 +265,7 @@ public function action(
264265
'buildCommands' => $commands,
265266
'sourcePath' => $path,
266267
'sourceSize' => $fileSize,
268+
'totalSize' => $fileSize,
267269
'sourceChunksTotal' => $chunks,
268270
'sourceChunksUploaded' => $chunksUploaded,
269271
'search' => implode(' ', [$deploymentId, $entrypoint]),

src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function action(
100100
'$internalId' => '',
101101
'$id' => $deploymentId,
102102
'sourcePath' => $destination,
103+
'totalSize' => $deployment->getAttribute('sourceSize', 0),
103104
'entrypoint' => $function->getAttribute('entrypoint'),
104105
'buildCommands' => $function->getAttribute('commands', ''),
105106
'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]),

src/Appwrite/Platform/Modules/Functions/Workers/Builds.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ protected function buildDeployment(Device $deviceForFunctions, Device $deviceFor
285285
$directorySize = $device->getFileSize($source);
286286
$deployment
287287
->setAttribute('sourcePath', $source)
288-
->setAttribute('sourceSize', $directorySize);
288+
->setAttribute('sourceSize', $directorySize)
289+
->setAttribute('totalSize', $directorySize);
289290
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
290291

291292
$queueForRealtime
@@ -436,7 +437,8 @@ protected function buildDeployment(Device $deviceForFunctions, Device $deviceFor
436437

437438
$deployment
438439
->setAttribute('sourcePath', $source)
439-
->setAttribute('sourceSize', $directorySize);
440+
->setAttribute('sourceSize', $directorySize)
441+
->setAttribute('totalSize', $directorySize);
440442
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
441443

442444
$queueForRealtime
@@ -720,6 +722,7 @@ protected function buildDeployment(Device $deviceForFunctions, Device $deviceFor
720722
$deployment->setAttribute('status', 'ready');
721723
$deployment->setAttribute('buildPath', $response['path']);
722724
$deployment->setAttribute('buildSize', $response['size']);
725+
$deployment->setAttribute('totalSize', $deployment->getAttribute('buildSize', 0) + $deployment->getAttribute('sourceSize', 0));
723726

724727
$logs = '';
725728
foreach ($response['output'] as $log) {

src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public function action(
243243
'buildOutput' => $outputDirectory,
244244
'sourcePath' => $path,
245245
'sourceSize' => $fileSize,
246+
'totalSize' => $fileSize,
246247
'search' => implode(' ', [$deploymentId]),
247248
'activate' => $activate,
248249
'sourceMetadata' => $metadata,
@@ -300,6 +301,7 @@ public function action(
300301
'buildOutput' => $outputDirectory,
301302
'sourcePath' => $path,
302303
'sourceSize' => $fileSize,
304+
'totalSize' => $fileSize,
303305
'sourceChunksTotal' => $chunks,
304306
'sourceChunksUploaded' => $chunksUploaded,
305307
'search' => implode(' ', [$deploymentId]),

src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,16 @@ public function action(
111111
'$internalId' => '',
112112
'$id' => $deploymentId,
113113
'sourcePath' => $destination,
114+
'totalSize' => $deployment->getAttribute('sourceSize', 0),
114115
'buildCommands' => \implode(' && ', $commands),
115116
'buildOutput' => $site->getAttribute('outputDirectory', ''),
116117
'search' => implode(' ', [$deploymentId]),
117118
'screenshotLight' => '',
118119
'screenshotDark' => '',
119120
'buildStartAt' => null,
120121
'buildEndAt' => null,
121-
'buildDuration' => null,
122-
'buildSize' => null,
122+
'buildDuration' => 0,
123+
'buildSize' => 0,
123124
'status' => 'waiting',
124125
'buildPath' => '',
125126
'buildLogs' => '',

src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Deployments extends Base
77
public const ALLOWED_ATTRIBUTES = [
88
'buildSize',
99
'sourceSize',
10+
'totalSize',
1011
'buildDuration',
1112
'status',
1213
'activate',

src/Appwrite/Utopia/Response/Model/Deployment.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public function __construct()
6464
'default' => 0,
6565
'example' => 128,
6666
])
67+
->addRule('totalSize', [
68+
'type' => self::TYPE_INTEGER,
69+
'description' => 'The total size in bytes (source and build output).',
70+
'default' => 0,
71+
'example' => 128,
72+
])
6773
->addRule('buildId', [
6874
'type' => self::TYPE_STRING,
6975
'description' => 'The current build ID.',

tests/e2e/Services/Functions/FunctionsCustomServerTest.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ public function testCreateFunctionAndDeploymentFromTemplate()
408408
$this->assertEquals(202, $deployment['headers']['status-code']);
409409
$this->assertNotEmpty($deployment['body']['$id']);
410410

411+
$deployment = $this->getDeployment($functionId, $deployment['body']['$id']);
412+
$this->assertEquals(200, $deployment['headers']['status-code']);
413+
$this->assertEquals(0, $deployment['body']['sourceSize']);
414+
$this->assertEquals(0, $deployment['body']['buildSize']);
415+
$this->assertEquals(0, $deployment['body']['totalSize']);
416+
411417
$deployments = $this->listDeployments($functionId);
412418

413419
$this->assertEquals(200, $deployments['headers']['status-code']);
@@ -480,7 +486,14 @@ public function testCreateFunctionAndDeploymentFromTemplate()
480486
$this->assertStringContainsString("Total users: " . $totalUsers, $execution['body']['logs']);
481487
}, 10000, 500);
482488

483-
$function = $this->deleteFunction($functionId);
489+
$deployment = $this->getDeployment($functionId, $deployment['body']['$id']);
490+
$this->assertEquals(200, $deployment['headers']['status-code']);
491+
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
492+
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
493+
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
494+
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
495+
496+
$function = $this->cleanupFunction($functionId);
484497
}
485498

486499
/**
@@ -1634,11 +1647,14 @@ public function testCookieExecution()
16341647
'entrypoint' => 'index.php',
16351648
'timeout' => 15,
16361649
]);
1637-
$this->setupDeployment($functionId, [
1650+
$this->assertNotEmpty($functionId);
1651+
1652+
$deploymentId = $this->setupDeployment($functionId, [
16381653
'entrypoint' => 'index.php',
16391654
'code' => $this->packageFunction('php-cookie'),
16401655
'activate' => true
16411656
]);
1657+
$this->assertNotEmpty($deploymentId);
16421658

16431659
$cookie = 'cookieName=cookieValue; cookie2=value2; cookie3=value=3; cookie4=val:ue4; cookie5=value5';
16441660
$execution = $this->createExecution($functionId, [
@@ -1654,6 +1670,13 @@ public function testCookieExecution()
16541670
$this->assertEquals($cookie, $execution['body']['responseBody']);
16551671
$this->assertGreaterThan(0, $execution['body']['duration']);
16561672

1673+
$deployment = $this->getDeployment($functionId, $deploymentId);
1674+
$this->assertEquals(200, $deployment['headers']['status-code']);
1675+
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
1676+
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
1677+
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
1678+
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
1679+
16571680
$this->cleanupFunction($functionId);
16581681
}
16591682

@@ -2029,13 +2052,34 @@ public function testDuplicateDeployment(): void
20292052
$this->assertEquals(200, $function['headers']['status-code']);
20302053
$this->assertStringContainsString('maintenance.js', $function['body']['commands']);
20312054

2032-
$deploymentId2 = $this->setupDuplicateDeployment($functionId, $deploymentId1);
2055+
$deployment = $this->createDuplicateDeployment($functionId, $deploymentId1);
2056+
$this->assertEquals(202, $deployment['headers']['status-code']);
2057+
2058+
$deploymentId2 = $deployment['body']['$id'];
20332059
$this->assertNotEmpty($deploymentId2);
20342060

2061+
$deployment = $this->getDeployment($functionId, $deploymentId2);
2062+
$this->assertEquals(200, $deployment['headers']['status-code']);
2063+
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
2064+
$this->assertEquals(0, $deployment['body']['buildSize']);
2065+
$this->assertEquals($deployment['body']['sourceSize'], $deployment['body']['totalSize']);
2066+
2067+
$this->assertEventually(function () use ($functionId, $deploymentId2) {
2068+
$function = $this->getFunction($functionId);
2069+
$this->assertEquals($deploymentId2, $function['body']['deploymentId']);
2070+
}, 50000, 500);
2071+
20352072
$execution = $this->createExecution($functionId);
20362073
$this->assertEquals(201, $execution['headers']['status-code']);
20372074
$this->assertStringContainsString('Maintenance', $execution['body']['responseBody']);
20382075

2076+
$deployment = $this->getDeployment($functionId, $deploymentId2);
2077+
$this->assertEquals(200, $deployment['headers']['status-code']);
2078+
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
2079+
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
2080+
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
2081+
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
2082+
20392083
$this->cleanupFunction($functionId);
20402084
}
20412085

0 commit comments

Comments
 (0)