Skip to content

filter_parser: describe how reserve_data handles invalid records - #733

Merged
Watson1978 merged 2 commits into
fluent:1.0from
NopeCharon:filter-parser-invalid-record-reserve-data
Nov 30, 2026
Merged

Watson1978 merged 2 commits into
fluent:1.0from
NopeCharon:filter-parser-invalid-record-reserve-data

Conversation

@NopeCharon

@NopeCharon NopeCharon commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

The emit_invalid_record_to_error section of the parser filter article lists the three invalid cases. It does not say that reserve_data changes what happens to the record. This adds the explanation planned in #442:

  • A table of what happens to an invalid record in each case, with reserve_data false and reserve_data true. With reserve_data true, a record whose key_name is missing passes through as is. So does a record whose value the parser returns no record for. A record whose parsing raises an error is still discarded. A key_name field whose value is null counts as a missing key.
  • What "the format is not matched" and "an unexpected error" mean. The first is when the json and regexp parsers yield no record for a value. The second is when the parser raises, for example on a time field that cannot be parsed with time_format, or, with the regexp parser, on an invalid byte sequence while replace_invalid_sequence is false.
  • emit_invalid_record_to_error defaults to true, so a record passed through with reserve_data true is also emitted to @ERROR. The section shows a configuration that only passes the records through, with its result. With that configuration, a record whose parsing raises an error is dropped without an error event or a log.
  • With hash_value_field, a record passed through gets an empty hash in that field. The record emitted to @ERROR does not get the empty hash.
  • The reserve_data section now points to this explanation.

The behavior described comes from filter_stream, filter_one_record and handle_parsed in lib/fluent/plugin/filter_parser.rb. Parse errors from time parsing come from Parser#parse_time.

Fixes #442

The emit_invalid_record_to_error section listed the three invalid cases,
but did not say that reserve_data changes what happens to the record.

In filter_parser, with reserve_data true, a record whose key_name does
not exist is passed through as it is, and so is a record whose value the
parser returns no record for. A record whose parsing raises an error,
such as a time field that does not match time_format, is still
discarded. Since emit_invalid_record_to_error is true by default, a
record passed through is also emitted to the @error label.

Add a table of the behavior per case, explain the cases and the
duplication with the default emit_invalid_record_to_error, and show a
configuration that only passes the records through. Also point to it
from the reserve_data section.

Fixes fluent#442

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
@netlify

netlify Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

👷 Deploy request for fluentd-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d7f4385

@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 documenting this. I checked the table, the example output, and the hash_value_field note against Fluentd v1.20.1 and the current master, and they match. The four links also match the heading anchors on docs.fluentd.org.

One part needs a fix. The invalid byte sequence example of "an unexpected error" depends on the parser, and it does not apply to the json parser. The other comment is optional.

Comment thread filter/parser.md Resolved
Comment thread filter/parser.md Resolved
@Watson1978 Watson1978 added the bug Something isn't working label Nov 29, 2026
The invalid byte sequence example of an unexpected error applies to the
regexp parser, not to the json parser, which treats such a value as
not matched or parses it. Name the regexp parser for it, and say that
the json and regexp parsers raise when the time field cannot be parsed
with time_format.

Also note that a key_name field whose value is null is handled as a
missing key, that with emit_invalid_record_to_error false a record
whose parsing raises an error is dropped without an error event or a
log, and that the record emitted to @error does not get the empty
hash_value_field hash.

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>

@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 both suggestions. I reran the cases from my previous review on Fluentd v1.20.1 and the current master, and the results match the updated text. LGTM.

@Watson1978
Watson1978 merged commit c7a6eda into fluent:1.0 Nov 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unclear description of logic that happens on an error in the "parser filter"

2 participants