Parsing behavior in this library was originally designed for a different data model than the one we now have. The expected usage of body
and attributes
have been redefined. As such, the behavior of parsers should be reevaluated.
This is not my first attempt to propose changes to the way parsers behave. I believe my previous attempts have been too focused on proposing changes, which is difficult to do without lengthy explanations of the current behavior. The following is instead meant to be read as a standalone proposal for how parsers should behave. Please read accordingly.
I suggest the following would be ideal behavior:
- Parsing should be non-destructive by default.
- Parsing should be destructive only when the same value is specified for both
parse_from
and parse_to
.
- The
parse_from
setting should default to body
.
- The
parse_to
setting should default to attributes
.
- The
preserve_to
setting should not exist.
Rationale
- Parsing should be non-destructive by default.
The primary purpose of parsing operations is to isolate information. Where the extracted information should be placed is a secondary, but obvious, concern. However, what happens to the original value is easily overlooked. As a general principle, destruction of the original value should require intentional configuration.
- Parsing should be destructive only when the same value is specified for both
parse_from
and parse_to
.
A somewhat common use case involves applying structure to an unstructured log. For example, when a user extracts information from a line of text, they may wish keep only the key value pairs they have isolated. When this is the case, an intuitive choice is to overwrite the original value. This should be supported but should require explicit configuration.
- The
parse_from
setting should default to body
.
The body typically contains an unstructured log. Parsing this value is the most common parsing use case. Therefore, parsers should default to parsing the body.
- The
parse_to
setting should default to attributes
.
The result of a parsing operation is a structured object. This is true of all parsers that have a parse_to
field.
The data model strongly encourages that structured data belong in attributes
, so this is a natural default value for parse_to
.
Additionally, the default value for parse_to
should be different than that of parse_from
, else we have a situation where parsing operations are destructive by default.
- The
preserve_to
setting should not exist.
If parsing is non-destructive by default, there is no need to provide a special setting for preservation. In the case where a user wishes to "back up" a value and destroy the original, they can do so by copying or moving the value before parsing.