From 4ad29e201c0871fb097b1d9fef849ae11af9c4d2 Mon Sep 17 00:00:00 2001 From: Richard Treu Date: Mon, 9 Dec 2024 11:20:05 +0100 Subject: [PATCH] filter_nest: Add config property suppress_warnings to skip lift errors In case of lift, if there's no valid/matching key found and the content cannot be lifted, the filter will throw an error. However, there can be scenarios, where it is intended that sometimes the lift filter does not find a match (like two different kinds of logs with the same tag). Then these warnings should be disableable by the user. This commit adds an option to suppress these kind of warnings. Signed-off-by: Richard Treu --- plugins/filter_nest/nest.c | 16 +++++++++++++--- plugins/filter_nest/nest.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/filter_nest/nest.c b/plugins/filter_nest/nest.c index 2ace2137e81..51b3fbdfe18 100644 --- a/plugins/filter_nest/nest.c +++ b/plugins/filter_nest/nest.c @@ -146,6 +146,9 @@ static int configure(struct filter_nest_ctx *ctx, ctx->prefix = flb_strdup(kv->val); ctx->prefix_len = flb_sds_len(kv->val); ctx->remove_prefix = true; + } + else if (strcasecmp(kv->key, "suppress_warnings") == 0) { + continue; } else { flb_plg_error(ctx->ins, "Invalid configuration key '%s'", kv->key); return -1; @@ -385,9 +388,11 @@ static inline bool is_kv_to_lift(msgpack_object_kv * kv, } memcpy(tmp, key, klen); tmp[klen] = '\0'; - flb_plg_warn(ctx->ins, "Value of key '%s' is not a map. " - "Will not attempt to lift from here", - tmp); + if (ctx->suppress_warnings == false) { + flb_plg_warn(ctx->ins, "Value of key '%s' is not a map. " + "Will not attempt to lift from here", + tmp); + } flb_free(tmp); return false; } @@ -757,6 +762,11 @@ static struct flb_config_map config_map[] = { 0, FLB_FALSE, 0, "Remove prefix from affected keys if it matches this string" }, + { + FLB_CONFIG_MAP_BOOL, "suppress_warnings", "false", + 0, FLB_TRUE, offsetof(struct filter_nest_ctx, suppress_warnings), + "Suppress warnings about non-matching keys" + }, {0} }; diff --git a/plugins/filter_nest/nest.h b/plugins/filter_nest/nest.h index 678c79a836b..672f58e3c57 100644 --- a/plugins/filter_nest/nest.h +++ b/plugins/filter_nest/nest.h @@ -35,6 +35,7 @@ struct filter_nest_ctx int key_len; char *prefix; int prefix_len; + bool suppress_warnings; // nest struct mk_list wildcards; int wildcards_cnt;