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: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ 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
OPR_EXECUTOR_RETRY_ATTEMPTS=5
OPR_EXECUTOR_RETRY_DELAY_MS=500
OPR_EXECUTOR_RETRY_DELAY_MS=500
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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 All @@ -97,7 +98,7 @@ OPR_EXECUTOR_RETRY_DELAY_MS=500

> `OPR_EXECUTOR_CONNECTION_STORAGE` takes a DSN string that represents a connection to your storage device. If you would like to use your local filesystem, you can use `file://localhost`. If using S3 or any other provider for storage, use a DSN of the following format `s3://access_key:access_secret@host:port/bucket_name?region=us-east-1`

> For backwards compatibility, executor also supports `OPR_EXECUTOR_STORAGE_*` variables as replacement for `OPR_EXECUTOR_CONNECTION_STORAGE`, as seen in [Appwrite repository](https://github.com/appwrite/appwrite/blob/1.3.8/.env#L26-L46).
> For backwards compatibility, executor also supports `OPR_EXECUTOR_STORAGE_*` variables as replacement for `OPR_EXECUTOR_CONNECTION_STORAGE`, as seen in [Appwrite repository](https://github.com/appwrite/appwrite/blob/1.3.8/.env#L26-L46).

4. Start Docker container:

Expand Down Expand Up @@ -130,7 +131,7 @@ docker compose down

## API Endpoints

| Method | Endpoint | Description | Params |
| Method | Endpoint | Description | Params |
|--------|----------|-------------| ------ |
| GET |`/v1/runtimes/{runtimeId}/logs`| Get live stream of logs of a runtime | [JSON](#v1runtimesruntimeidlogs) |
| POST |`/v1/runtimes`| Create a new runtime server | [JSON](#v1runtimes) |
Expand All @@ -148,7 +149,7 @@ docker compose down

#### /v1/runtimes
| Param | Type | Description | Required | Default |
|-------|------|-------------|----------|---------|
|-------|------|-------------|----------|---------|
| `runtimeId` | `string` | Runtime unique ID | ✅ | |
| `image` | `string` | Base image name of the runtime | ✅ | |
| `entrypoint` | `string` | Entrypoint of the code file | | ' ' |
Expand Down
27 changes: 4 additions & 23 deletions app/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Route;
use Utopia\Http\Validator\AnyOf;
use Utopia\Http\Validator\Assoc;
use Utopia\Http\Validator\Boolean;
Expand All @@ -21,29 +20,17 @@
use Utopia\Http\Validator\WhiteList;
use Utopia\Orchestration\Adapter\DockerAPI;

function logError(Log $log, Throwable $error, string $action, Logger $logger = null, Route $route = null): void
function logError(Log $log, Throwable $error, string $action, 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 && ($error->getCode() === 500 || $error->getCode() === 0)) {
$version = (string)Http::getEnv('OPR_EXECUTOR_VERSION', '');
if (empty($version)) {
$version = 'UNKNOWN';
}

$log->setNamespace("executor");
$log->setServer(\gethostname() !== false ? \gethostname() : null);
$log->setVersion($version);
$log->setType(Log::TYPE_ERROR);
$log->setMessage($error->getMessage());

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

$log->addTag('code', \strval($error->getCode()));
$log->addTag('verboseType', get_class($error));
Expand All @@ -54,16 +41,11 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
// TODO: @Meldiron Uncomment, was warning: Undefined array key "file" in Sentry.php on line 68
// $log->addExtra('detailedTrace', $error->getTrace());

$log->setAction($action);

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

$responseCode = $logger->addLog($log);
Console::info('Executor log pushed with status code: ' . $responseCode);
}
}


Http::get('/v1/runtimes/:runtimeId/logs')
->groups(['api'])
->desc("Get live stream of logs of a runtime")
Expand Down Expand Up @@ -360,14 +342,13 @@ function (

/** Set callbacks */
Http::error()
->inject('route')
->inject('error')
->inject('logger')
->inject('response')
->inject('log')
->action(function (?Route $route, Throwable $error, ?Logger $logger, Response $response, Log $log) {
->action(function (Throwable $error, ?Logger $logger, Response $response, Log $log) {
try {
logError($log, $error, "httpError", $logger, $route);
logError($log, $error, "httpError", $logger);
} catch (Throwable) {
Console::warning('Unable to send log message');
}
Expand Down
23 changes: 21 additions & 2 deletions app/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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;
Expand Down Expand Up @@ -56,9 +58,26 @@
return $logger;
});


/** Resources */
Http::setResource('log', fn () => new Log());
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);

Expand Down