Repository navigation
Keep a matched record when the parsed time is nil - #127
Conversation
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the fix. I tested 8779a63 with Fluentd 1.20.1. The new test fails on master and passes here. With grok_pattern and estimate_current_event false, a match that captures no timestamp now yields the captured fields and a nil time. filter_parser keeps the original event time for that match.
My only requested code change is in the inline comment about the fallback for unmatched lines.
With those parser settings, in_tail, in_tcp, in_udp and in_syslog now warn and drop a match that captures no timestamp by default. With the requested change, they would also warn and drop an unmatched line. On master, the fallback emitted both cases with the current time. This drop behavior is expected for these inputs and matches @type regexp.
GrokParser#parse only yields when both the time and the record are set, but Fluentd's regexp parser returns a nil time whenever it has no time field to read, which is what estimate_current_event false asks for. A match then looks exactly like a miss, so the record is discarded, the NoneParser fallback emits the raw line, and grok_failure_key claims that no pattern matched. parse_by returns a nil record on a real miss, so testing the record on its own separates the two cases. The <grok> section path does not forward estimate_current_event to the inner parser at all, so only the grok_pattern path changes here. configure now copies estimate_current_event from the grok_pattern parser onto the NoneParser fallback, so a matched line that carries no timestamp and an unmatched line agree. The value comes from that parser rather than from the plugin, because an owner such as in_exec defaults the plugin to false while the inner parser keeps true, and reading the plugin would leave only unmatched lines with a nil time. Without a grok_pattern parser the fallback keeps its default. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
8779a63 to
00e4261
Compare
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for applying the change. I tested 00e4261 with Fluentd 1.20.1. All 53 tests pass, and the new unmatched-line test fails without the configure change. With grok_pattern and an explicit estimate_current_event false, filter_parser now keeps the original event time for both a match with no timestamp and an unmatched line. When the option is not set, the output is the same as on master. This includes in_exec and out_exec_filter. The <grok> section path also behaves as on master.
My earlier request also changes one in_tail case. I am fine with it, and no code change is needed. I tested multiline_grok with estimate_current_event false, without multiline_start_regexp or emit_unmatched_lines. The input was miss followed by five lines with a timestamp. With \A before the timestamp in the pattern, all six lines stayed in the buffer. They were dropped with a warning at shutdown. Without \A, the five timestamped records came through, and miss was dropped with no warning about it. On master, the fallback emitted miss as its own record. Core @type multiline without format_firstline gave the same results as this commit.
With
grok_patternandestimate_current_event false, grok on master discards the parsed fields when a match does not capture the configured time key. Fluentd's regexp parser returns a nil time when there is no time field to read, which is what that option asks for, and the old code returns the matched fields only when both the time and the record are set. A match is then indistinguishable from a miss, so theNoneParserfallback emits the raw line andgrok_failure_keyreports that no pattern matched when one did.parse_byreturns a nil record on a real miss, so checking the record alone separates the two. On%{IP:ip_address}against127.0.0.1withgrok_failure_key grok_failure, the result goes from[current_time, {"message"=>"127.0.0.1", "grok_failure"=>"No grok pattern matched"}]to[nil, {"ip_address"=>"127.0.0.1"}]. The<grok>section path never forwards the option to the inner parser, so it is unaffected.The
NoneParserfallback now follows theestimate_current_eventof thegrok_patternparser. With an explicitestimate_current_event false, an unmatched line also yields the raw record with a nil time. With these settings,in_tailandin_tcpwarn and drop both an unmatched line and a match with no timestamp. They do the same with@type regexp. Withmultiline_grokand nomultiline_start_regexp,in_tailcan keep an unmatched line in its buffer.