]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: rename last_change counter to last_state_change
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 30 Jun 2025 13:55:56 +0000 (15:55 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 30 Jun 2025 14:26:38 +0000 (16:26 +0200)
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.

include/haproxy/counters-t.h
src/backend.c
src/counters.c
src/server.c
src/server_state.c
src/stats-proxy.c

index b52fc93f4b72d15797d97711bf53ab56ae029f9b..c4774c9e039041550d244d8475cad4de1e4aee93 100644 (file)
@@ -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 */\
index 56a6d88b0614ec779b22d16a70c495d2a630556a..57702fd2ed1c47451479081b3135294bedfa7dbe 100644 (file)
@@ -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)) {
index 33f48ad93432bbc2497c065df9fb1462f66b7201..84f3073eec328ec5cf8d9e347f56ada5711b132a 100644 (file)
@@ -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;
 }
 
index 73870574bf08a5fb6a2b9f868464723d3d2143b7..8cad9ca049482ec5ea35be87a5e60fbae977d1d5 100644 (file)
@@ -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);
        }
 }
 
index ee1f51fcb1b5dba2de399ddd58f1741bf51916bd..2bbcb46d978b9372d38c040dad3ef6b4e2472e2b 100644 (file)
@@ -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;
 
index 48215ac51802780aab62722148ad1d1b6098553a..eddc59d5a33b1a88fd6e755f80e2037c3ee4eec2 100644 (file)
@@ -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)" },