fluent-plugin-json-in-json-2 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/fluent-plugin-json-in-json.gemspec +1 -1
- data/lib/fluent/plugin/parser_json_in_json.rb +10 -6
- data/test/test_parser.rb +14 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d1b8a01f1186485694e04e9aab84ba22d292fb1
|
4
|
+
data.tar.gz: b6816327d8350b8dc61c3b29f1fbddfc6990091f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e63efe8408c30193f928ab9b35a622529f8efdfa7ca6d102417e78b6bb372b7ee484c34a07f7755a0a797e128126f26b01546fa435cb9ae7c6022abd892107f
|
7
|
+
data.tar.gz: d51d6473474ee28621c0def79063df6f4a18874586df990e056c6163bf84e971fbda2d5b6688fd6fdfee2cdad8dfee9654e09a0eba63adec11df11b891355bad
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "fluent-plugin-json-in-json-2"
|
4
|
-
spec.version = "1.0.
|
4
|
+
spec.version = "1.0.2"
|
5
5
|
spec.authors = ["Gavin M. Roy", "Arcadiy Ivanov", "Alik Khilazhev"]
|
6
6
|
spec.email = ["gavinmroy@gmail.com", "arcadiy@ivanov.biz", "alikhil@mail.ru"]
|
7
7
|
spec.description = %q{Parser plugin that parses JSON attributes with JSON strings in them}
|
@@ -24,12 +24,16 @@ module Fluent
|
|
24
24
|
|
25
25
|
record.each do |k, v|
|
26
26
|
if v.is_a?(String) && /^\s*(\{|\[)/ =~ v
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
begin
|
28
|
+
deserialized = Yajl.load(v)
|
29
|
+
if deserialized.is_a?(Hash)
|
30
|
+
values.merge!(deserialized)
|
31
|
+
record.delete k
|
32
|
+
elsif deserialized.is_a?(Array)
|
33
|
+
values[k] = deserialized
|
34
|
+
end
|
35
|
+
rescue Yajl::ParseError
|
36
|
+
# continue if failed to parse record
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
data/test/test_parser.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
require 'fluent/test/driver/parser'
|
3
3
|
require 'fluent/plugin/parser_json_in_json'
|
4
|
+
require 'yajl'
|
4
5
|
|
5
6
|
class JsonInJsonParserTest < ::Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -43,7 +44,7 @@ class JsonInJsonParserTest < ::Test::Unit::TestCase
|
|
43
44
|
def test_parse_string_time()
|
44
45
|
@parser.configure('time_format' => '%Y-%m-%dT%H:%M:%S.%NZ', 'keep_time_key' => 'true')
|
45
46
|
@parser.instance.parse('{"log":"2018-06-26 13:20:44.075 INFO --- [pool-8-thread-3] outgoing","stream":"stdout","time":"2018-06-26T13:20:44.076022960Z"}') { |time, record|
|
46
|
-
assert_equal(event_time('2018-06-26 13:20:44.076022960
|
47
|
+
assert_equal(event_time('2018-06-26 13:20:44.076022960').to_f, time.to_f)
|
47
48
|
assert_equal({
|
48
49
|
'log'=>'2018-06-26 13:20:44.075 INFO --- [pool-8-thread-3] outgoing',
|
49
50
|
'stream'=>'stdout',
|
@@ -51,4 +52,16 @@ class JsonInJsonParserTest < ::Test::Unit::TestCase
|
|
51
52
|
}, record)
|
52
53
|
}
|
53
54
|
end
|
55
|
+
|
56
|
+
def test_yajl_load()
|
57
|
+
@parser.configure({})
|
58
|
+
@parser.instance.parse('{ "log": " [ msg ] messoge [ k ]", "stream": "stdout"}') { |time, record|
|
59
|
+
assert_equal({
|
60
|
+
'log'=> ' [ msg ] messoge [ k ]',
|
61
|
+
'stream'=>'stdout',
|
62
|
+
}, record)
|
63
|
+
}
|
64
|
+
# Yajl.load('["kek":1}')
|
65
|
+
end
|
66
|
+
|
54
67
|
end
|