diff options
| author | fox <fox@fakecake.org> | 2026-10-14 21:41:11 +0300 |
|---|---|---|
| committer | GitLab <noreply@fakecake.org> | 2026-10-14 21:41:11 +0300 |
| commit | fa0e418228ec4ff79ef4b2024beb2491e15d538e (patch) | |
| tree | 906546542b5df2689ee6a0c16b889df82f947580 /classes/Handler/HealthzHandler.php | |
| parent | c0135cc03916ad22707064e8957dce3f8e067a5d (diff) | |
| parent | 48d7b08a87adec0ce1c114bd5c70c0f6e108a954 (diff) | |
| download | the-epube-fa0e418228ec4ff79ef4b2024beb2491e15d538e.tar.gz the-epube-fa0e418228ec4ff79ef4b2024beb2491e15d538e.tar.xz | |
Merge branch 'dev' into 'master'
Dev See merge request git/the-epube!77
Diffstat (limited to 'classes/Handler/HealthzHandler.php')
| -rw-r--r-- | classes/Handler/HealthzHandler.php | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/classes/Handler/HealthzHandler.php b/classes/Handler/HealthzHandler.php index 722422c..f12649b 100644 --- a/classes/Handler/HealthzHandler.php +++ b/classes/Handler/HealthzHandler.php @@ -9,38 +9,40 @@ use Request; use RequestHandlerInterface; use Response; +/** + * Public k8s healthcheck endpoint. Intentionally does NOT implement + * AuthRequired. Because it is unauthenticated, it must not leak any + * internals (DSNs, paths, driver errors) — failure details go to the + * PHP error log, the HTTP response only carries 200/503. + */ class HealthzHandler implements RequestHandlerInterface { public function handle(Request $request): Response { - $status = "ok"; - $errors = []; + $healthy = true; // Test Calibre SQLite database try { $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB)); $caldb->query("SELECT 1 FROM books LIMIT 1"); } catch (\PDOException $e) { - $status = "degraded"; - $errors["calibre_db"] = "Connection failed: " . $e->getMessage(); + $healthy = false; + error_log("healthz: calibre db check failed: " . $e->getMessage()); } // Test main database (via ORM/Db) try { Db::pdo()->query("SELECT 1"); } catch (\PDOException $e) { - $status = "degraded"; - $errors["main_db"] = "Connection failed: " . $e->getMessage(); + $healthy = false; + error_log("healthz: main db check failed: " . $e->getMessage()); } $response = (new Response()) ->withHeader("Content-Type", "application/json") - ->withBody(json_encode([ - "status" => $status, - "errors" => $errors, - ])); + ->withBody(json_encode(["status" => $healthy ? "ok" : "error"])); - if ($status === "degraded") { + if (!$healthy) { $response = $response->withStatus(503); } |
