Skip to content

Commit

Permalink
filter_nest: Add config property suppress_warnings to skip lift errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
drbugfinder-work committed Dec 9, 2024
1 parent 412d3ea commit 4ad29e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/filter_nest/nest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}
};

Expand Down
1 change: 1 addition & 0 deletions plugins/filter_nest/nest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4ad29e2

Please sign in to comment.