这是indexloc提供的服务,不要输入任何密码
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
24 changes: 19 additions & 5 deletions docs/graphql/manual/api-reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,25 @@ in JSON format:
Health check API
^^^^^^^^^^^^^^^^

A ``GET`` request to the public ``/healthz`` endpoint will respond with ``200``
if the GraphQL engine is ready to serve requests and there are no inconsistencies
with the metadata. The response will be ``500`` if there are metadata
inconsistencies and you should use the console or check the server logs to find
out what the errors are.
A ``GET`` request to the public ``/healthz`` endpoint will respond with the following:

.. list-table::
:header-rows: 1

* - Server condition
- HTTP Status
- Message
* - All healthy
- 200
- OK
* - Serving requests but some metadata objects are inconsistent/not-available
- 200
- WARN: inconsistent objects in schema
* - Unhealthy
- 500
- ERROR

If there are metadata inconsistencies, you should use the console or use the `get_inconsistent_metadata <schema-metadata-api/manage-metadata.html#get-inconsistent-metadata>`_ API to find out what the inconsistent objects are.


.. _pg_dump_api:
Expand Down
18 changes: 15 additions & 3 deletions server/src-lib/Hasura/Server/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Control.Concurrent.MVar
import Control.Exception (IOException, try)
import Control.Monad.Stateless
import Data.Aeson hiding (json)
import Data.Either (isRight)
import Data.Int (Int64)
import Data.IORef
import Data.Time.Clock (UTCTime)
Expand Down Expand Up @@ -530,9 +531,12 @@ httpApp corsCfg serverCtx enableConsole consoleAssetsDir enableTelemetry = do
-- Health check endpoint
Spock.get "healthz" $ do
sc <- liftIO $ getSCFromRef $ scCacheRef serverCtx
if null $ scInconsistentObjs sc
then Spock.setStatus HTTP.status200 >> Spock.lazyBytes "OK"
else Spock.setStatus HTTP.status500 >> Spock.lazyBytes "ERROR"
dbOk <- checkDbConnection
if dbOk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no content-type set when using lazyBytes, also no point using lazyBytes for such small strings.

then Spock.setStatus HTTP.status200 >> (Spock.text $ if null (scInconsistentObjs sc)
then "OK"
else "WARN: inconsistent objects in schema")
else Spock.setStatus HTTP.status500 >> Spock.text "ERROR"

Spock.get "v1/version" $ do
uncurry Spock.setHeader jsonHeader
Expand Down Expand Up @@ -618,6 +622,14 @@ httpApp corsCfg serverCtx enableConsole consoleAssetsDir enableTelemetry = do
enablePGDump = isPGDumpEnabled serverCtx
enableConfig = isConfigEnabled serverCtx

checkDbConnection = do
e <- liftIO $ runExceptT $ runLazyTx' (scPGExecCtx serverCtx) select1Query
pure $ isRight e
where
select1Query :: (MonadTx m) => m Int
select1Query = liftTx $ runIdentity . Q.getRow <$> Q.withQE defaultTxErrorHandler
[Q.sql| SELECT 1 |] () False

serveApiConsole = do
-- redirect / to /console
Spock.get Spock.root $ Spock.redirect "console"
Expand Down