commit 32a6adb: controller.c: Implement ready/health endpoints

Manuel Rüger manuel at rueg.eu
Wed Jul 21 10:07:05 UTC 2021


Author: Manuel Rüger
Date: 2021-06-08 23:18:21 +0200
URL: https://github.com/rspamd/rspamd/commit/32a6adb5bf6dc5b42b08768a6f7470dfdc31fbdb (refs/pull/3788/head)

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.

---
 src/controller.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

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"
@@ -1579,6 +1581,46 @@ err:
 	rspamd_controller_send_error (conn_ent, 500, "Internal error");
 }
 
+/*
+ * 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
@@ -3894,6 +3936,12 @@ start_controller_worker (struct rspamd_worker *worker)
 	rspamd_http_router_add_path (ctx->http,
 			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);


More information about the Commits mailing list