Make sure JSON parser returns Hash - #4106
Conversation
9c0005e to
f0591f0
Compare
|
Additional confirming of the difference of the behavior, <source>
@type sample
tag test.hash
sample {"message": "{\"k\":\"v\"}"}
</source>
<source>
@type sample
tag test.string
sample {"message": "\"HELLO\""}
</source>
<source>
@type sample
tag test.invalid
sample {"message": "HELLO"}
</source>
<source>
@type sample
tag test.array
sample {"message": "[{\"k\":\"v\"}, {\"k2\":\"v2\"}]"}
</source>
<filter test.**>
@type parser
key_name message
<parse>
@type json
</parse>
</filter>
<filter test.**>
@type record_transformer
enable_ruby true
<record>
class ${record.class}
</record>
</filter>
<match test.**>
@type stdout
</match>Before this fixSome patterns result in errors in subsequent processing. After this fixCorrectly, I left a comment in the code about |
|
Sorry for the timing of the v1.16.0 release. I understand that we would not be able to put this fix in v1.16.0. |
There was a problem hiding this comment.
Explanation of the diff
There did not seem to be any particular reason for raise only here.
We should align with parse_params_default.
f0591f0 to
39b72c6
Compare
|
I confirmed the failing tests. They seem to be unstable tests and not related to this fix. |
There was a problem hiding this comment.
Why don't you do this in this PR?
There was a problem hiding this comment.
I thought it should be summarized as fixing the JSON parser.
Since there is no time before the next release, I also wanted to keep the scope of impact as small as possible.
About in_http, I had no choice but to fix it in this PR.
If it looks like I should fix it in this PR, I will try today or tomorrow.
Or I can try to fix it in another PR after this PR is merged.
There was a problem hiding this comment.
It should be done in this PR instead of adding such workaround, since it's considered as a same problem and sometimes such workaround lives long unexpectedly.
I’ll postpone merging this to v1.17.0.
There was a problem hiding this comment.
Thanks for your review. I Understood.
My understanding was that the existing workaround was minimized here, not adding a new workaround.
But certainly, if it is not fixed entirely, it may lead to unnecessary problems.
Especially for MessagePackParser as @custom_parser.
|
TODO: Fix other parsers. |
|
Sorry for the delay. I'm going to fix this for the next release. |
It is wrong for Parser to return a record that is not Hash. Subsequent processing may result in errors. Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
in_http didn't support yield of Parser. The specification assumed that Parser could return Array. However, this is wrong. Parser shouldn't return Array. Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
Config to reproduce:
<source>
@type sample
tag test.array
sample {"message": "[{\"k\":\"v\"}, {\"k2\":\"v2\"}]"}
</source>
<filter test.**>
@type parser
key_name message
<parse>
@type json
</parse>
</filter>
<match test.**>
@type stdout
</match>
Result:
2023-03-21 23:24:52.004470792 +0900 test.array: {"k":"v"}
2023-03-21 23:24:52.004470792 +0900 test.array: {"k":"v"}
...
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
39b72c6 to
940624e
Compare
|
I have add new PR for this |
Which issue(s) this PR fixes:
Fixes #4100
What this PR does / why we need it:
Make sure JSON parser returns
Hash.It is wrong for Parser to return a record that is not Hash.
Subsequent processing may result in errors.
The result of parsing JSON can be a value other than Hash.
Originally, the data represented by JSON was not limited to Hash.
The current implementation of
JSONParserdoes not appear to have sufficiently considered this.We need to consider carefully the specification of the case where raw data can not be parsed as
Hash.The currently intended usecases appears to be
HashorArrayofHash.We should consider only these 2 patterns as parsable for now.
in_httpassumed that Parser could return Array.Therefore, it needed to be fixed along with this.
MessagePackParserappears to have the same issue. (Not fixed in this PR.)Docs Changes:
Not needed.
Release Note:
Same as the title.
Difference
Case: No subsequent processing
Config
Operation
Result before this fix
Result after this fix
Case: With subsequent filter processing
Config
Operation
Result before this fix
Result after this fix