Add live endpoint to admin server
* refactor io tests * add network package to windows
This commit is contained in:
committed by
Steve Chavez
parent
65a3ae08f0
commit
4a9ca9bdae
+2
-1
@@ -9,7 +9,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- #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
|
||||
+ The check is at the `<host>:<admin_server_port>/live` endpoint. A 200 OK status will be returned if postgrest is alive, otherwise a 503 will be returned.
|
||||
+ A `<host>:<admin_server_port>/ready` endpoint is available for checking a correct internal state(the database connection plus the schema cache). 200 OK = ready, 503 = not ready.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
+1
-1
@@ -97,6 +97,7 @@ library
|
||||
, lens >= 4.14 && < 5.1
|
||||
, lens-aeson >= 1.0.1 && < 1.2
|
||||
, mtl >= 2.2.2 && < 2.3
|
||||
, network >= 2.6 && < 3.2
|
||||
, network-uri >= 2.6.1 && < 2.8
|
||||
, optparse-applicative >= 0.13 && < 0.17
|
||||
, parsec >= 3.1.11 && < 3.2
|
||||
@@ -134,7 +135,6 @@ library
|
||||
build-depends:
|
||||
unix
|
||||
, directory >= 1.2.6 && < 1.4
|
||||
, network >= 2.6 && < 3.2
|
||||
exposed-modules:
|
||||
PostgREST.Unix
|
||||
|
||||
|
||||
@@ -31,7 +31,10 @@ postgrestAdmin appState appConfig req respond = do
|
||||
else do
|
||||
result <- SQL.use (AppState.getPool appState) $ SQL.sql "SELECT 1"
|
||||
respond $ Wai.responseLBS (if isRight result && isMainAppReachable then HTTP.status200 else HTTP.status503) [] mempty
|
||||
_ -> respond $ Wai.responseLBS HTTP.status404 [] mempty
|
||||
["live"] ->
|
||||
respond $ Wai.responseLBS (if isMainAppReachable then HTTP.status200 else HTTP.status503) [] mempty
|
||||
_ ->
|
||||
respond $ Wai.responseLBS HTTP.status404 [] mempty
|
||||
|
||||
-- Try to connect to the main app socket
|
||||
-- Note that it doesn't even send a valid HTTP request, we just want to check that the main app is accepting connections
|
||||
|
||||
+21
-10
@@ -778,15 +778,26 @@ def test_admin_not_found(defaultenv):
|
||||
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,
|
||||
"PGRST_ADMIN_SERVER_PORT": "3001",
|
||||
}
|
||||
|
||||
with run(env=env, port=None) as postgrest:
|
||||
with run(env=defaultenv, adminport=freeport()) as postgrest:
|
||||
# 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']}/ready"
|
||||
)
|
||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||
response = postgrest.admin.get("/ready")
|
||||
assert response.status_code == 503
|
||||
|
||||
|
||||
def test_admin_live_good(defaultenv):
|
||||
"Should get a success from the admin live endpoint if the main app is running"
|
||||
|
||||
with run(env=defaultenv, port=freeport(), adminport=freeport()) as postgrest:
|
||||
response = postgrest.admin.get("/live")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_admin_live_dependent_on_main_app(defaultenv):
|
||||
"Should get a failure from the admin live endpoint if the main app also fails"
|
||||
|
||||
with run(env=defaultenv, adminport=freeport()) as postgrest:
|
||||
# delete the unix socket to make the main app fail
|
||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||
response = postgrest.admin.get("/live")
|
||||
assert response.status_code == 503
|
||||
|
||||
Reference in New Issue
Block a user