Skip to content

Commit

Permalink
parser_json: use JSON as fallback parser instead of Yajl for performance
Browse files Browse the repository at this point in the history
Signed-off-by: Shizuo Fujita <[email protected]>
  • Loading branch information
Watson1978 committed Jan 31, 2025
1 parent 24f08be commit 9b3887f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/parser_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def configure_json_parser(name)
when :oj
return [Oj.method(:load), Oj::ParseError] if Fluent::OjOptions.available?

log&.info "Oj is not installed, and failing back to Yajl for json parser"
configure_json_parser(:yajl)
log&.info "Oj is not installed, and failing back to JSON for json parser"
configure_json_parser(:json)
when :json then [JSON.method(:load), JSON::ParserError]
when :yajl then [Yajl.method(:load), Yajl::ParseError]
else
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_parser_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def test_fall_back_oj_to_yajl_if_oj_not_available

result = @parser.instance.configure_json_parser(:oj)

assert_equal [Yajl.method(:load), Yajl::ParseError], result
assert_equal [JSON.method(:load), JSON::ParserError], result
logs = @parser.logs.collect do |log|
log.gsub(/\A\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4} /, "")
end
assert_equal(
["[info]: Oj is not installed, and failing back to Yajl for json parser\n"],
["[info]: Oj is not installed, and failing back to JSON for json parser\n"],
logs
)
end
Expand Down

0 comments on commit 9b3887f

Please sign in to comment.