Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions filter/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
<filter foo.bar>
@type parser
key_name log
reserve_data true
emit_invalid_record_to_error false
<parse>
@type json
</parse>
</filter>
```

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?
Expand Down