]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks/event_hdl: SERVER_CHECK event
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 30 Mar 2023 08:19:08 +0000 (10:19 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
Adding a new event type: SERVER_CHECK.

This event is published when a server's check state ought to be reported.
(check status change or check result)

SERVER_CHECK event is provided as a server event with additional data
carrying relevant check's context such as check's result and health.

include/haproxy/event_hdl-t.h
include/haproxy/server-t.h
include/haproxy/server.h
src/check.c
src/event_hdl.c
src/server.c

index 249cfeda2ef7dd6964ba722cdfef1f2b58200f5d..28b0cf15674510796f1636edb1dcd9ada6e46a1a 100644 (file)
@@ -272,6 +272,8 @@ struct event_hdl_sub {
 #define EVENT_HDL_SUB_SERVER_STATE                      EVENT_HDL_SUB_TYPE(1,5)
 /* server admin change */
 #define EVENT_HDL_SUB_SERVER_ADMIN                      EVENT_HDL_SUB_TYPE(1,6)
+/* server check-related (agent or health) event */
+#define EVENT_HDL_SUB_SERVER_CHECK                      EVENT_HDL_SUB_TYPE(1,7)
 
 /*     ---------------------------------------        */
 
index 60eb92555f00588106f4a4ec50740e754ac73881..bdbde022f71e1ca8c7a96c001f0e7ee6db51c7aa 100644 (file)
@@ -443,6 +443,7 @@ struct event_hdl_cb_data_server {
         *   EVENT_HDL_SUB_SERVER_DOWN
         *   EVENT_HDL_SUB_SERVER_STATE
         *   EVENT_HDL_SUB_SERVER_ADMIN
+        *   EVENT_HDL_SUB_SERVER_CHECK
         */
        struct {
                /* safe data can be safely used from both
@@ -543,6 +544,25 @@ struct event_hdl_cb_data_server_admin {
        /* no unsafe data */
 };
 
+/* data provided to EVENT_HDL_SUB_SERVER_CHECK handlers through
+ * event_hdl facility
+ *
+ * Note that this may be casted to regular event_hdl_cb_data_server if
+ * you don't care about check related optional info
+ */
+struct event_hdl_cb_data_server_check {
+       /* provided by:
+        *   EVENT_HDL_SUB_SERVER_CHECK
+        */
+       struct event_hdl_cb_data_server server;                 /* must be at the beginning */
+       struct {
+               struct event_hdl_cb_data_server_checkres res;   /* check result snapshot */
+       } safe;
+       struct {
+               struct check *ptr;                              /* check ptr */
+       } unsafe;
+};
+
 /* Storage structure to load server-state lines from a flat file into
  * an ebtree, for faster processing
  */
index 79220503a9750b625ce7140f8b7a550594cfc1d8..4c382fa695fb487bca97ab57d2f0a5716334b440 100644 (file)
@@ -66,6 +66,7 @@ int srv_init_per_thr(struct server *srv);
 void srv_set_ssl(struct server *s, int use_ssl);
 const char *srv_adm_st_chg_cause(enum srv_adm_st_chg_cause cause);
 const char *srv_op_st_chg_cause(enum srv_op_st_chg_cause cause);
+void srv_event_hdl_publish_check(struct server *srv, struct check *check);
 
 /* functions related to server name resolution */
 int srv_prepare_for_resolution(struct server *srv, const char *hostname);
index d894c3c0d198209d5496d96f0de378ff6174836a..309b999649afdef1d473bb459ce9c1d477975572 100644 (file)
@@ -464,7 +464,7 @@ void set_server_check_status(struct check *check, short status, const char *desc
 {
        struct server *s = check->server;
        short prev_status = check->status;
-       int report = 0;
+       int report = (status != prev_status) ? 1 : 0;
 
        TRACE_POINT(CHK_EV_HCHK_RUN, check);
 
@@ -505,8 +505,6 @@ void set_server_check_status(struct check *check, short status, const char *desc
         */
        if (!s)
            return;
-       report = 0;
-
 
        switch (check->result) {
        case CHK_RES_FAILED:
@@ -543,8 +541,10 @@ void set_server_check_status(struct check *check, short status, const char *desc
                break;
        }
 
-       if (s->proxy->options2 & PR_O2_LOGHCHKS &&
-           (status != prev_status || report)) {
+       if (report)
+               srv_event_hdl_publish_check(s, check);
+
+       if (s->proxy->options2 & PR_O2_LOGHCHKS && report) {
                chunk_printf(&trash,
                             "%s check for %sserver %s/%s %s%s",
                             (check->state & CHK_ST_AGENT) ? "Agent" : "Health",
index 5fc1935ecd70e4e16fbffdbc9914f44ff5d1ad01..7641486cf9f92a06c0beb1da3e7861b81990ecfd 100644 (file)
@@ -31,6 +31,7 @@ static struct event_hdl_sub_type_map event_hdl_sub_type_map[] = {
        {"SERVER_DOWN",         EVENT_HDL_SUB_SERVER_DOWN},
        {"SERVER_STATE",        EVENT_HDL_SUB_SERVER_STATE},
        {"SERVER_ADMIN",        EVENT_HDL_SUB_SERVER_ADMIN},
+       {"SERVER_CHECK",        EVENT_HDL_SUB_SERVER_CHECK},
 };
 
 /* internal types (only used in this file) */
index 272e4e9c79132595228f552fbf0fd0bf2779c338..46ee174958c8962d6a4819251e1adbccbe8b854c 100644 (file)
@@ -262,6 +262,27 @@ static void srv_event_hdl_publish(struct event_hdl_sub_type event,
        _srv_event_hdl_publish(event, cb_data, srv);
 }
 
+/* Publish SERVER_CHECK event
+ *
+ * This special event will contain extra hints related to the check itself
+ *
+ * Must be called with server lock held
+ */
+void srv_event_hdl_publish_check(struct server *srv, struct check *check)
+{
+       struct event_hdl_cb_data_server_check cb_data;
+
+       /* check event provides additional info about the server check */
+       _srv_event_hdl_prepare_checkres(&cb_data.safe.res, check);
+
+       cb_data.unsafe.ptr = check;
+
+       /* prepare event data (common server data) */
+       _srv_event_hdl_prepare((struct event_hdl_cb_data_server *)&cb_data, srv, 0);
+
+       _srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_CHECK, cb_data, srv);
+}
+
 /*
  * Check that we did not get a hash collision.
  * Unlikely, but it can happen. The server's proxy must be at least