-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PatternJsonProvider: Inconsistent handling of configuration error #686
Milestone
Comments
This works for me as long as the implementation isn't too complex, and logstash-logback-encoder can easily detect errors. logback itself doesn't complain about invalid patterns until they are used, so I'm not sure how easy it will be to detect them. |
brenuart
added a commit
that referenced
this issue
Nov 3, 2021
…s instead of logging an ERROR status AbstractJsonPatternParser now throws a JsonPatternException in case of invalid pattern. It is up to the AbstractPatternLayoutJsonProvider to catch the exception, log an error status and decide how it should behave. Invalid PatternLayout formats are now detected and throw a JsonPatternException as well. Detection is done by configuring the PatternLayout instances with a custom Logback context that throws an exception when an ERROR status is logged. The former implementation used to ignore fields with an invalid pattern layout while keeping the other. This results in a partial JSON output with only the valid fields. This behaviour is now changed and the provider reverts to producing nothing in case of bad configuration. These changes address issue #686.
brenuart
added a commit
that referenced
this issue
Nov 3, 2021
…s instead of logging an ERROR status AbstractJsonPatternParser now throws a JsonPatternException in case of invalid pattern. It is up to the AbstractPatternLayoutJsonProvider to catch the exception, log an error status and decide how it should behave. Invalid PatternLayout formats are now detected and throw a JsonPatternException as well. Detection is done by configuring the PatternLayout instances with a custom Logback context that throws an exception when an ERROR status is logged. The former implementation used to ignore fields with an invalid pattern layout while keeping the other. This results in a partial JSON output with only the valid fields. This behaviour is now changed and the provider reverts to producing nothing in case of bad configuration. These changes address issue #686.
brenuart
added a commit
that referenced
this issue
Nov 8, 2021
… instead of logging an ERROR status (#691) AbstractJsonPatternParser now throws a JsonPatternException in case of invalid pattern. It is up to the AbstractPatternLayoutJsonProvider to catch the exception, log an error status and decide how it should behave. Invalid PatternLayout formats are now detected and throw a JsonPatternException as well. Detection is done by inspecting the parsed output returned by the PatternLayout when it is started, looking for the special %PARSER_ERROR marker inserted when it encounters an error. The previous implementation used to ignore fields with an invalid pattern layout while keeping the other. This results in a partial JSON output with only the valid fields. This behaviour is now changed and the provider reverts to producing nothing in case of bad configuration. These changes address issue #686.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The behaviour of the PatternJsonProvider when it is given an invalid pattern differs depending on the type of error. Here are a few examples:
(1) Invalid conversion word in Pattern layout
The following JSON pattern refers to the log message using the
%message
conversion word instead of%msg
:The following error status is emitted when the provider is started but no exception is thrown:
The provider is started and produces the following JSON output when serialising log events:
(2) Syntax error in Pattern Layout
The following JSON pattern contains a syntax error (conversion word missing after
%
):This is causing an ERROR status with an exception when the provider is started:
Unlike the previous case, the message field is now populated at runtime with an empty string instead of a "%PARSE_ERROR" special value:
(3) Invalid JSON pattern
The PatternJsonProvider accepts a valid JSON string for its "pattern" property. If the supplied value is not a valid JSON, an ERROR status is logged and the provider defaults to an empty pattern, producing nothing at runtime.
Example (missing closing quote):
Produces the following ERROR when the provider is started:
And the following JSON is produced at runtime:
According to me, replacing the pattern with an error marker like
%PARSE_ERROR
is not a good option. This will produce a valid JSON output at runtime in most cases making it difficult to notice something went wrong with the configuration. Even worst if it is wrapped with a#asLong
operation like this:{ "age": "#asLong(%relative)" }
. The operation will receive the "%PARSE_ERROR" string and will fail to convert it to a long defaulting tonull
.IMHO, the best strategy is to log an ERROR status in all cases and don't produce anything at runtime. This is the behaviour adopted by most of the other JsonProvider when their configuration is wrong: they simply revert producing nothing.
@philsttr What's your opinion?
The text was updated successfully, but these errors were encountered: