diff options
author | Manuel Rüger <manuel@rueg.eu> | 2021-06-08 23:18:21 +0200 |
---|---|---|
committer | Manuel Rüger <manuel@rueg.eu> | 2021-06-09 00:12:00 +0200 |
commit | 32a6adb5bf6dc5b42b08768a6f7470dfdc31fbdb (patch) | |
tree | fc7657ad8a0ab64cf110c4cbf6a8d0d365ca2024 | |
parent | 5efa9983936e94c5ef3df2092eac63dbd4ccd654 (diff) | |
download | rspamd-32a6adb5bf6dc5b42b08768a6f7470dfdc31fbdb.tar.gz rspamd-32a6adb5bf6dc5b42b08768a6f7470dfdc31fbdb.zip |
controller.c: Implement ready/health endpoints
These endpoints allow an orchestrator like kubernetes to verify the
status of rspamd (https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
Current implementation is very minimal.
The health endpoint allows to verify rspamd internally. It could check
for internal configuration and ensure that rspamd itself is healthy
and available.
The ready endpoint signals that rspamd is ready to receive and process
traffic and thus ensures that configured external components are available.
The readiness check could for example test if configured redis servers or
at least one rspamd upstreams is available.
-rw-r--r-- | src/controller.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/controller.c b/src/controller.c index 185970efa..e209d9320 100644 --- a/src/controller.c +++ b/src/controller.c @@ -46,11 +46,13 @@ #define PATH_GET_MAP "/getmap" #define PATH_GRAPH "/graph" #define PATH_PIE_CHART "/pie" +#define PATH_HEALTHY "/healthy" #define PATH_HISTORY "/history" #define PATH_HISTORY_RESET "/historyreset" #define PATH_LEARN_SPAM "/learnspam" #define PATH_LEARN_HAM "/learnham" #define PATH_METRICS "/metrics" +#define PATH_READY "/ready" #define PATH_SAVE_ACTIONS "/saveactions" #define PATH_SAVE_SYMBOLS "/savesymbols" #define PATH_SAVE_MAP "/savemap" @@ -1580,6 +1582,46 @@ err: } /* + * Healthy command handler: + * request: /healthy + * headers: Password + * reply: json {"success":true} + */ +static int +rspamd_controller_handle_healthy (struct rspamd_http_connection_entry *conn_ent, + struct rspamd_http_message *msg) +{ + struct rspamd_controller_session *session = conn_ent->ud; + + if (!rspamd_controller_check_password (conn_ent, session, msg, FALSE)) { + return 0; + } + + rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + return 0; +} + +/* + * Ready command handler: + * request: /ready + * headers: Password + * reply: json {"success":true} or {"error":"error message"} + */ +static int +rspamd_controller_handle_ready (struct rspamd_http_connection_entry *conn_ent, + struct rspamd_http_message *msg) +{ + struct rspamd_controller_session *session = conn_ent->ud; + + if (!rspamd_controller_check_password (conn_ent, session, msg, FALSE)) { + return 0; + } + + rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + return 0; +} + +/* * History command handler: * request: /history * headers: Password @@ -3895,6 +3937,12 @@ start_controller_worker (struct rspamd_worker *worker) PATH_GRAPH, rspamd_controller_handle_graph); rspamd_http_router_add_path (ctx->http, + PATH_HEALTHY, + rspamd_controller_handle_healthy); + rspamd_http_router_add_path (ctx->http, + PATH_READY, + rspamd_controller_handle_ready); + rspamd_http_router_add_path (ctx->http, PATH_HISTORY, rspamd_controller_handle_history); rspamd_http_router_add_path (ctx->http, |