diff --git a/app/config/runtimes/sizes.php b/app/config/runtimes/sizes.php index 194250b62d..c34b2e30b0 100644 --- a/app/config/runtimes/sizes.php +++ b/app/config/runtimes/sizes.php @@ -11,8 +11,8 @@ return [ 'memory' => 1024, 'cpus' => 1 ], - Sizes::S_2VCPU_1GB->value => [ - 'memory' => 1024, + Sizes::S_2VCPU_2GB->value => [ + 'memory' => 2048, 'cpus' => 2 ], Sizes::S_2VCPU_4GB->value => [ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 2ae97d7fa4..5bc73b20fb 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1828,8 +1828,8 @@ App::post('/v1/functions/:functionId/executions') ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function - ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, $function->getAttribute('memory') * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), $function->getAttribute('memory') * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, $function->getAttribute('memory', 512) * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), $function->getAttribute('memory', 512) * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) ; if ($function->getAttribute('logging')) { diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index ab050c105b..e9604bb50e 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -410,8 +410,8 @@ class Builds extends Action source: $source, image: $runtime['image'], version: $version, - cpus: 2, - memory: 1024, + cpus: $function->getAttribute('cpus', 1), + memory: $function->getAttribute('memory', 512), remove: true, entrypoint: $deployment->getAttribute('entrypoint'), destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}", @@ -542,11 +542,11 @@ class Builds extends Action ->addMetric(METRIC_BUILDS, 1) // per project ->addMetric(METRIC_BUILDS_STORAGE, $build->getAttribute('size', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$build->getAttribute('duration', 0) * 1000) - ->addMetric(METRIC_BUILDS_MB_SECONDS, $function->getAttribute('memory') * $build->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(METRIC_BUILDS_MB_SECONDS, $function->getAttribute('memory', 512) * $build->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS), 1) // per function ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS), $function->getAttribute('memory') * $build->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_MB_SECONDS), $function->getAttribute('memory', 512) * $build->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) ->setProject($project) ->trigger(); } diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 14a97e675a..a2a6b6d47d 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -509,8 +509,8 @@ class Functions extends Action ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000))// per project ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) - ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, $function->getAttribute('memory') * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), $function->getAttribute('memory') * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, $function->getAttribute('memory', 512) * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_MB_SECONDS), $function->getAttribute('memory', 512) * $execution->getAttribute('duration', 0) * $function->getAttribute('cpus', 1)) ->trigger() ; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 4093ac5795..58f44b3506 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -400,7 +400,6 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.name', 'users.*.update.email', ], - 'schedule' => '0 0 1 1 *', 'timeout' => 15, 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', @@ -418,7 +417,6 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.name', 'users.*.update.email', ], $response1['body']['events']); - $this->assertEquals('0 0 1 1 *', $response1['body']['schedule']); $this->assertEquals(15, $response1['body']['timeout']); $this->assertEquals(1024, $response1['body']['memory']); $this->assertEquals(1, $response1['body']['cpus']); @@ -436,7 +434,6 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.name', 'users.*.update.email', ], - 'schedule' => '0 0 1 1 *', 'timeout' => 15, 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', @@ -444,6 +441,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(400, $response2['headers']['status-code']); + $this->assertEquals('Invalid `size` param: String must be a valid size value of s-1vcpu-512mb, s-1vcpu-1gb', $response2['body']['message']); return $data; }