]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: promex: Add support for specialized front/back/li/srv metric names
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 4 Dec 2023 08:00:18 +0000 (09:00 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 Dec 2023 09:24:41 +0000 (10:24 +0100)
Depending on the scope, metrics can have different names. For instance, the
number of active/backend servers are reported with
"haproxy_backend_active_servers"/"haproxy_backend_backup_servers" metric names
in the backend scope while it should be
"haproxy_server_active"/"haproxy_server_backup" in the server scope.

To be able to support different names depending on the scope for the same
metric, arrays of ISTs were added, one by scope (front, back, listen,
server). These arrays only contain names overriding the default ones.

Note: the exemple above is not supported for now and is the reason for this
commit.

addons/promex/service-prometheus.c

index 6885d202e512d71698b2be3f4fde3e9fac0441da..86782b1af9edd14c931b611e17ff0e954f7d7b30 100644 (file)
@@ -306,6 +306,22 @@ const struct promex_metric promex_st_metrics[ST_F_TOTAL_FIELDS] = {
        [ST_F_AGG_CHECK_STATUS]     = { .n = IST("agg_check_status"),                 .type = PROMEX_MT_GAUGE,    .flags = (                                               PROMEX_FL_BACK_METRIC                       ) },
 };
 
+/* Specialized frontend metric names, to override default ones */
+const struct ist promex_st_front_metrics_names[ST_F_TOTAL_FIELDS] = {
+};
+
+/* Specialized bakcend metric names, to override default ones */
+const struct ist promex_st_back_metrics_names[ST_F_TOTAL_FIELDS] = {
+};
+
+/* Specialized listener metric names, to override default ones */
+const struct ist promex_st_li_metrics_names[ST_F_TOTAL_FIELDS] = {
+};
+
+/* Specialized server metric names, to override default ones */
+const struct ist promex_st_srv_metrics_names[ST_F_TOTAL_FIELDS] = {
+};
+
 /* Description of overridden stats fields */
 const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
        [ST_F_STATUS]         = IST("Current status of the service, per state label value."),
@@ -490,8 +506,8 @@ static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
  * success. Otherwise if <out> length exceeds <max>, it returns 0.
  */
 static int promex_dump_metric(struct appctx *appctx, struct htx *htx, struct ist prefix,
-                             const  struct promex_metric *metric, struct field *val,
-                             struct promex_label *labels, struct ist *out, size_t max)
+                             const struct ist n, const  struct promex_metric *metric,
+                             struct field *val, struct promex_label *labels, struct ist *out, size_t max)
 {
        struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
        struct promex_ctx *ctx = appctx->svcctx;
@@ -502,7 +518,7 @@ static int promex_dump_metric(struct appctx *appctx, struct htx *htx, struct ist
 
        /* Fill the metric name */
        istcat(&name, prefix, PROMEX_MAX_NAME_LEN);
-       istcat(&name, metric->n, PROMEX_MAX_NAME_LEN);
+       istcat(&name, (isttest(n) ? n : metric->n), PROMEX_MAX_NAME_LEN);
 
 
        if ((ctx->flags & PROMEX_FL_METRIC_HDR) &&
@@ -585,7 +601,7 @@ static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
                                val = info[ctx->field_num];
                }
 
-               if (!promex_dump_metric(appctx, htx, prefix, &promex_global_metrics[ctx->field_num],
+               if (!promex_dump_metric(appctx, htx, prefix, IST_NULL, &promex_global_metrics[ctx->field_num],
                                        &val, labels, &out, max))
                        goto full;
 
@@ -645,7 +661,9 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                                labels[1].name = ist("state");
                                                labels[1].value = promex_front_st[ctx->obj_state];
                                                val = mkf_u32(FO_STATUS, state == ctx->obj_state);
-                                               if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                               if (!promex_dump_metric(appctx, htx, prefix,
+                                                                       promex_st_front_metrics_names[ctx->field_num],
+                                                                       &promex_st_metrics[ctx->field_num],
                                                                        &val, labels, &out, max))
                                                        goto full;
                                        }
@@ -683,7 +701,9 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num];
                        }
 
-                       if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                       if (!promex_dump_metric(appctx, htx, prefix,
+                                               promex_st_front_metrics_names[ctx->field_num],
+                                               &promex_st_metrics[ctx->field_num],
                                                &val, labels, &out, max))
                                goto full;
                  next_px:
@@ -757,7 +777,9 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                                                        val = mkf_u32(FO_STATUS, status == ctx->obj_state);
                                                        labels[2].name = ist("state");
                                                        labels[2].value = ist(li_status_st[ctx->obj_state]);
-                                                       if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                                       if (!promex_dump_metric(appctx, htx, prefix,
+                                                                               promex_st_li_metrics_names[ctx->field_num],
+                                                                               &promex_st_metrics[ctx->field_num],
                                                                                &val, labels, &out, max))
                                                                goto full;
                                                }
@@ -768,6 +790,7 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                                }
 
                                if (!promex_dump_metric(appctx, htx, prefix,
+                                                       promex_st_li_metrics_names[ctx->field_num],
                                                        &promex_st_metrics[ctx->field_num],
                                                        &val, labels, &out, max))
                                        goto full;
@@ -852,7 +875,9 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                                val = mkf_u32(FN_GAUGE, srv_state_count[ctx->obj_state]);
                                                labels[1].name = ist("state");
                                                labels[1].value = promex_srv_st[ctx->obj_state];
-                                               if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                               if (!promex_dump_metric(appctx, htx, prefix,
+                                                                       promex_st_back_metrics_names[ctx->field_num],
+                                                                       &promex_st_metrics[ctx->field_num],
                                                                        &val, labels, &out, max))
                                                        goto full;
                                        }
@@ -876,7 +901,9 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                                check_state = get_check_status_info(ctx->obj_state);
                                                labels[1].name = ist("state");
                                                labels[1].value = ist(check_state);
-                                               if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                               if (!promex_dump_metric(appctx, htx, prefix,
+                                                                       promex_st_back_metrics_names[ctx->field_num],
+                                                                       &promex_st_metrics[ctx->field_num],
                                                                        &val, labels, &out, max))
                                                        goto full;
                                        }
@@ -888,7 +915,9 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                                labels[1].name = ist("state");
                                                labels[1].value = promex_back_st[ctx->obj_state];
                                                val = mkf_u32(FO_STATUS, bkd_state == ctx->obj_state);
-                                               if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                               if (!promex_dump_metric(appctx, htx, prefix,
+                                                                       promex_st_back_metrics_names[ctx->field_num],
+                                                                       &promex_st_metrics[ctx->field_num],
                                                                        &val, labels, &out, max))
                                                        goto full;
                                        }
@@ -956,7 +985,9 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num];
                        }
 
-                       if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                       if (!promex_dump_metric(appctx, htx, prefix,
+                                               promex_st_back_metrics_names[ctx->field_num],
+                                               &promex_st_metrics[ctx->field_num],
                                                &val, labels, &out, max))
                                goto full;
                  next_px:
@@ -1031,7 +1062,9 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                                        val = mkf_u32(FO_STATUS, state == ctx->obj_state);
                                                        labels[2].name = ist("state");
                                                        labels[2].value = promex_srv_st[ctx->obj_state];
-                                                       if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                                       if (!promex_dump_metric(appctx, htx, prefix,
+                                                                               promex_st_srv_metrics_names[ctx->field_num],
+                                                                               &promex_st_metrics[ctx->field_num],
                                                                                &val, labels, &out, max))
                                                                goto full;
                                                }
@@ -1080,7 +1113,9 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                                        check_state = get_check_status_info(ctx->obj_state);
                                                        labels[2].name = ist("state");
                                                        labels[2].value = ist(check_state);
-                                                       if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                                                       if (!promex_dump_metric(appctx, htx, prefix,
+                                                                               promex_st_srv_metrics_names[ctx->field_num],
+                                                                               &promex_st_metrics[ctx->field_num],
                                                                                &val, labels, &out, max))
                                                                goto full;
                                                }
@@ -1121,7 +1156,9 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                                val = stats[ctx->field_num];
                                }
 
-                               if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num],
+                               if (!promex_dump_metric(appctx, htx, prefix,
+                                                       promex_st_srv_metrics_names[ctx->field_num],
+                                                       &promex_st_metrics[ctx->field_num],
                                                        &val, labels, &out, max))
                                        goto full;
                          next_sv:
@@ -1189,7 +1226,7 @@ static int promex_dump_sticktable_metrics(struct appctx *appctx, struct htx *htx
                                        goto next_px;
                        }
 
-                       if (!promex_dump_metric(appctx, htx, prefix,
+                       if (!promex_dump_metric(appctx, htx, prefix, IST_NULL,
                                                &promex_sticktable_metrics[ctx->field_num],
                                                &val, labels, &out, max))
                                goto full;