Skip to content

Keep a matched record when the parsed time is nil - #127

Merged
Watson1978 merged 1 commit into
fluent:masterfrom
arpitjain099:fix/grok-keep-record-with-nil-time
Nov 24, 2026
Merged

Watson1978 merged 1 commit into
fluent:masterfrom
arpitjain099:fix/grok-keep-record-with-nil-time

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

With grok_pattern and estimate_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 the NoneParser fallback emits the raw line and grok_failure_key reports that no pattern matched when one did.

parse_by returns a nil record on a real miss, so checking the record alone separates the two. On %{IP:ip_address} against 127.0.0.1 with grok_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 NoneParser fallback now follows the estimate_current_event of the grok_pattern parser. With an explicit estimate_current_event false, an unmatched line also yields the raw record with a nil time. With these settings, in_tail and in_tcp warn and drop both an unmatched line and a match with no timestamp. They do the same with @type regexp. With multiline_grok and no multiline_start_regexp, in_tail can keep an unmatched line in its buffer.

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/fluent/plugin/parser_grok.rb Resolved
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>
@arpitjain099
arpitjain099 force-pushed the fix/grok-keep-record-with-nil-time branch from 8779a63 to 00e4261 Compare November 22, 2026 08:40
@Watson1978 Watson1978 added the bug label Nov 24, 2026

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Watson1978
Watson1978 merged commit 6fdfa54 into fluent:master Nov 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants