]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: move freq-ctr from proxy/server into counters struct
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 29 Apr 2024 14:05:27 +0000 (16:05 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 2 May 2024 08:55:25 +0000 (10:55 +0200)
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.

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

index 8ba6322649fe16d48e9f8638c96767e4a1d324d8..eb1ce66d282c8d58fc165b868d4ac74fd17262aa 100644 (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 */
index eaeb06c2fc0155337a416f724d0cdb6d70787ca9..7695b4ef364fc8927bb0154d265454d8f22e56c2 100644 (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 */
index c3ab1701b876a88b6aef3102720e8218d93d8caa..974c78aea11248728e7b7c3a631395590a385f59 100644 (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 */
index 3bc2371e153aea12a29158498fb33a05cdba177d..b6ff41a9cf443209f819961008e4ddf35d32a3f0 100644 (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 */
index cb1c3c54946bf52302d4ce5dc359a60d8b777890..4d27e769ffb4af0ff236ef3e6b2fb7e8e23ca840 100644 (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 */
index 57b9ee34f14b740b97c7c274b717a93ece4bb4c4..cfe1add5a64179c84be3918af353d1359d4ad120 100644 (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;
 }
 
index e9b3bc0694f8d122ba5cce165f354fbdae0268bd..3b3bcbb1631e58338168abd703921487f0d9c7e6 100644 (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;
 }
 
index 01740f003d44467c4eb014a9ef8ca7c4062335aa..a3485580b389314dab7671e20f978a3550e8d8a4 100644 (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
index e5ba7bf120a724f9263e689cbc67a4de29f2553d..6fd123638f901c41547e9b27f7bc38563599edf4 100644 (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
index 5ada0503eeafcc5ae9eae977bb5838b242d354e5..65b701fdb6de69270828909e5570bfe627ed716a 100644 (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);