From b6668b157b2310cd155f1c1ee5f70b4503f73017 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 8 Jan 2022 17:06:35 +0900 Subject: [PATCH] filter_rewrite_tag: set 'keep' before emitting(#4518) 'keep' is set when process_record returns FLB_TRUE. It indicates some records can be dropped. e.g. If first record is not matched regex, 'keep' is not initialized. 'keep' is undefined and it can be different from FLB_TRUE. It causes the first record is lost even if user sets 'KEEP' is true. Signed-off-by: Takahiro Yamashita --- plugins/filter_rewrite_tag/rewrite_tag.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/filter_rewrite_tag/rewrite_tag.c b/plugins/filter_rewrite_tag/rewrite_tag.c index aff6953b6f6..df37fef5d81 100644 --- a/plugins/filter_rewrite_tag/rewrite_tag.c +++ b/plugins/filter_rewrite_tag/rewrite_tag.c @@ -323,6 +323,9 @@ static int process_record(const char *tag, int tag_len, msgpack_object map, mk_list_foreach(head, &ctx->rules) { rule = mk_list_entry(head, struct rewrite_rule, _head); + if (rule) { + *keep = rule->keep_record; + } ret = flb_ra_regex_match(rule->ra_key, map, rule->regex, &result); if (ret < 0) { /* no match */ rule = NULL; @@ -359,7 +362,7 @@ static int process_record(const char *tag, int tag_len, msgpack_object map, return FLB_FALSE; } - *keep = rule->keep_record; + return FLB_TRUE; }