MINOR: counters: move freq-ctr from proxy/server into counters struct

Move freq-ctr defined in proxy or server structures into their dedicated
fe_counters/be_counters struct.

Functionnaly no change here. This commit will allow to convert rate
stats column to generic one, which is mandatory to manipulate them in
the stats-file.
This commit is contained in:
Amaury Denoyelle 2024-04-29 16:05:27 +02:00
parent 4e9e841878
commit 639e73f8f2
10 changed files with 28 additions and 27 deletions

View File

@ -23,6 +23,8 @@
#ifndef _HAPROXY_COUNTERS_T_H
#define _HAPROXY_COUNTERS_T_H
#include <haproxy/freq_ctr-t.h>
/* counters used by listeners and frontends */
struct fe_counters {
unsigned int conn_max; /* max # of active sessions */
@ -63,6 +65,10 @@ struct fe_counters {
long long cache_hits; /* cache hits */
} http;
} p; /* protocol-specific stats */
struct freq_ctr sess_per_sec; /* sessions per second on this server */
struct freq_ctr req_per_sec; /* HTTP requests per second on the frontend */
struct freq_ctr conn_per_sec; /* received connections per second on the frontend */
};
/* counters used by servers and backends */
@ -115,6 +121,8 @@ struct be_counters {
long long cache_hits; /* cache hits */
} http;
} p; /* protocol-specific stats */
struct freq_ctr sess_per_sec; /* sessions per second on this server */
};
#endif /* _HAPROXY_COUNTERS_T_H */

View File

@ -34,7 +34,6 @@
#include <haproxy/backend-t.h>
#include <haproxy/compression-t.h>
#include <haproxy/counters-t.h>
#include <haproxy/freq_ctr-t.h>
#include <haproxy/guid-t.h>
#include <haproxy/obj_type-t.h>
#include <haproxy/queue-t.h>
@ -354,10 +353,6 @@ struct proxy {
struct queue queue; /* queued requests (pendconns) */
int totpend; /* total number of pending connections on this instance (for stats) */
unsigned int feconn, beconn; /* # of active frontend and backends streams */
struct freq_ctr fe_req_per_sec; /* HTTP requests per second on the frontend */
struct freq_ctr fe_conn_per_sec; /* received connections per second on the frontend */
struct freq_ctr fe_sess_per_sec; /* accepted sessions per second on the frontend (after tcp rules) */
struct freq_ctr be_sess_per_sec; /* sessions per second on the backend */
unsigned int fe_sps_lim; /* limit on new sessions per second on the frontend */
unsigned int fullconn; /* #conns on backend above which servers are used at full load */
unsigned int tot_fe_maxconn; /* #maxconn of frontends linked to that backend, it is used to compute fullconn */

View File

@ -134,7 +134,7 @@ static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->cum_conn);
HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.cps_max,
update_freq_ctr(&fe->fe_conn_per_sec, 1));
update_freq_ctr(&fe->fe_counters.conn_per_sec, 1));
}
/* increase the number of cumulated connections accepted by the designated frontend */
@ -145,7 +145,7 @@ static inline void proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe)
if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->cum_sess);
HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.sps_max,
update_freq_ctr(&fe->fe_sess_per_sec, 1));
update_freq_ctr(&fe->fe_counters.sess_per_sec, 1));
}
/* increase the number of cumulated HTTP sessions on the designated frontend.
@ -168,7 +168,7 @@ static inline void proxy_inc_be_ctr(struct proxy *be)
{
_HA_ATOMIC_INC(&be->be_counters.cum_sess);
HA_ATOMIC_UPDATE_MAX(&be->be_counters.sps_max,
update_freq_ctr(&be->be_sess_per_sec, 1));
update_freq_ctr(&be->be_counters.sess_per_sec, 1));
}
/* increase the number of cumulated requests on the designated frontend.
@ -185,7 +185,7 @@ static inline void proxy_inc_fe_req_ctr(struct listener *l, struct proxy *fe,
if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->p.http.cum_req[http_ver]);
HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.p.http.rps_max,
update_freq_ctr(&fe->fe_req_per_sec, 1));
update_freq_ctr(&fe->fe_counters.req_per_sec, 1));
}
/* Returns non-zero if the proxy is configured to retry a request if we got that status, 0 otherwise */

View File

@ -31,7 +31,6 @@
#include <haproxy/check-t.h>
#include <haproxy/connection-t.h>
#include <haproxy/counters-t.h>
#include <haproxy/freq_ctr-t.h>
#include <haproxy/guid-t.h>
#include <haproxy/listener-t.h>
#include <haproxy/obj_type-t.h>
@ -366,7 +365,6 @@ struct server {
int cur_sess; /* number of currently active sessions (including syn_sent) */
int served; /* # of active sessions currently being served (ie not pending) */
int consecutive_errors; /* current number of consecutive errors */
struct freq_ctr sess_per_sec; /* sessions per second on this server */
struct be_counters counters; /* statistics counters */
/* Below are some relatively stable settings, only changed under the lock */

View File

@ -181,7 +181,7 @@ static inline void srv_inc_sess_ctr(struct server *s)
{
_HA_ATOMIC_INC(&s->counters.cum_sess);
HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max,
update_freq_ctr(&s->sess_per_sec, 1));
update_freq_ctr(&s->counters.sess_per_sec, 1));
}
/* set the time of last session on the designated server */

View File

@ -3080,7 +3080,7 @@ smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *k
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&px->be_sess_per_sec);
smp->data.u.sint = read_freq_ctr(&px->be_counters.sess_per_sec);
return 1;
}
@ -3263,7 +3263,7 @@ smp_fetch_srv_sess_rate(const struct arg *args, struct sample *smp, const char *
{
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&args->data.srv->sess_per_sec);
smp->data.u.sint = read_freq_ctr(&args->data.srv->counters.sess_per_sec);
return 1;
}

View File

@ -252,7 +252,7 @@ smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&px->fe_req_per_sec);
smp->data.u.sint = read_freq_ctr(&px->fe_counters.req_per_sec);
return 1;
}
@ -272,7 +272,7 @@ smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *k
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&px->fe_sess_per_sec);
smp->data.u.sint = read_freq_ctr(&px->fe_counters.sess_per_sec);
return 1;
}

View File

@ -1070,11 +1070,11 @@ void listener_accept(struct listener *l)
}
#endif
if (p && p->fe_sps_lim) {
int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
int max = freq_ctr_remain(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0);
if (unlikely(!max)) {
/* frontend accept rate limit was reached */
expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
expire = tick_add(now_ms, next_event_delay(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0));
goto limit_proxy;
}
@ -1545,7 +1545,7 @@ void listener_accept(struct listener *l)
dequeue_all_listeners();
if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
(!p->fe_sps_lim || freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0) > 0))
(!p->fe_sps_lim || freq_ctr_remain(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0) > 0))
dequeue_proxy_listeners(p);
}
return;
@ -1604,14 +1604,14 @@ void listener_release(struct listener *l)
dequeue_all_listeners();
if (fe && !MT_LIST_ISEMPTY(&fe->listener_queue) &&
(!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_sess_per_sec, fe->fe_sps_lim, 0) > 0))
(!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_counters.sess_per_sec, fe->fe_sps_lim, 0) > 0))
dequeue_proxy_listeners(fe);
else {
unsigned int wait;
int expire = TICK_ETERNITY;
if (fe->task && fe->fe_sps_lim &&
(wait = next_event_delay(&fe->fe_sess_per_sec,fe->fe_sps_lim, 0))) {
(wait = next_event_delay(&fe->fe_counters.sess_per_sec,fe->fe_sps_lim, 0))) {
/* we're blocking because a limit was reached on the number of
* requests/s on the frontend. We want to re-check ASAP, which
* means in 1 ms before estimated expiration date, because the

View File

@ -1980,7 +1980,7 @@ struct task *manage_proxy(struct task *t, void *context, unsigned int state)
goto out;
if (p->fe_sps_lim &&
(wait = next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0))) {
(wait = next_event_delay(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0))) {
/* we're blocking because a limit was reached on the number of
* requests/s on the frontend. We want to re-check ASAP, which
* means in 1 ms before estimated expiration date, because the

View File

@ -877,7 +877,7 @@ int stats_fill_fe_line(struct proxy *px, int flags, struct field *line, int len,
field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE);
break;
case ST_I_PX_RATE:
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec));
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.sess_per_sec));
break;
case ST_I_PX_RATE_LIM:
field = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
@ -886,13 +886,13 @@ int stats_fill_fe_line(struct proxy *px, int flags, struct field *line, int len,
field = mkf_u32(FN_MAX, px->fe_counters.sps_max);
break;
case ST_I_PX_REQ_RATE:
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec));
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.req_per_sec));
break;
case ST_I_PX_REQ_RATE_MAX:
field = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
break;
case ST_I_PX_CONN_RATE:
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec));
field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.conn_per_sec));
break;
case ST_I_PX_CONN_RATE_MAX:
field = mkf_u32(FN_MAX, px->fe_counters.cps_max);
@ -1364,7 +1364,7 @@ int stats_fill_sv_line(struct proxy *px, struct server *sv, int flags,
field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV);
break;
case ST_I_PX_RATE:
field = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec));
field = mkf_u32(FN_RATE, read_freq_ctr(&sv->counters.sess_per_sec));
break;
case ST_I_PX_RATE_MAX:
field = mkf_u32(FN_MAX, sv->counters.sps_max);
@ -1710,7 +1710,7 @@ int stats_fill_be_line(struct proxy *px, int flags, struct field *line, int len,
field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE);
break;
case ST_I_PX_RATE:
field = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
field = mkf_u32(0, read_freq_ctr(&px->be_counters.sess_per_sec));
break;
case ST_I_PX_RATE_MAX:
field = mkf_u32(0, px->be_counters.sps_max);