MINOR: checks/event_hdl: SERVER_CHECK event
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.
diff --git a/include/haproxy/event_hdl-t.h b/include/haproxy/event_hdl-t.h
index 249cfed..28b0cf1 100644
--- a/include/haproxy/event_hdl-t.h
+++ b/include/haproxy/event_hdl-t.h
@@ -272,6 +272,8 @@
#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)
/* --------------------------------------- */
diff --git a/include/haproxy/server-t.h b/include/haproxy/server-t.h
index 60eb925..bdbde02 100644
--- a/include/haproxy/server-t.h
+++ b/include/haproxy/server-t.h
@@ -443,6 +443,7 @@
* 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 @@
/* 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
*/
diff --git a/include/haproxy/server.h b/include/haproxy/server.h
index 7922050..4c382fa 100644
--- a/include/haproxy/server.h
+++ b/include/haproxy/server.h
@@ -66,6 +66,7 @@
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);
diff --git a/src/check.c b/src/check.c
index d894c3c..309b999 100644
--- a/src/check.c
+++ b/src/check.c
@@ -464,7 +464,7 @@
{
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 @@
*/
if (!s)
return;
- report = 0;
-
switch (check->result) {
case CHK_RES_FAILED:
@@ -543,8 +541,10 @@
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",
diff --git a/src/event_hdl.c b/src/event_hdl.c
index 5fc1935..7641486 100644
--- a/src/event_hdl.c
+++ b/src/event_hdl.c
@@ -31,6 +31,7 @@
{"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) */
diff --git a/src/server.c b/src/server.c
index 272e4e9..46ee174 100644
--- a/src/server.c
+++ b/src/server.c
@@ -262,6 +262,27 @@
_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