]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: promex: Rename dump functions to use the right wording
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 31 Jan 2024 09:42:10 +0000 (10:42 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Feb 2024 08:11:34 +0000 (09:11 +0100)
In Prometheus, a time series a stream of timestamped values belonging to the
same metric and the same set of labeled dimensions. Thus the exporter dump
time-series and not metrics.

Thus, promex_dump_metric(), promex_dump_metric_header() and
promex_metric_to_str() functions were renamed to replace "metric"

addons/promex/service-prometheus.c

index 1b98fa85219a87582e9a58aa25e34928720060f0..21660ff76b203f361838b09e3090f743fa4a6c98 100644 (file)
@@ -393,7 +393,7 @@ enum promex_srv_state promex_srv_status(struct server *sv)
  * to process this kind of value). It returns 1 on success. Otherwise, it
  * returns 0. The buffer's length must not exceed <max> value.
  */
-static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
+static int promex_ts_val_to_str(struct buffer *out, struct field *f, size_t max)
 {
        int ret = 0;
 
@@ -412,12 +412,13 @@ static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
        return 1;
 }
 
-/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
- * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
+/* Dump the time series header lines for <metric>. It is its #HELP and #TYPE
+ * strings. It returns 1 on success. Otherwise, if <out> length exceeds <max>,
+ * it returns 0.
  */
-static int promex_dump_metric_header(struct appctx *appctx, const struct promex_metric *metric,
-                                    const struct ist name, const struct ist d,
-                                    struct ist *out, size_t max)
+static int promex_dump_ts_header(struct appctx *appctx, const struct promex_metric *metric,
+                                const struct ist name, const struct ist d,
+                                struct ist *out, size_t max)
 {
        struct promex_ctx *ctx = appctx->svcctx;
        struct ist type;
@@ -457,14 +458,14 @@ static int promex_dump_metric_header(struct appctx *appctx, const struct promex_
        return 0;
 }
 
-/* Dump the line for <metric>. It starts by the metric name followed by its
- * labels (proxy name, server name...) between braces and finally its value. If
- * not already done, the header lines are dumped first. It returns 1 on
- * success. Otherwise if <out> length exceeds <max>, it returns 0.
+/* Dump the time series for <metric>. It starts by the metric name followed by
+ * its labels (proxy name, server name...) between braces and finally its
+ * value. If not already done, the header lines are dumped first. It returns 1
+ * on success. Otherwise if <out> length exceeds <max>, it returns 0.
  */
-static int promex_dump_metric(struct appctx *appctx, struct ist prefix,
-                             const struct ist n, const  struct ist desc, const struct promex_metric *metric,
-                             struct field *val, struct promex_label *labels, struct ist *out, size_t max)
+static int promex_dump_ts(struct appctx *appctx, struct ist prefix,
+                         const struct ist n, const  struct ist desc, 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;
@@ -478,7 +479,7 @@ static int promex_dump_metric(struct appctx *appctx, struct ist prefix,
        istcat(&name, (isttest(n) ? n : metric->n), PROMEX_MAX_NAME_LEN);
 
        if ((ctx->flags & PROMEX_FL_METRIC_HDR) &&
-           !promex_dump_metric_header(appctx, metric, name, desc, out, max))
+           !promex_dump_ts_header(appctx, metric, name, desc, out, max))
                goto full;
 
        if (istcat(out, name, max) == -1)
@@ -511,7 +512,7 @@ static int promex_dump_metric(struct appctx *appctx, struct ist prefix,
                goto full;
 
        trash.data = out->len;
-       if (!promex_metric_to_str(&trash, val, max))
+       if (!promex_ts_val_to_str(&trash, val, max))
                goto full;
        out->len = trash.data;
 
@@ -557,9 +558,9 @@ static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
                                val = info[ctx->field_num];
                }
 
-               if (!promex_dump_metric(appctx, prefix, IST_NULL, IST_NULL,
-                                       &promex_global_metrics[ctx->field_num],
-                                       &val, labels, &out, max))
+               if (!promex_dump_ts(appctx, prefix, IST_NULL, IST_NULL,
+                                   &promex_global_metrics[ctx->field_num],
+                                   &val, labels, &out, max))
                        goto full;
 
                ctx->flags |= PROMEX_FL_METRIC_HDR;
@@ -621,11 +622,11 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                                labels[1].value = promex_front_st[ctx->obj_state];
                                                val = mkf_u32(FO_STATUS, state == ctx->obj_state);
 
-                                               if (!promex_dump_metric(appctx, prefix,
-                                                                       promex_st_front_metrics_names[ctx->field_num],
-                                                                       promex_st_metric_desc[ctx->field_num],
-                                                                       &promex_st_metrics[ctx->field_num],
-                                                                       &val, labels, &out, max))
+                                               if (!promex_dump_ts(appctx, prefix,
+                                                                   promex_st_front_metrics_names[ctx->field_num],
+                                                                   promex_st_metric_desc[ctx->field_num],
+                                                                   &promex_st_metrics[ctx->field_num],
+                                                                   &val, labels, &out, max))
                                                        goto full;
                                        }
                                        ctx->obj_state = 0;
@@ -662,11 +663,11 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num];
                        }
 
-                       if (!promex_dump_metric(appctx, prefix,
-                                               promex_st_front_metrics_names[ctx->field_num],
-                                               promex_st_metric_desc[ctx->field_num],
-                                               &promex_st_metrics[ctx->field_num],
-                                               &val, labels, &out, max))
+                       if (!promex_dump_ts(appctx, prefix,
+                                           promex_st_front_metrics_names[ctx->field_num],
+                                           promex_st_metric_desc[ctx->field_num],
+                                           &promex_st_metrics[ctx->field_num],
+                                           &val, labels, &out, max))
                                goto full;
                  next_px:
                        px = px->next;
@@ -717,10 +718,10 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                val = stats[ctx->field_num + ctx->mod_field_num];
                                metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
 
-                               if (!promex_dump_metric(appctx, prefix,
-                                                       ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
-                                                       ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
-                                                       &metric, &val, labels, &out, max))
+                               if (!promex_dump_ts(appctx, prefix,
+                                                   ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
+                                                   ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
+                                                   &metric, &val, labels, &out, max))
                                        goto full;
 
                        next_px2:
@@ -807,11 +808,11 @@ 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, prefix,
-                                                                               promex_st_li_metrics_names[ctx->field_num],
-                                                                               promex_st_metric_desc[ctx->field_num],
-                                                                               &promex_st_metrics[ctx->field_num],
-                                                                               &val, labels, &out, max))
+                                                       if (!promex_dump_ts(appctx, prefix,
+                                                                           promex_st_li_metrics_names[ctx->field_num],
+                                                                           promex_st_metric_desc[ctx->field_num],
+                                                                           &promex_st_metrics[ctx->field_num],
+                                                                           &val, labels, &out, max))
                                                                goto full;
                                                }
                                                ctx->obj_state = 0;
@@ -820,11 +821,11 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                                                val = stats[ctx->field_num];
                                }
 
-                               if (!promex_dump_metric(appctx, prefix,
-                                                       promex_st_li_metrics_names[ctx->field_num],
-                                                       promex_st_metric_desc[ctx->field_num],
-                                                       &promex_st_metrics[ctx->field_num],
-                                                       &val, labels, &out, max))
+                               if (!promex_dump_ts(appctx, prefix,
+                                                   promex_st_li_metrics_names[ctx->field_num],
+                                                   promex_st_metric_desc[ctx->field_num],
+                                                   &promex_st_metrics[ctx->field_num],
+                                                   &val, labels, &out, max))
                                        goto full;
                        }
                        li = NULL;
@@ -888,10 +889,10 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num + ctx->mod_field_num];
                                        metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
 
-                                       if (!promex_dump_metric(appctx, prefix,
-                                                               ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
-                                                               ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
-                                                               &metric, &val, labels, &out, max))
+                                       if (!promex_dump_ts(appctx, prefix,
+                                                           ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
+                                                           ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
+                                                           &metric, &val, labels, &out, max))
                                                goto full;
                                }
                                li = NULL;
@@ -984,11 +985,11 @@ 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, prefix,
-                                                                       promex_st_back_metrics_names[ctx->field_num],
-                                                                       promex_st_metric_desc[ctx->field_num],
-                                                                       &promex_st_metrics[ctx->field_num],
-                                                                       &val, labels, &out, max))
+                                               if (!promex_dump_ts(appctx, prefix,
+                                                                   promex_st_back_metrics_names[ctx->field_num],
+                                                                   promex_st_metric_desc[ctx->field_num],
+                                                                   &promex_st_metrics[ctx->field_num],
+                                                                   &val, labels, &out, max))
                                                        goto full;
                                        }
                                        ctx->obj_state = 0;
@@ -1011,11 +1012,11 @@ 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, prefix,
-                                                                       promex_st_back_metrics_names[ctx->field_num],
-                                                                       promex_st_metric_desc[ctx->field_num],
-                                                                       &promex_st_metrics[ctx->field_num],
-                                                                       &val, labels, &out, max))
+                                               if (!promex_dump_ts(appctx, prefix,
+                                                                   promex_st_back_metrics_names[ctx->field_num],
+                                                                   promex_st_metric_desc[ctx->field_num],
+                                                                   &promex_st_metrics[ctx->field_num],
+                                                                   &val, labels, &out, max))
                                                        goto full;
                                        }
                                        ctx->obj_state = 0;
@@ -1026,11 +1027,11 @@ 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, prefix,
-                                                                       promex_st_back_metrics_names[ctx->field_num],
-                                                                       promex_st_metric_desc[ctx->field_num],
-                                                                       &promex_st_metrics[ctx->field_num],
-                                                                       &val, labels, &out, max))
+                                               if (!promex_dump_ts(appctx, prefix,
+                                                                   promex_st_back_metrics_names[ctx->field_num],
+                                                                   promex_st_metric_desc[ctx->field_num],
+                                                                   &promex_st_metrics[ctx->field_num],
+                                                                   &val, labels, &out, max))
                                                        goto full;
                                        }
                                        ctx->obj_state = 0;
@@ -1097,11 +1098,11 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num];
                        }
 
-                       if (!promex_dump_metric(appctx, prefix,
-                                               promex_st_back_metrics_names[ctx->field_num],
-                                               promex_st_metric_desc[ctx->field_num],
-                                               &promex_st_metrics[ctx->field_num],
-                                               &val, labels, &out, max))
+                       if (!promex_dump_ts(appctx, prefix,
+                                           promex_st_back_metrics_names[ctx->field_num],
+                                           promex_st_metric_desc[ctx->field_num],
+                                           &promex_st_metrics[ctx->field_num],
+                                           &val, labels, &out, max))
                                goto full;
                  next_px:
                        px = px->next;
@@ -1152,10 +1153,10 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                val = stats[ctx->field_num + ctx->mod_field_num];
                                metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
 
-                               if (!promex_dump_metric(appctx, prefix,
-                                                       ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
-                                                       ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
-                                                       &metric, &val, labels, &out, max))
+                               if (!promex_dump_ts(appctx, prefix,
+                                                   ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
+                                                   ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
+                                                   &metric, &val, labels, &out, max))
                                        goto full;
 
                        next_px2:
@@ -1242,11 +1243,11 @@ 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, prefix,
-                                                                               promex_st_srv_metrics_names[ctx->field_num],
-                                                                               promex_st_metric_desc[ctx->field_num],
-                                                                               &promex_st_metrics[ctx->field_num],
-                                                                               &val, labels, &out, max))
+                                                       if (!promex_dump_ts(appctx, prefix,
+                                                                           promex_st_srv_metrics_names[ctx->field_num],
+                                                                           promex_st_metric_desc[ctx->field_num],
+                                                                           &promex_st_metrics[ctx->field_num],
+                                                                           &val, labels, &out, max))
                                                                goto full;
                                                }
                                                ctx->obj_state = 0;
@@ -1294,11 +1295,11 @@ 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, prefix,
-                                                                               promex_st_srv_metrics_names[ctx->field_num],
-                                                                               promex_st_metric_desc[ctx->field_num],
-                                                                               &promex_st_metrics[ctx->field_num],
-                                                                               &val, labels, &out, max))
+                                                       if (!promex_dump_ts(appctx, prefix,
+                                                                           promex_st_srv_metrics_names[ctx->field_num],
+                                                                           promex_st_metric_desc[ctx->field_num],
+                                                                           &promex_st_metrics[ctx->field_num],
+                                                                           &val, labels, &out, max))
                                                                goto full;
                                                }
                                                ctx->obj_state = 0;
@@ -1342,11 +1343,11 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                                val = stats[ctx->field_num];
                                }
 
-                               if (!promex_dump_metric(appctx, prefix,
-                                                       promex_st_srv_metrics_names[ctx->field_num],
-                                                       promex_st_metric_desc[ctx->field_num],
-                                                       &promex_st_metrics[ctx->field_num],
-                                                       &val, labels, &out, max))
+                               if (!promex_dump_ts(appctx, prefix,
+                                                   promex_st_srv_metrics_names[ctx->field_num],
+                                                   promex_st_metric_desc[ctx->field_num],
+                                                   &promex_st_metrics[ctx->field_num],
+                                                   &val, labels, &out, max))
                                        goto full;
                          next_sv:
                                sv = sv->next;
@@ -1412,10 +1413,10 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                        val = stats[ctx->field_num + ctx->mod_field_num];
                                        metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
 
-                                       if (!promex_dump_metric(appctx, prefix,
-                                                               ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
-                                                               ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
-                                                               &metric, &val, labels, &out, max))
+                                       if (!promex_dump_ts(appctx, prefix,
+                                                           ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
+                                                           ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
+                                                           &metric, &val, labels, &out, max))
                                                goto full;
 
                                  next_sv2:
@@ -1494,8 +1495,8 @@ static int promex_dump_module_metrics(struct appctx *appctx, struct promex_modul
                        if (ret < 0)
                                goto error;
 
-                       if (!promex_dump_metric(appctx, prefix, IST_NULL, desc, &metric,
-                                               &val, labels, out, max))
+                       if (!promex_dump_ts(appctx, prefix, IST_NULL, desc, &metric,
+                                           &val, labels, out, max))
                                goto full;
 
                next: