logstash-codec-json_lines 2.0.3 → 2.0.4
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/CHANGELOG.md +3 -0
- data/lib/logstash/codecs/json_lines.rb +7 -4
- data/logstash-codec-json_lines.gemspec +2 -2
- data/spec/codecs/json_lines_spec.rb +34 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f521208069a7cd36106fb98b084d514e09ee87f
|
4
|
+
data.tar.gz: 4be461209d267a74a8ba35904f6f819493c8c466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97921e4feed4e57da139aa12b6a29d00f0430ecf19bf6b4c94fd46ca03db3c1c5430b63a26b22de5b83c47eca4d81749232bad2675e6e4a84d026385f612f41f
|
7
|
+
data.tar.gz: bd9480c4584eb40ea9b1218821cf53ac6de56e61f50c47a158476353300239d89280292f4cac31f21c3e4e0ade204c363d15e8e3ecaca3fa2915493c326d9512
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ require "logstash/codecs/line"
|
|
4
4
|
require "logstash/json"
|
5
5
|
|
6
6
|
# This codec will decode streamed JSON that is newline delimited.
|
7
|
-
# Encoding will emit a single JSON string ending in a
|
7
|
+
# Encoding will emit a single JSON string ending in a `@delimiter`
|
8
8
|
# NOTE: Do not use this codec if your source input is line-oriented JSON, for
|
9
9
|
# example, redis or file inputs. Rather, use the json codec.
|
10
10
|
# More info: This codec is expecting to receive a stream (string) of newline
|
@@ -25,11 +25,14 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
|
|
25
25
|
# For nxlog users, you'll want to set this to `CP1252`
|
26
26
|
config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"
|
27
27
|
|
28
|
+
# Change the delimiter that separates lines
|
29
|
+
config :delimiter, :validate => :string, :default => "\n"
|
30
|
+
|
28
31
|
public
|
29
32
|
|
30
33
|
def initialize(params={})
|
31
34
|
super(params)
|
32
|
-
@lines = LogStash::Codecs::Line.new
|
35
|
+
@lines = LogStash::Codecs::Line.new("delimiter" => @delimiter)
|
33
36
|
@lines.charset = @charset
|
34
37
|
end
|
35
38
|
|
@@ -40,9 +43,9 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
|
|
40
43
|
end # def decode
|
41
44
|
|
42
45
|
def encode(event)
|
43
|
-
# Tack on a
|
46
|
+
# Tack on a @delimiter for now because previously most of logstash's JSON
|
44
47
|
# outputs emitted one per line, and whitespace is OK in json.
|
45
|
-
@on_event.call(event, "#{event.to_json}#{
|
48
|
+
@on_event.call(event, "#{event.to_json}#{@delimiter}")
|
46
49
|
end # def encode
|
47
50
|
|
48
51
|
private
|
@@ -1,7 +1,7 @@
|
|
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.0.4'
|
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"
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
# Gem dependencies
|
23
23
|
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
|
24
24
|
|
25
|
-
s.add_runtime_dependency 'logstash-codec-line'
|
25
|
+
s.add_runtime_dependency 'logstash-codec-line', '>= 2.1.0'
|
26
26
|
|
27
27
|
s.add_development_dependency 'logstash-devutils'
|
28
28
|
end
|
@@ -32,6 +32,23 @@ describe LogStash::Codecs::JSONLines do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
context "when using custom delimiter" do
|
36
|
+
let(:delimiter) { "|" }
|
37
|
+
let(:line) { "{\"hey\":1}|{\"hey\":2}|{\"hey\":3}|" }
|
38
|
+
subject do
|
39
|
+
next LogStash::Codecs::JSONLines.new("delimiter" => delimiter)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should decode multiple lines separated by the delimiter" do
|
43
|
+
result = []
|
44
|
+
subject.decode(line) { |event| result << event }
|
45
|
+
expect(result.size).to eq(3)
|
46
|
+
expect(result[0]["hey"]).to eq(1)
|
47
|
+
expect(result[1]["hey"]).to eq(2)
|
48
|
+
expect(result[2]["hey"]).to eq(3)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
35
52
|
context "processing plain text" do
|
36
53
|
it "falls back to plain text" do
|
37
54
|
decoded = false
|
@@ -85,9 +102,10 @@ describe LogStash::Codecs::JSONLines do
|
|
85
102
|
end
|
86
103
|
|
87
104
|
context "#encode" do
|
105
|
+
let(:data) { { LogStash::Event::TIMESTAMP => "2015-12-07T11:37:00.000Z", "foo" => "bar", "baz" => {"bah" => ["a","b","c"]}} }
|
106
|
+
let(:event) { LogStash::Event.new(data) }
|
107
|
+
|
88
108
|
it "should return json data" do
|
89
|
-
data = {LogStash::Event::TIMESTAMP => "2015-12-07T11:37:00.000Z", "foo" => "bar", "baz" => {"bah" => ["a","b","c"]}}
|
90
|
-
event = LogStash::Event.new(data)
|
91
109
|
got_event = false
|
92
110
|
subject.on_event do |e, d|
|
93
111
|
insist { d } == "#{LogStash::Event.new(data).to_json}\n"
|
@@ -99,6 +117,20 @@ describe LogStash::Codecs::JSONLines do
|
|
99
117
|
subject.encode(event)
|
100
118
|
insist { got_event }
|
101
119
|
end
|
120
|
+
|
121
|
+
context "when using custom delimiter" do
|
122
|
+
let(:delimiter) { "|" }
|
123
|
+
subject do
|
124
|
+
next LogStash::Codecs::JSONLines.new("delimiter" => delimiter)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should decode multiple lines separated by the delimiter" do
|
128
|
+
subject.on_event do |e, d|
|
129
|
+
insist { d } == "#{LogStash::Event.new(data).to_json}#{delimiter}"
|
130
|
+
end
|
131
|
+
subject.encode(event)
|
132
|
+
end
|
133
|
+
end
|
102
134
|
end
|
103
135
|
|
104
136
|
context 'reading from a simulated multiline json file without last newline' do
|
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.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|
@@ -36,12 +36,12 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 2.1.0
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: 2.1.0
|
45
45
|
prerelease: false
|
46
46
|
type: :runtime
|
47
47
|
- !ruby/object:Gem::Dependency
|