]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: counters: factor out smp_fetch_sc*_http_err_cnt
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Jul 2013 14:45:38 +0000 (16:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Aug 2013 19:17:14 +0000 (21:17 +0200)
smp_fetch_sc0_http_err_cnt, smp_fetch_sc1_http_err_cnt, smp_fetch_sc2_http_err_cnt,
smp_fetch_src_http_err_cnt and smp_fetch_http_err_cnt were merged into a single
function which relies on the fetch name to decide what to return.

src/session.c

index a0e1c96d88d2afb88bd6d51cb7351323e0a1e45f..42f182ccba57a28fd67ac58cfc13b13902866d86 100644 (file)
@@ -2945,15 +2945,24 @@ smp_fetch_sc_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsig
        return 1;
 }
 
-/* set temp integer to the cumulated number of sessions in the stksess entry <ts> */
+/* set <smp> to the cumulated number of HTTP requests errors from the session's
+ * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or
+ * "src_http_err_cnt" only.
+ */
 static int
-smp_fetch_http_err_cnt(struct stktable *table, struct sample *smp, struct stksess *ts)
+smp_fetch_sc_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                          const struct arg *args, struct sample *smp, const char *kw)
 {
+       struct stkctr *stkctr = smp_fetch_sc_stkctr(l4, args, kw);
+
+       if (!stkctr)
+               return 0;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->type = SMP_T_UINT;
        smp->data.uint = 0;
-       if (ts != NULL) {
-               void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_CNT);
+       if (stkctr->entry != NULL) {
+               void *ptr = stktable_data_ptr(stkctr->table, stkctr->entry, STKTABLE_DT_HTTP_ERR_CNT);
                if (!ptr)
                        return 0; /* parameter not stored */
                smp->data.uint = stktable_data_cast(ptr, http_err_cnt);
@@ -2961,57 +2970,6 @@ smp_fetch_http_err_cnt(struct stktable *table, struct sample *smp, struct stkses
        return 1;
 }
 
-/* set temp integer to the cumulated number of sessions from the session's tracked FE counters */
-static int
-smp_fetch_sc0_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                           const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[0].entry)
-               return 0;
-
-       return smp_fetch_http_err_cnt(l4->stkctr[0].table, smp, l4->stkctr[0].entry);
-}
-
-/* set temp integer to the cumulated number of sessions from the session's tracked BE counters */
-static int
-smp_fetch_sc1_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                           const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[1].entry)
-               return 0;
-
-       return smp_fetch_http_err_cnt(l4->stkctr[1].table, smp, l4->stkctr[1].entry);
-}
-
-/* set temp integer to the cumulated number of sessions from the session's tracked BE counters */
-static int
-smp_fetch_sc2_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                           const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[2].entry)
-               return 0;
-
-       return smp_fetch_http_err_cnt(l4->stkctr[2].table, smp, l4->stkctr[2].entry);
-}
-
-/* set temp integer to the cumulated number of session from the session's source
- * address in the table pointed to by expr.
- * Accepts exactly 1 argument of type table.
- */
-static int
-smp_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                           const struct arg *args, struct sample *smp, const char *kw)
-{
-       struct stktable_key *key;
-
-       key = addr_to_stktable_key(&l4->si[0].conn->addr.from);
-       if (!key)
-               return 0;
-
-       px = args->data.prx;
-       return smp_fetch_http_err_cnt(&px->table, smp, stktable_lookup_key(&px->table, key));
-}
-
 /* set temp integer to the session rate in the stksess entry <ts> over the configured period */
 static int
 smp_fetch_http_err_rate(struct stktable *table, struct sample *smp, struct stksess *ts)
@@ -3465,7 +3423,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc0_conn_rate",      smp_fetch_sc_conn_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_get_gpc0",       smp_fetch_sc_get_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_gpc0_rate",      smp_fetch_sc_gpc0_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc0_http_err_cnt",   smp_fetch_sc0_http_err_cnt,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
+       { "sc0_http_err_cnt",   smp_fetch_sc_http_err_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_http_err_rate",  smp_fetch_sc0_http_err_rate,  0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3484,7 +3442,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc1_conn_rate",      smp_fetch_sc_conn_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_get_gpc0",       smp_fetch_sc_get_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_gpc0_rate",      smp_fetch_sc_gpc0_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc1_http_err_cnt",   smp_fetch_sc1_http_err_cnt,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
+       { "sc1_http_err_cnt",   smp_fetch_sc_http_err_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_http_err_rate",  smp_fetch_sc1_http_err_rate,  0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3503,7 +3461,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc2_conn_rate",      smp_fetch_sc_conn_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_get_gpc0",       smp_fetch_sc_get_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_gpc0_rate",      smp_fetch_sc_gpc0_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc2_http_err_cnt",   smp_fetch_sc2_http_err_cnt,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
+       { "sc2_http_err_cnt",   smp_fetch_sc_http_err_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_http_err_rate",  smp_fetch_sc2_http_err_rate,  0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3522,7 +3480,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "src_conn_rate",      smp_fetch_sc_conn_rate,       ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_get_gpc0",       smp_fetch_sc_get_gpc0,        ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_gpc0_rate",      smp_fetch_sc_gpc0_rate,       ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
-       { "src_http_err_cnt",   smp_fetch_src_http_err_cnt,   ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+       { "src_http_err_cnt",   smp_fetch_sc_http_err_cnt,    ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_http_err_rate",  smp_fetch_src_http_err_rate,  ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_http_req_cnt",   smp_fetch_sc_http_req_cnt,    ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_http_req_rate",  smp_fetch_sc_http_req_rate,   ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },