Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ OPR_EXECUTOR_MAINTENANCE_INTERVAL=60
OPR_EXECUTOR_NETWORK=executor_runtimes
OPR_EXECUTOR_IMAGE=executor-local
OPR_EXECUTOR_SECRET=executor-secret-key
OPR_EXECUTOR_LOGGING_PROVIDER=
OPR_EXECUTOR_LOGGING_CONFIG=
OPR_EXECUTOR_LOGGING_IDENTIFIER=
OPR_EXECUTOR_DOCKER_HUB_USERNAME=
OPR_EXECUTOR_DOCKER_HUB_PASSWORD=
OPR_EXECUTOR_RUNTIME_VERSIONS=v2,v5
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ services:
- OPR_EXECUTOR_MAINTENANCE_INTERVAL
- OPR_EXECUTOR_NETWORK
- OPR_EXECUTOR_SECRET
- OPR_EXECUTOR_LOGGING_PROVIDER
- OPR_EXECUTOR_LOGGING_CONFIG
- OPR_EXECUTOR_DOCKER_HUB_USERNAME
- OPR_EXECUTOR_DOCKER_HUB_PASSWORD
- OPR_EXECUTOR_RUNTIME_VERSIONS
Expand Down Expand Up @@ -85,9 +83,6 @@ OPR_EXECUTOR_INACTIVE_THRESHOLD=60
OPR_EXECUTOR_MAINTENANCE_INTERVAL=60
OPR_EXECUTOR_NETWORK=openruntimes-runtimes
OPR_EXECUTOR_SECRET=executor-secret-key
OPR_EXECUTOR_LOGGING_PROVIDER=
OPR_EXECUTOR_LOGGING_CONFIG=
OPR_EXECUTOR_LOGGING_IDENTIFIER=
OPR_EXECUTOR_DOCKER_HUB_USERNAME=
OPR_EXECUTOR_DOCKER_HUB_PASSWORD=
OPR_EXECUTOR_RUNTIME_VERSIONS=v5
Expand Down Expand Up @@ -197,8 +192,6 @@ docker compose down
| OPR_EXECUTOR_MAINTENANCE_INTERVAL| Interval (in seconds) at which the Executor performs maintenance tasks, ex: `60` |
| OPR_EXECUTOR_NETWORK | Network used by the executor for runtimes, ex: `openruntimes-runtimes` |
| OPR_EXECUTOR_SECRET | Secret key used by the executor for authentication |
| OPR_EXECUTOR_LOGGING_PROVIDER | Deprecated: use `OPR_EXECUTOR_LOGGING_CONFIG` with DSN instead. External logging provider used by the executor, ex: `sentry` |
| OPR_EXECUTOR_LOGGING_CONFIG | External logging provider DSN used by the executor, ex: `sentry://PROJECT_ID:SENTRY_API_KEY@SENTRY_HOST/` |
| OPR_EXECUTOR_DOCKER_HUB_USERNAME | Username for Docker Hub authentication (if applicable) |
| OPR_EXECUTOR_DOCKER_HUB_PASSWORD | Password for Docker Hub authentication (if applicable) |
| OPR_EXECUTOR_RUNTIME_VERSIONS | Version tag for runtime environments, ex: `v5` |
Expand Down
19 changes: 6 additions & 13 deletions app/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use OpenRuntimes\Executor\Exception;
use OpenRuntimes\Executor\BodyMultipart;
use OpenRuntimes\Executor\Runner\Adapter as Runner;
use Utopia\Logger\Log;
use Utopia\System\System;
use Utopia\Http\Http;
use Utopia\Http\Request;
Expand All @@ -25,15 +24,14 @@
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
->param('timeout', '600', new Text(16), 'Maximum logs timeout.', true)
->inject('response')
->inject('log')
->inject('runner')
->action(function (string $runtimeId, string $timeoutStr, Response $response, Log $log, Runner $runner) {
->action(function (string $runtimeId, string $timeoutStr, Response $response, Runner $runner) {
$timeout = \intval($timeoutStr);

$response->sendHeader('Content-Type', 'text/event-stream');
$response->sendHeader('Cache-Control', 'no-cache');

$runner->getLogs($runtimeId, $timeout, $response, $log);
$runner->getLogs($runtimeId, $timeout, $response);

$response->end();
});
Expand Down Expand Up @@ -69,9 +67,8 @@
->param('version', 'v5', new WhiteList(\explode(',', System::getEnv('OPR_EXECUTOR_RUNTIME_VERSIONS', 'v5') ?? 'v5')), 'Runtime Open Runtime version.', true)
->param('restartPolicy', DockerAPI::RESTART_NO, new WhiteList([DockerAPI::RESTART_NO, DockerAPI::RESTART_ALWAYS, DockerAPI::RESTART_ON_FAILURE, DockerAPI::RESTART_UNLESS_STOPPED], true), 'Define restart policy for the runtime once an exit code is returned. Default value is "no". Possible values are "no", "always", "on-failure", "unless-stopped".', true)
->inject('response')
->inject('log')
->inject('runner')
->action(function (string $runtimeId, string $image, string $entrypoint, string $source, string $destination, string $outputDirectory, array $variables, string $runtimeEntrypoint, string $command, int $timeout, bool $remove, float $cpus, int $memory, string $version, string $restartPolicy, Response $response, Log $log, Runner $runner) {
->action(function (string $runtimeId, string $image, string $entrypoint, string $source, string $destination, string $outputDirectory, array $variables, string $runtimeEntrypoint, string $command, int $timeout, bool $remove, float $cpus, int $memory, string $version, string $restartPolicy, Response $response, Runner $runner) {
$secret = \bin2hex(\random_bytes(16));

/**
Expand Down Expand Up @@ -105,7 +102,7 @@

$variables = array_map(fn ($v) => strval($v), $variables);

$container = $runner->createRuntime($runtimeId, $secret, $image, $entrypoint, $source, $destination, $variables, $runtimeEntrypoint, $command, $timeout, $remove, $cpus, $memory, $version, $restartPolicy, $log);
$container = $runner->createRuntime($runtimeId, $secret, $image, $entrypoint, $source, $destination, $variables, $runtimeEntrypoint, $command, $timeout, $remove, $cpus, $memory, $version, $restartPolicy);
$response->setStatusCode(Response::STATUS_CODE_CREATED)->json($container);
});

Expand Down Expand Up @@ -134,10 +131,9 @@
->desc('Delete a runtime')
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
->inject('response')
->inject('log')
->inject('runner')
->action(function (string $runtimeId, Response $response, Log $log, Runner $runner) {
$runner->deleteRuntime($runtimeId, $log);
->action(function (string $runtimeId, Response $response, Runner $runner) {
$runner->deleteRuntime($runtimeId);
$response->setStatusCode(Response::STATUS_CODE_OK)->send();
});

Expand Down Expand Up @@ -165,7 +161,6 @@
->param('restartPolicy', DockerAPI::RESTART_NO, new WhiteList([DockerAPI::RESTART_NO, DockerAPI::RESTART_ALWAYS, DockerAPI::RESTART_ON_FAILURE, DockerAPI::RESTART_UNLESS_STOPPED], true), 'Define restart policy once exit code is returned by command. Default value is "no". Possible values are "no", "always", "on-failure", "unless-stopped".', true)
->inject('response')
->inject('request')
->inject('log')
->inject('runner')
->action(
function (
Expand All @@ -187,7 +182,6 @@ function (
string $restartPolicy,
Response $response,
Request $request,
Log $log,
Runner $runner
) {
// Extra parsers and validators to support both JSON and multipart
Expand Down Expand Up @@ -258,7 +252,6 @@ function (
$runtimeEntrypoint,
$logging,
$restartPolicy,
$log
);

// Backwards compatibility for headers
Expand Down
43 changes: 1 addition & 42 deletions app/error.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,14 @@
<?php

use OpenRuntimes\Executor\Exception;
use Utopia\Console;
use Utopia\Http\Http;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
use Utopia\Http\Response;
use Utopia\System\System;

function logError(Log $log, Throwable $error, ?Logger $logger = null): void
{
Console::error('[Error] Type: ' . get_class($error));
Console::error('[Error] Message: ' . $error->getMessage());
Console::error('[Error] File: ' . $error->getFile());
Console::error('[Error] Line: ' . $error->getLine());

if ($logger === null) {
return;
}

// Log everything, except those explicitly marked as not loggable
if ($error instanceof Exception && !$error->isPublishable()) {
return;
}

try {
$log->setType(Log::TYPE_ERROR);
$log->setMessage($error->getMessage());
$log->setAction("httpError");
$log->addTag('code', \strval($error->getCode()));
$log->addTag('verboseType', get_class($error));
$log->addExtra('file', $error->getFile());
$log->addExtra('line', $error->getLine());
$log->addExtra('trace', $error->getTraceAsString());

$status = $logger->addLog($log);

Console::info("Pushed log with response status code: $status");
} catch (\Throwable $e) {
Console::error("Failed to push log: {$e->getMessage()}");
}
}

Http::error()
->inject('error')
->inject('logger')
->inject('response')
->inject('log')
->action(function (Throwable $error, ?Logger $logger, Response $response, Log $log) {
logError($log, $error, $logger);

->action(function (Throwable $error, Response $response) {
// Show all Executor\Exceptions, or everything if in development
$public = $error instanceof Exception || Http::isDevelopment();
$exception = $public ? $error : new Exception(Exception::GENERAL_UNKNOWN);
Expand Down
79 changes: 0 additions & 79 deletions app/init.php
Original file line number Diff line number Diff line change
@@ -1,87 +1,8 @@
<?php

use Utopia\Config\Config;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
use Utopia\Logger\Adapter\AppSignal;
use Utopia\Logger\Adapter\LogOwl;
use Utopia\Logger\Adapter\Raygun;
use Utopia\Logger\Adapter\Sentry;
use Utopia\DSN\DSN;
use Utopia\Http\Http;
use Utopia\Http\Route;
use Utopia\Registry\Registry;
use Utopia\System\System;

const MAX_LOG_SIZE = 5 * 1024 * 1024;
const MAX_BUILD_LOG_SIZE = 1 * 1000 * 1000;

Config::load('errors', __DIR__ . '/config/errors.php');

// Setup Registry
$register = new Registry();

$register->set('logger', function () {
$providerName = System::getEnv('OPR_EXECUTOR_LOGGING_PROVIDER', '');
$providerConfig = System::getEnv('OPR_EXECUTOR_LOGGING_CONFIG', '');

try {
$loggingProvider = new DSN($providerConfig ?? '');

$providerName = $loggingProvider->getScheme();
$providerConfig = match ($providerName) {
'sentry' => ['key' => $loggingProvider->getPassword(), 'projectId' => $loggingProvider->getUser() ?? '', 'host' => 'https://' . $loggingProvider->getHost()],
'logowl' => ['ticket' => $loggingProvider->getUser() ?? '', 'host' => $loggingProvider->getHost()],
default => ['key' => $loggingProvider->getHost()],
};
} catch (Throwable) {
$configChunks = \explode(";", ($providerConfig ?? ''));

$providerConfig = match ($providerName) {
'sentry' => ['key' => $configChunks[0], 'projectId' => $configChunks[1] ?? '', 'host' => '',],
'logowl' => ['ticket' => $configChunks[0] ?? '', 'host' => ''],
default => ['key' => $providerConfig],
};
}

$logger = null;

if (!empty($providerName) && is_array($providerConfig) && Logger::hasProvider($providerName)) {
$adapter = match ($providerName) {
'sentry' => new Sentry($providerConfig['projectId'] ?? '', $providerConfig['key'] ?? '', $providerConfig['host'] ?? ''),
'logowl' => new LogOwl($providerConfig['ticket'] ?? '', $providerConfig['host'] ?? ''),
'raygun' => new Raygun($providerConfig['key'] ?? ''),
'appsignal' => new AppSignal($providerConfig['key'] ?? ''),
default => throw new Exception('Provider "' . $providerName . '" not supported.')
};

$logger = new Logger($adapter);
}

return $logger;
});

/** Resources */
Http::setResource('log', function (?Route $route) {
$log = new Log();

$log->setNamespace("executor");
$log->setEnvironment(Http::isProduction() ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING);

$version = (string) System::getEnv('OPR_EXECUTOR_VERSION', 'UNKNOWN');
$log->setVersion($version);

$server = System::getEnv('OPR_EXECUTOR_LOGGING_IDENTIFIER', \gethostname() ?: 'UNKNOWN');
$log->setServer($server);

if ($route) {
$log->addTag('method', $route->getMethod());
$log->addTag('url', $route->getPath());
}

return $log;
}, ['route']);

Http::setResource('register', fn () => $register);

Http::setResource('logger', fn (Registry $register) => $register->get('logger'), ['register']);
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"utopia-php/dsn": "0.2.*",
"utopia-php/fetch": "0.4.*",
"utopia-php/framework": "0.34.*",
"utopia-php/logger": "0.6.*",
"utopia-php/orchestration": "0.19.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/registry": "0.5.*",
Expand Down
56 changes: 1 addition & 55 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ services:
- OPR_EXECUTOR_MAINTENANCE_INTERVAL
- OPR_EXECUTOR_NETWORK
- OPR_EXECUTOR_SECRET
- OPR_EXECUTOR_LOGGING_PROVIDER
- OPR_EXECUTOR_LOGGING_CONFIG
- OPR_EXECUTOR_DOCKER_HUB_USERNAME
- OPR_EXECUTOR_DOCKER_HUB_PASSWORD
- OPR_EXECUTOR_RUNTIME_VERSIONS
Expand Down
Loading