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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ OPR_PROXY_WORKER_PER_CORE=6
OPR_PROXY_EXECUTORS=mockoon1,mockoon2
OPR_PROXY_HEALTHCHECK=enabled
OPR_PROXY_HEALTHCHECK_INTERVAL=5000
OPR_PROXY_HEALTHCHECK_URL=
OPR_PROXY_MAX_TIMEOUT=600
OPR_PROXY_ENV=development
OPR_PROXY_SECRET=proxy-secret-key
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ services:
- OPR_PROXY_LOGGING_PROVIDER
- OPR_PROXY_LOGGING_CONFIG
- OPR_PROXY_HEALTHCHECK
- OPR_PROXY_HEALTHCHECK_URL
whoami1:
hostname: whoami1
image: containous/whoami
Expand All @@ -73,6 +74,7 @@ OPR_PROXY_EXECUTORS=whoami1,whoami2
OPR_PROXY_HEALTHCHECK=disabled
OPR_PROXY_SECRET=proxy-secret-key
OPR_PROXY_HEALTHCHECK_INTERVAL=5000
OPR_PROXY_HEALTHCHECK_URL=
OPR_PROXY_ENV=development
OPR_PROXY_EXECUTOR_SECRET=executor-secret-key
OPR_PROXY_LOGGING_PROVIDER=
Expand Down Expand Up @@ -112,6 +114,7 @@ docker compose down
| OPR_PROXY_EXECUTORS | Comma-separated hostnames of servers under the proxy. |
| OPR_PROXY_HEALTHCHECK | Health check by HTTP request to /v1/health. 'enabled' by default. To disable, set to 'disabled'. |
| OPR_PROXY_HEALTHCHECK_INTERVAL | Delay in milliseconds between health checks. 10000 by default. Only relevant if OPR_PROXY_HEALTHCHECK is 'enabled'. |
| OPR_PROXY_HEALTHCHECK_URL | URL to send health check request to. Only relevant if OPR_PROXY_HEALTHCHECK is 'enabled'. |
| OPR_PROXY_MAX_TIMEOUT | Maximum timeout in seconds for communication between proxy and executor. Default is 600 seconds. |
| OPR_PROXY_ENV | Runtime environment. 'production' or 'development'. Development may expose debug information and is not recommended on production server. |
| OPR_PROXY_SECRET | Secret that needs to be provided in `Authroization` header when communicating with the to proxy. |
Expand Down
11 changes: 11 additions & 0 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Utopia\Balancer\Group;
use Utopia\Balancer\Option;
use Utopia\CLI\Console;
use Utopia\Fetch\Client;
use Utopia\Registry\Registry;
use Utopia\Swoole\Request;
use Utopia\Swoole\Response;
Expand Down Expand Up @@ -184,6 +185,8 @@ function healthCheck(bool $forceShowError = false): void
->run()
->getNodes();

$healthy = true;

foreach ($nodes as $node) {
$status = $node->isOnline() ? 'online' : 'offline';
$hostname = $node->getHostname();
Expand All @@ -198,12 +201,20 @@ function healthCheck(bool $forceShowError = false): void
}
}

if ($status === 'offline') {
$healthy = false;
}

$state->set($node->getHostname(), [
'status' => $status,
'hostname' => $hostname,
'state' => \json_encode($node->getState())
]);
}

if (App::getEnv('OPR_PROXY_HEALTHCHECK_URL', '') !== '' && $healthy) {
Client::fetch(App::getEnv('OPR_PROXY_HEALTHCHECK_URL', '') ?? '');
}
}

function logError(Throwable $error, string $action, ?Logger $logger, Utopia\Route $route = null): void
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"utopia-php/registry": "0.6.*",
"utopia-php/cli": "0.13.*",
"utopia-php/logger": "0.3.*",
"utopia-php/balancer": "0.4.*"
"utopia-php/balancer": "0.4.*",
"utopia-php/fetch": "^0.1.0"
},
"require-dev": {
"swoole/ide-helper": "4.8.5",
Expand All @@ -42,4 +43,4 @@
"php": "8.0"
}
}
}
}
Loading