Source Health Check
Overview
Hasura enables users to check the health of connected data sources via the health check API. API reference here.
Configuring source health check
A health check configuration contains information that Hasura uses to determine the health state of a source. You can set the time interval for when Hasura will re-perform the check on the source.
Currently, Hasura supports enabling health checks on Postgres and MS SQL Server databases. Support for other data sources will be added soon.
Health check configurations for Postgres and SQL Server sources are identical and are as follows.
- Console
- CLI
- API
Console support will be added soon.
You can add health check for a source by adding the config to the /metadata/databases/database.yaml
file:
- name: <db-name>
kind: postgres
health_check:
test:
sql: SELECT 1
interval: 10
retries: 3
retry_interval: 5
timeout: 5
configuration:
connection_info:
database_url:
from_env: <DATABASE_URL_ENV>
pool_settings:
idle_timeout: 180
max_connections: 50
retries: 1
Apply the metadata by running:
hasura metadata apply
You can add health check for a database using the pg_add_source metadata API.
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type":"pg_add_source",
"args":{
"name":"<db_name>",
"replace_configuration":true,
"configuration":{
"connection_info":{
"database_url":{
"from_env":"<DATABASE_URL_ENV>"
}
}
},
"health_check": {
"test": {
"sql": "SELECT 1"
},
"interval": 300,
"timeout": 5,
"retries": 3,
"retry_interval": 5
}
}
}
Reporting source health check
API
Health check reports of sources can be obtained through a GET
request from the
/healthz/sources
API, on demand. Learn more about the API here.
Logging
Hasura logs the health check status and other information via health-check-log
type when enabled.
Learn more about the health checks logs here.