Change admin health endpoint to ready
This commit is contained in:
committed by
Steve Chavez
parent
bba6e96fd3
commit
65a3ae08f0
+2
-1
@@ -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 `<host>:<admin_server_port>/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 `<host>:<admin_server_port>/ready` endpoint
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+10
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user