diff --git a/app/http.php b/app/http.php index 6d862c38..ddd35256 100644 --- a/app/http.php +++ b/app/http.php @@ -591,8 +591,7 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st // No error if ($errNo === 0) { - // TODO: @Meldiron This shoudl retry as well - if ($statusCode >= 400) { + if ($statusCode >= 400 && $i === 4) { $body = \json_decode($error, true); throw new Exception('An internal curl error has occurred while starting runtime! Error Msg: ' . ($body['message'] ?? $error), 500); } @@ -767,10 +766,10 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st batch([ function () use (&$output) { - $output['hostUsage'] = System::getCPUUsage(5); + $output['usage'] = System::getCPUUsage(5); }, function () use (&$output, $orchestration) { - $functionsUsage = []; + $runtimes = []; $containerUsages = $orchestration->getStats( filters: [ 'label' => 'openruntimes-executor=' . System::getHostname() ], @@ -778,10 +777,16 @@ function () use (&$output, $orchestration) { ); foreach ($containerUsages as $containerUsage) { - $functionsUsage[$containerUsage['name']] = $containerUsage['cpu'] * 100; + $hostnameArr = \explode('-', $containerUsage['name']); + \array_shift($hostnameArr); + $hostname = \implode('-', $hostnameArr); + $runtimes[$hostname] = [ + 'status' => 'pass', + 'usage' => $containerUsage['cpu'] * 100 + ]; } - $output['functionsUsage'] = $functionsUsage; + $output['runtimes'] = $runtimes; } ]); diff --git a/tests/ExecutorTest.php b/tests/ExecutorTest.php index bc16c097..c4077ed1 100644 --- a/tests/ExecutorTest.php +++ b/tests/ExecutorTest.php @@ -6,6 +6,7 @@ use Utopia\CLI\Console; // TODO: @Meldiron Write more tests (validators mainly) +// TODO: @Meldiron Health API tests final class ExecutorTest extends TestCase {