diff --git a/filter/parser.md b/filter/parser.md index e3636e05..7eef62ec 100644 --- a/filter/parser.md +++ b/filter/parser.md @@ -160,6 +160,8 @@ Without `reserve_data`, the result is: # output data: {"user":1,"num":2} ``` +`reserve_data` also changes what happens to a record that cannot be parsed. See [`emit_invalid_record_to_error`](#emitinvalidrecordtoerror) for details. + ### remove\_key\_name\_field | type | default | version | @@ -264,6 +266,41 @@ You can rescue unexpected format logs in the `@ERROR` label. If you want to ignore these errors, set `false`. +Whether an invalid record is also passed to the next filter or output depends on [`reserve_data`](#reservedata) and on the case: + +| invalid case | `reserve_data false` | `reserve_data true` | +| :--- | :--- | :--- | +| key does not exist | record is discarded | original record is passed through | +| the format is not matched | record is discarded | original record is passed through, unparsed | +| an unexpected error | record is discarded | record is discarded | + +"Key does not exist" also covers a `key_name` field whose value is `null`. "The format is not matched" means that the parser returns no record, as the `json` and `regexp` parsers do for a value they cannot parse. "An unexpected error" means that the parser raises an error. For example, the `json` and `regexp` parsers raise an error when the time field cannot be parsed with `time_format`. The `regexp` parser also raises an error on an invalid byte sequence while [`replace_invalid_sequence`](#replaceinvalidsequence) is `false`. A record whose parsing raises an error is discarded even with `reserve_data true`. + +`emit_invalid_record_to_error` does not change this. Since it is `true` by default, a record passed through with `reserve_data true` is also emitted to the `@ERROR` label, so the same record goes to both. If you only want to pass such records through, set `emit_invalid_record_to_error false`: + +```text + + @type parser + key_name log + reserve_data true + emit_invalid_record_to_error false + + @type json + + +``` + +With above configuration, here is the result for a value which is not JSON: + +```text +# input data: {"key":"value","log":"not json"} +# output data: {"key":"value","log":"not json"} +``` + +With above configuration, a record whose parsing raises an error is discarded without an error event or a log. + +If [`hash_value_field`](#hashvaluefield) is set, an empty hash is stored in that field of a record passed through. The record emitted to the `@ERROR` label does not get the empty hash. + ## FAQ ### `suppress_parse_error_log` is missing. What are the alternatives?