From c53b61c0d6ede807de459aa79cd0ca93d0a3dcde Mon Sep 17 00:00:00 2001 From: jantti Date: Wed, 25 Dec 2024 14:41:17 +0900 Subject: [PATCH] out_loki: fix removing keys defined by labels When key is defined as a Loki label with labels, label_keys or label_map_path, the code is trying to remove them. However, if remove_keys is not defined, it never gets to the part that actually removes them. This looks like an obvious bug to me. I moved the debug message to inside the if (size > 0) statement, because earlier it would only print it if it was actually trying to remove something. So without moving it it would spam it every time. And absence of the message would then indicate size == 0. Not sure if this is the best, though. --- plugins/out_loki/loki.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/out_loki/loki.c b/plugins/out_loki/loki.c index 9722ebc3170..37595497cb5 100644 --- a/plugins/out_loki/loki.c +++ b/plugins/out_loki/loki.c @@ -916,13 +916,14 @@ static int prepare_remove_keys(struct flb_loki *ctx) return -1; } } - size = mk_list_size(patterns); + } + + size = mk_list_size(patterns); + if (size > 0) { flb_plg_debug(ctx->ins, "remove_mpa size: %d", size); - if (size > 0) { - ctx->remove_mpa = flb_mp_accessor_create(patterns); - if (ctx->remove_mpa == NULL) { - return -1; - } + ctx->remove_mpa = flb_mp_accessor_create(patterns); + if (ctx->remove_mpa == NULL) { + return -1; } }