MEDIUM: proxy: add and use a separate last_change variable for internal use

Same motivation as previous commit, proxy last_change is "abused" because
it is used for 2 different purposes, one for stats, and the other one
for process-local internal use.

Let's add a separate proxy-only last_change variable for internal use,
and leave the last_change shared (and thread-grouped) counter for
statistics.
This commit is contained in:
Aurelien DARRAGON 2025-06-30 15:45:44 +02:00
parent 01dfe17acf
commit 5b1480c9d4
4 changed files with 7 additions and 6 deletions

View File

@ -311,7 +311,7 @@ struct proxy {
char flags; /* bit field PR_FL_* */ char flags; /* bit field PR_FL_* */
enum pr_mode mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP, ... */ enum pr_mode mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP, ... */
char cap; /* supported capabilities (PR_CAP_*) */ char cap; /* supported capabilities (PR_CAP_*) */
/* 4-bytes hole */ unsigned long last_change; /* internal use only: last time the proxy state was changed */
struct list global_list; /* list member for global proxy list */ struct list global_list; /* list member for global proxy list */

View File

@ -2894,6 +2894,7 @@ void back_handle_st_rdy(struct stream *s)
*/ */
void set_backend_down(struct proxy *be) 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_change, ns_to_sec(now_ns));
_HA_ATOMIC_INC(&be->be_counters.shared->tg[tgid - 1]->down_trans); _HA_ATOMIC_INC(&be->be_counters.shared->tg[tgid - 1]->down_trans);
@ -2967,12 +2968,10 @@ int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit)
} }
int be_downtime(struct proxy *px) { int be_downtime(struct proxy *px) {
unsigned long last_change = COUNTERS_SHARED_LAST(px->be_counters.shared->tg, last_change); if (px->lbprm.tot_weight && px->last_change < ns_to_sec(now_ns)) // ignore negative time
if (px->lbprm.tot_weight && last_change < ns_to_sec(now_ns)) // ignore negative time
return px->down_time; return px->down_time;
return ns_to_sec(now_ns) - last_change + px->down_time; return ns_to_sec(now_ns) - px->last_change + px->down_time;
} }
/* /*

View File

@ -1722,6 +1722,7 @@ int setup_new_proxy(struct proxy *px, const char *name, unsigned int cap, char *
} }
px->cap = cap; px->cap = cap;
px->last_change = ns_to_sec(now_ns);
if (name && !(cap & PR_CAP_INT)) if (name && !(cap & PR_CAP_INT))
proxy_store_name(px); proxy_store_name(px);

View File

@ -7064,13 +7064,14 @@ static void srv_update_status(struct server *s, int type, int cause)
if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0)
set_backend_down(s->proxy); /* backend going down */ set_backend_down(s->proxy); /* backend going down */
else if (!prev_srv_count && (s->proxy->srv_bck || s->proxy->srv_act)) { else if (!prev_srv_count && (s->proxy->srv_bck || s->proxy->srv_act)) {
unsigned long last_change = COUNTERS_SHARED_LAST(s->proxy->be_counters.shared->tg, last_change); unsigned long last_change = s->proxy->last_change;
/* backend was down and is back up again: /* backend was down and is back up again:
* no helper function, updating last_change and backend downtime stats * no helper function, updating last_change and backend downtime stats
*/ */
if (last_change < ns_to_sec(now_ns)) // ignore negative times if (last_change < ns_to_sec(now_ns)) // ignore negative times
s->proxy->down_time += ns_to_sec(now_ns) - last_change; 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_change, ns_to_sec(now_ns));
} }
} }