From: Aurelien DARRAGON Date: Mon, 30 Jun 2025 13:55:56 +0000 (+0200) Subject: MINOR: counters: rename last_change counter to last_state_change X-Git-Tag: v3.3-dev3~72 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4fcc9b55723fe927e45ab3727e75f814e1fdb0d2;p=thirdparty%2Fhaproxy.git MINOR: counters: rename last_change counter to last_state_change Since proxy and server struct already have an internal last_change variable and we cannot merge it with the shared counter one, let's rename the last_change counter to be more specific and prevent the mixup between the two. last_change counter is renamed to last_state_change, and unlike the internal last_change, this one is a shared counter so it is expected to be updated by other processes in our back. However, when updating last_state_change counter, we use the value of the server/proxy last_change as reference value. --- diff --git a/include/haproxy/counters-t.h b/include/haproxy/counters-t.h index b52fc93f4..c4774c9e0 100644 --- a/include/haproxy/counters-t.h +++ b/include/haproxy/counters-t.h @@ -35,7 +35,7 @@ }; #define COUNTERS_SHARED_TG \ struct { \ - unsigned long last_change; /* last time, when the state was changed */\ + unsigned long last_state_change; /* last time, when the state was changed */\ long long srv_aborts; /* aborted responses during DATA phase caused by the server */\ long long cli_aborts; /* aborted responses during DATA phase caused by the client */\ long long internal_errors; /* internal processing errors */\ diff --git a/src/backend.c b/src/backend.c index 56a6d88b0..57702fd2e 100644 --- a/src/backend.c +++ b/src/backend.c @@ -2895,7 +2895,7 @@ void back_handle_st_rdy(struct stream *s) void set_backend_down(struct proxy *be) { be->last_change = ns_to_sec(now_ns); - HA_ATOMIC_STORE(&be->be_counters.shared->tg[tgid - 1]->last_change, ns_to_sec(now_ns)); + HA_ATOMIC_STORE(&be->be_counters.shared->tg[tgid - 1]->last_state_change, be->last_change); _HA_ATOMIC_INC(&be->be_counters.shared->tg[tgid - 1]->down_trans); if (!(global.mode & MODE_STARTING)) { diff --git a/src/counters.c b/src/counters.c index 33f48ad93..84f3073ee 100644 --- a/src/counters.c +++ b/src/counters.c @@ -61,7 +61,6 @@ void counters_be_shared_drop(struct be_counters_shared *counters) static void*_counters_shared_get(const struct guid_node *guid, size_t size) { struct counters_shared *shared; - uint last_change; int it = 0; /* no shared memory for now, simply allocate a memory block @@ -80,10 +79,11 @@ static void*_counters_shared_get(const struct guid_node *guid, size_t size) } it += 1; } - last_change = ns_to_sec(now_ns); - /* only set one group, only latest value is considered */ - HA_ATOMIC_STORE(&shared->tg[0]->last_change, last_change); + /* initial values: + * only set one group, only latest value is considered + */ + HA_ATOMIC_STORE(&shared->tg[0]->last_state_change, ns_to_sec(now_ns)); return shared; } diff --git a/src/server.c b/src/server.c index 73870574b..8cad9ca04 100644 --- a/src/server.c +++ b/src/server.c @@ -7051,8 +7051,8 @@ static void srv_update_status(struct server *s, int type, int cause) if (s->cur_state != SRV_ST_RUNNING && s->proxy->ready_srv == s) HA_ATOMIC_STORE(&s->proxy->ready_srv, NULL); - HA_ATOMIC_STORE(&s->counters.shared->tg[tgid - 1]->last_change, ns_to_sec(now_ns)); s->last_change = ns_to_sec(now_ns); + HA_ATOMIC_STORE(&s->counters.shared->tg[tgid - 1]->last_state_change, s->last_change); /* publish the state change */ _srv_event_hdl_prepare_state(&cb_data.state, @@ -7072,7 +7072,7 @@ static void srv_update_status(struct server *s, int type, int cause) if (last_change < ns_to_sec(now_ns)) // ignore negative times s->proxy->down_time += ns_to_sec(now_ns) - last_change; s->proxy->last_change = ns_to_sec(now_ns); - HA_ATOMIC_STORE(&s->proxy->be_counters.shared->tg[tgid - 1]->last_change, ns_to_sec(now_ns)); + HA_ATOMIC_STORE(&s->proxy->be_counters.shared->tg[tgid - 1]->last_state_change, s->proxy->last_change); } } diff --git a/src/server_state.c b/src/server_state.c index ee1f51fcb..2bbcb46d9 100644 --- a/src/server_state.c +++ b/src/server_state.c @@ -321,8 +321,8 @@ static void srv_state_srv_update(struct server *srv, int version, char **params) srv_adm_set_drain(srv); } - HA_ATOMIC_STORE(&srv->counters.shared->tg[0]->last_change, ns_to_sec(now_ns) - srv_last_time_change); srv->last_change = ns_to_sec(now_ns) - srv_last_time_change; + HA_ATOMIC_STORE(&srv->counters.shared->tg[0]->last_state_change, srv->last_change); srv->check.status = srv_check_status; srv->check.result = srv_check_result; diff --git a/src/stats-proxy.c b/src/stats-proxy.c index 48215ac51..eddc59d5a 100644 --- a/src/stats-proxy.c +++ b/src/stats-proxy.c @@ -100,7 +100,7 @@ const struct stat_col stat_cols_px[ST_I_PX_MAX] = { [ST_I_PX_BCK] = { .name = "bck", .alt_name = "backup_servers", .desc = "Total number of backup UP servers with a non-zero weight", .cap = STATS_PX_CAP___BS }, [ST_I_PX_CHKFAIL] = ME_NEW_BE_SHARED("chkfail", "check_failures_total", FN_COUNTER, FF_U64, failed_checks, STATS_PX_CAP____S, "Total number of failed individual health checks per server/backend, since the worker process started"), [ST_I_PX_CHKDOWN] = ME_NEW_BE_SHARED("chkdown", "check_up_down_total", FN_COUNTER, FF_U64, down_trans, STATS_PX_CAP___BS, "Total number of failed checks causing UP to DOWN server transitions, per server/backend, since the worker process started"), - [ST_I_PX_LASTCHG] = ME_NEW_BE_SHARED("lastchg", "check_last_change_seconds", FN_AGE, FF_U32, last_change, STATS_PX_CAP___BS, "How long ago the last server state changed, in seconds"), + [ST_I_PX_LASTCHG] = ME_NEW_BE_SHARED("lastchg", "check_last_change_seconds", FN_AGE, FF_U32, last_state_change, STATS_PX_CAP___BS, "How long ago the last server state changed, in seconds"), [ST_I_PX_DOWNTIME] = { .name = "downtime", .alt_name = "downtime_seconds_total", .desc = "Total time spent in DOWN state, for server or backend", .cap = STATS_PX_CAP___BS }, [ST_I_PX_QLIMIT] = { .name = "qlimit", .alt_name = "queue_limit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)", .cap = STATS_PX_CAP____S }, [ST_I_PX_PID] = { .name = "pid", .alt_name = NULL, .desc = "Relative worker process number (1)" },