diff --git a/CHANGELOG.md b/CHANGELOG.md index 682a64374..37693a575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - - #1933, Add a minimal health check endpoint on an admin port at the `:/health` endpoint - @steve-chavez + - #1933, #2109, Add a minimal health check endpoint - @steve-chavez + For enabling this, the `admin-server-port` config must be set explictly + + The check is at the `:/ready` endpoint ### Fixed diff --git a/src/PostgREST/Admin.hs b/src/PostgREST/Admin.hs index acae273b2..24622d952 100644 --- a/src/PostgREST/Admin.hs +++ b/src/PostgREST/Admin.hs @@ -24,7 +24,7 @@ postgrestAdmin appState appConfig req respond = do isMainAppReachable <- isRight <$> reachMainApp appConfig case Wai.pathInfo req of - ["health"] -> + ["ready"] -> if configDbChannelEnabled appConfig then do listenerOn <- AppState.getIsListenerOn appState respond $ Wai.responseLBS (if listenerOn && isMainAppReachable then HTTP.status200 else HTTP.status503) [] mempty diff --git a/src/PostgREST/AppState.hs b/src/PostgREST/AppState.hs index 47eeaa12d..d6163b9d7 100644 --- a/src/PostgREST/AppState.hs +++ b/src/PostgREST/AppState.hs @@ -55,7 +55,7 @@ data AppState = AppState , stateIsWorkerOn :: IORef Bool -- | Binary semaphore used to sync the listener(NOTIFY reload) with the connectionWorker. , stateListener :: MVar () - -- | State of the LISTEN channel, used for health checks + -- | State of the LISTEN channel, used for the admin server checks , stateIsListenerOn :: IORef Bool -- | Config that can change at runtime , stateConf :: IORef AppConfig diff --git a/src/PostgREST/CLI.hs b/src/PostgREST/CLI.hs index 2f80c1bdf..6f83d1d37 100644 --- a/src/PostgREST/CLI.hs +++ b/src/PostgREST/CLI.hs @@ -199,7 +199,7 @@ exampleConfigFile = |## when none is provided, 660 is applied by default |# server-unix-socket-mode = "660" | - |## admin server for health checks, it's disabled by default unless a port is specified + |## admin server used for checks, it's disabled by default unless a port is specified |# admin-server-port = 3001 | |## determine if the OpenAPI output should follow or ignore role privileges or be disabled entirely diff --git a/test/io-tests/test_io.py b/test/io-tests/test_io.py index 79cdaeecf..d2e61667a 100644 --- a/test/io-tests/test_io.py +++ b/test/io-tests/test_io.py @@ -741,8 +741,8 @@ def test_db_prepared_statements_disable(defaultenv): assert response.text == "false" -def test_admin_healthy_w_channel(defaultenv): - "Should get a success response from the admin server health endpoint when the LISTEN channel is enabled" +def test_admin_ready_w_channel(defaultenv): + "Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled" env = { **defaultenv, @@ -750,12 +750,12 @@ def test_admin_healthy_w_channel(defaultenv): } with run(env=env, adminport=freeport()) as postgrest: - response = postgrest.admin.get("/health") + response = postgrest.admin.get("/ready") assert response.status_code == 200 -def test_admin_healthy_wo_channel(defaultenv): - "Should get a success response from the admin server health endpoint when the LISTEN channel is disabled" +def test_admin_ready_wo_channel(defaultenv): + "Should get a success response from the admin server ready endpoint when the LISTEN channel is disabled" env = { **defaultenv, @@ -763,20 +763,20 @@ def test_admin_healthy_wo_channel(defaultenv): } with run(env=env, adminport=freeport()) as postgrest: - response = postgrest.admin.get("/health") + response = postgrest.admin.get("/ready") assert response.status_code == 200 def test_admin_not_found(defaultenv): - "Should get a not found from the admin server" + "Should get a not found from a undefined endpoint on the admin server" with run(env=defaultenv, adminport=freeport()) as postgrest: response = postgrest.admin.get("/notfound") assert response.status_code == 404 -def test_admin_health_dependent_on_main_app(defaultenv): - "Should get a failure from the admin health endpoint if the main app also fails" +def test_admin_ready_dependent_on_main_app(defaultenv): + "Should get a failure from the admin ready endpoint if the main app also fails" env = { **defaultenv, @@ -787,6 +787,6 @@ def test_admin_health_dependent_on_main_app(defaultenv): # delete the unix socket to make the main app fail os.remove(env["PGRST_SERVER_UNIX_SOCKET"]) response = requests.get( - f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/health" + f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/ready" ) assert response.status_code == 503