logstash-codec-json_lines 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/logstash/codecs/json_lines.rb +18 -10
- data/logstash-codec-json_lines.gemspec +2 -2
- data/spec/codecs/json_lines_spec.rb +37 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1506140c8e501d6674a9240c5e0e943dbad0adc
|
4
|
+
data.tar.gz: 86a5df4679925793a96dd8d41093c2ca69b6dabc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f3ea023534e310a9b3215909118af6b0709f4e20ec34b450b556ac2c97f8f05ae830e46e4ada813ebb4d3b720d1fec3bce83351a9ec4eab2d307321c51084a
|
7
|
+
data.tar.gz: c97a1312cb5c1f89a0c8763e1da59f25ea2fa942a5da7008422920e51f85578ccc9981b3556bf1649d8699241b5f2b71cc5a36c310e77e2616b373ce9e483835
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 2.1.0
|
2
|
+
- Backward compatible support for `Event#from_json` method https://github.com/logstash-plugins/logstash-codec-json_lines/pull/19
|
3
|
+
|
1
4
|
## 2.0.5
|
2
5
|
- Directly use buftok to avoid indirection through the line codec https://github.com/logstash-plugins/logstash-codec-json_lines/pull/18
|
3
6
|
|
@@ -36,26 +36,34 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
|
|
36
36
|
@converter.logger = @logger
|
37
37
|
end
|
38
38
|
|
39
|
-
def decode(data)
|
39
|
+
def decode(data, &block)
|
40
40
|
@buffer.extract(data).each do |line|
|
41
|
-
|
41
|
+
parse(@converter.convert(line), &block)
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
44
44
|
|
45
45
|
def encode(event)
|
46
46
|
# Tack on a @delimiter for now because previously most of logstash's JSON
|
47
47
|
# outputs emitted one per line, and whitespace is OK in json.
|
48
48
|
@on_event.call(event, "#{event.to_json}#{@delimiter}")
|
49
|
-
end
|
49
|
+
end
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
53
|
+
# from_json_parse uses the Event#from_json method to deserialize and directly produce events
|
54
|
+
def from_json_parse(json, &block)
|
55
|
+
LogStash::Event.from_json(json).each { |event| yield event }
|
56
|
+
rescue LogStash::Json::ParserError
|
57
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
59
58
|
end
|
60
59
|
|
60
|
+
# legacy_parse uses the LogStash::Json class to deserialize json
|
61
|
+
def legacy_parse(json, &block)
|
62
|
+
yield LogStash::Event.new(LogStash::Json.load(json))
|
63
|
+
rescue LogStash::Json::ParserError
|
64
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method :parse, LogStash::Event.respond_to?(:from_json) ? :from_json_parse : :legacy_parse
|
68
|
+
|
61
69
|
end # class LogStash::Codecs::JSONLines
|
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-json_lines'
|
4
|
-
s.version = '2.0
|
4
|
+
s.version = '2.1.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This codec will decode streamed JSON that is newline delimited."
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
10
10
|
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
|
11
|
-
s.require_paths
|
11
|
+
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
14
14
|
s.files = Dir['lib/**/*','spec/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
@@ -6,9 +6,10 @@ require "logstash/json"
|
|
6
6
|
require "insist"
|
7
7
|
|
8
8
|
describe LogStash::Codecs::JSONLines do
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
let(:codec_options) { {} }
|
11
|
+
|
12
|
+
shared_examples :codec do
|
12
13
|
|
13
14
|
context "#decode" do
|
14
15
|
it "should return an event from json data" do
|
@@ -37,9 +38,7 @@ describe LogStash::Codecs::JSONLines do
|
|
37
38
|
context "when using custom delimiter" do
|
38
39
|
let(:delimiter) { "|" }
|
39
40
|
let(:line) { "{\"hey\":1}|{\"hey\":2}|{\"hey\":3}|" }
|
40
|
-
|
41
|
-
next LogStash::Codecs::JSONLines.new("delimiter" => delimiter)
|
42
|
-
end
|
41
|
+
let(:codec_options) { { "delimiter" => delimiter } }
|
43
42
|
|
44
43
|
it "should decode multiple lines separated by the delimiter" do
|
45
44
|
result = []
|
@@ -122,9 +121,7 @@ describe LogStash::Codecs::JSONLines do
|
|
122
121
|
|
123
122
|
context "when using custom delimiter" do
|
124
123
|
let(:delimiter) { "|" }
|
125
|
-
|
126
|
-
next LogStash::Codecs::JSONLines.new("delimiter" => delimiter)
|
127
|
-
end
|
124
|
+
let(:codec_options) { { "delimiter" => delimiter } }
|
128
125
|
|
129
126
|
it "should decode multiple lines separated by the delimiter" do
|
130
127
|
subject.on_event do |e, d|
|
@@ -170,4 +167,35 @@ describe LogStash::Codecs::JSONLines do
|
|
170
167
|
expect(collector.last['field']).to eq('value2')
|
171
168
|
end
|
172
169
|
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
context "forcing legacy parsing" do
|
174
|
+
it_behaves_like :codec do
|
175
|
+
subject do
|
176
|
+
# register method is called in the constructor
|
177
|
+
LogStash::Codecs::JSONLines.new(codec_options)
|
178
|
+
end
|
179
|
+
|
180
|
+
before(:each) do
|
181
|
+
# stub codec parse method to force use of the legacy parser.
|
182
|
+
# this is very implementation specific but I am not sure how
|
183
|
+
# this can be tested otherwise.
|
184
|
+
allow(subject).to receive(:parse) do |line, &block|
|
185
|
+
subject.send(:legacy_parse, line, &block)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "default parser choice" do
|
192
|
+
# here we cannot force the use of the Event#from_json since if this test is run in the
|
193
|
+
# legacy context (no Java Event) it will fail but if in the new context, it will be picked up.
|
194
|
+
it_behaves_like :codec do
|
195
|
+
subject do
|
196
|
+
# register method is called in the constructor
|
197
|
+
LogStash::Codecs::JSONLines.new(codec_options)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
173
201
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-json_lines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|