Skip to content

Commit

Permalink
Merge pull request #1304 from fluent/port-1239-to-v0.12
Browse files Browse the repository at this point in the history
Port 1239 oj mode changes to v0.12
  • Loading branch information
repeatedly committed Nov 4, 2016
2 parents cd45819 + 703ee38 commit d915afa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/fluent/env.rb
Expand Up @@ -18,6 +18,7 @@ module Fluent
DEFAULT_CONFIG_PATH = ENV['FLUENT_CONF'] || '/etc/fluent/fluent.conf'
DEFAULT_PLUGIN_DIR = ENV['FLUENT_PLUGIN'] || '/etc/fluent/plugin'
DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
DEFAULT_OJ_OPTIONS = {bigdecimal_load: :float, mode: :compat}
DEFAULT_LISTEN_PORT = 24224
DEFAULT_FILE_PERMISSION = 0644
DEFAULT_DIR_PERMISSION = 0755
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/formatter.rb
Expand Up @@ -15,6 +15,7 @@
#

require 'fluent/configurable'
require 'fluent/env'
require 'fluent/registry'
require 'fluent/mixin'

Expand Down Expand Up @@ -141,7 +142,7 @@ def configure(conf)
begin
raise LoadError unless @json_parser == 'oj'
require 'oj'
Oj.default_options = {mode: :compat}
Oj.default_options = Fluent::DEFAULT_OJ_OPTIONS
@dump_proc = Oj.method(:dump)
rescue LoadError
@dump_proc = Yajl.method(:dump)
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/parser.rb
Expand Up @@ -22,6 +22,7 @@
require 'fluent/config/error'
require 'fluent/config/element'
require 'fluent/configurable'
require 'fluent/env'
require 'fluent/engine'
require 'fluent/registry'
require 'fluent/time'
Expand Down Expand Up @@ -260,7 +261,7 @@ def configure(conf)
begin
raise LoadError unless @json_parser == 'oj'
require 'oj'
Oj.default_options = {bigdecimal_load: :float, mode: :strict}
Oj.default_options = Fluent::DEFAULT_OJ_OPTIONS
@load_proc = Oj.method(:load)
@error_class = Oj::ParseError
rescue LoadError
Expand Down
12 changes: 12 additions & 0 deletions test/test_formatter.rb
Expand Up @@ -29,6 +29,10 @@ def record
{'message' => 'awesome'}
end

def symbolic_record
{:message => :awesome}
end

def with_timezone(tz)
oldtz, ENV['TZ'] = ENV['TZ'], tz
yield
Expand Down Expand Up @@ -138,6 +142,14 @@ def test_format(data)
assert_equal("#{Yajl.dump(record)}\n", formatted)
end

data('oj' => 'oj', 'yajl' => 'yajl')
def test_format_with_symbolic_record(data)
@formatter.configure('json_parser' => data)
formatted = @formatter.format(tag, @time, symbolic_record)

assert_equal("#{JSON.generate(record)}\n", formatted)
end

data('oj' => 'oj', 'yajl' => 'yajl')
def test_format_with_include_tag(data)
@formatter.configure('include_tag_key' => 'true', 'tag_key' => 'foo', 'json_parser' => data)
Expand Down
8 changes: 8 additions & 0 deletions test/test_parser.rb
Expand Up @@ -421,6 +421,14 @@ def test_parse_without_time(data)
}
end

data('oj' => 'oj', 'yajl' => 'yajl')
def test_parse_with_colon_string(data)
@parser.configure('json_parser' => data)
@parser.parse('{"time":1362020400,"log":":message"}') { |time, record|
assert_equal(record['log'], ':message')
}
end

data('oj' => 'oj', 'yajl' => 'yajl')
def test_parse_with_invalid_time(data)
@parser.configure('json_parser' => data)
Expand Down

0 comments on commit d915afa

Please sign in to comment.