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.
This commit is contained in:
Aurelien DARRAGON 2023-03-30 10:19:08 +02:00 committed by Christopher Faulet
parent 948dd3ddfb
commit dcbc2d2cac
6 changed files with 50 additions and 5 deletions

View 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)
/* --------------------------------------- */

View 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
*/

View 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);

View 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",

View 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) */

View 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