Skip to content

Commit bfc027e

Browse files
committed
parser_json: use JSON as fallback parser instead of Yajl for performance
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 24f08be commit bfc027e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/fluent/plugin/parser_json.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def configure_json_parser(name)
5252
when :oj
5353
return [Oj.method(:load), Oj::ParseError] if Fluent::OjOptions.available?
5454

55-
log&.info "Oj is not installed, and failing back to Yajl for json parser"
56-
configure_json_parser(:yajl)
57-
when :json then [JSON.method(:load), JSON::ParserError]
55+
log&.info "Oj is not installed, and failing back to JSON for json parser"
56+
configure_json_parser(:json)
57+
when :json then [JSON.method(:parse), JSON::ParserError]
5858
when :yajl then [Yajl.method(:load), Yajl::ParseError]
5959
else
6060
raise "BUG: unknown json parser specified: #{name}"

test/plugin/test_parser_json.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010

1111
sub_test_case "configure_json_parser" do
1212
data("oj", [:oj, [Oj.method(:load), Oj::ParseError]])
13-
data("json", [:json, [JSON.method(:load), JSON::ParserError]])
13+
data("json", [:json, [JSON.method(:parse), JSON::ParserError]])
1414
data("yajl", [:yajl, [Yajl.method(:load), Yajl::ParseError]])
1515
def test_return_each_loader((input, expected_return))
1616
result = @parser.instance.configure_json_parser(input)
@@ -28,12 +28,12 @@ def test_fall_back_oj_to_yajl_if_oj_not_available
2828

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

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

0 commit comments

Comments
 (0)