From 4e0e77ba1f6a5c8fccf89791bdaa4d673909dfd9 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 1 Aug 2024 08:24:05 -0600 Subject: [PATCH] filter_log_to_metrics: if add_label is not record accessor, use the string Signed-off-by: Eduardo Silva --- plugins/filter_log_to_metrics/log_to_metrics.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/filter_log_to_metrics/log_to_metrics.c b/plugins/filter_log_to_metrics/log_to_metrics.c index ce68e16da06..2eced31b5b4 100644 --- a/plugins/filter_log_to_metrics/log_to_metrics.c +++ b/plugins/filter_log_to_metrics/log_to_metrics.c @@ -406,7 +406,12 @@ static int fill_labels(struct log_to_metrics_ctx *ctx, char **label_values, label_iterator_start = NUMBER_OF_KUBERNETES_LABELS; } - for (i = label_iterator_start; i < label_counter; i++){ + for (i = label_iterator_start; i < label_counter; i++) { + if (*label_accessors[i] != '$'){ + snprintf(label_values[i], MAX_LABEL_LENGTH - 1, "%s", label_accessors[i]); + continue; + } + ra = flb_ra_create(label_accessors[i], FLB_TRUE); if (!ra) { flb_warn("invalid record accessor key, aborting"); @@ -415,9 +420,10 @@ static int fill_labels(struct log_to_metrics_ctx *ctx, char **label_values, rval = flb_ra_get_value_object(ra, map); if (!rval) { - /* Set value to empty string, so the value will be dropped in Cmetrics*/ - label_values[i][0] = '\0'; - } else if (rval->type == FLB_RA_STRING) { + /* Set value to empty string, so the value will be dropped in Cmetrics*/ + label_values[i][0] = '\0'; + } + else if (rval->type == FLB_RA_STRING) { snprintf(label_values[i], MAX_LABEL_LENGTH - 1, "%s", rval->val.string); }