logstash-codec-json_stream 1.0.0 → 1.1.0
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_stream.rb +24 -11
- data/logstash-codec-json_stream.gemspec +2 -1
- data/spec/codecs/json_stream_spec.rb +16 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61d4c637a37d172a265d32cf5adeeeb84b7e7d6a821c3c4a52d5613b9e7fc28e
|
4
|
+
data.tar.gz: d821b50785f069a7402a1f757bf7ee3e35229ae75184def3b60707a6defb581f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaef763e7882036ff02b4f9215b3aed538f90b07a0498464b1e9f546646744e981a23de6d9c87b45b76462235cf7f799d07f14cc1955a3ce4543013fbee89fe3
|
7
|
+
data.tar.gz: f6765f37c81b588e83830e1f99dae4e6941ba591051bdc1bbeb59b7d26023cde86173d046e44e4424c2b2f4089e79151c71400b6f5f689676926ff24c86237bb
|
data/CHANGELOG.md
CHANGED
@@ -21,9 +21,10 @@ class LogStash::Codecs::JSONStream < LogStash::Codecs::Base
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def decode(concatenated_json, &block)
|
24
|
-
|
24
|
+
array_json = @converter.convert("[#{concatenated_json.gsub('}{', '},{')}]")
|
25
|
+
parse(array_json, &block)
|
25
26
|
rescue LogStash::Json::ParserError => e
|
26
|
-
@logger.
|
27
|
+
@logger.warn("JSON parse error for json stream / concatenated json, original data now in message field", :error => e, :data => concatenated_json)
|
27
28
|
yield LogStash::Event.new("message" => concatenated_json, "tags" => ["_jsonparsefailure"])
|
28
29
|
rescue StandardError => e
|
29
30
|
# This should NEVER happen. But hubris has been the cause of many pipeline breaking things
|
@@ -38,18 +39,30 @@ class LogStash::Codecs::JSONStream < LogStash::Codecs::Base
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def encode(event)
|
41
|
-
@logger.error("Encoding is not supported by '
|
42
|
+
@logger.error("Encoding is not supported by 'jsonstream' plugin yet")
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
private
|
46
|
+
|
47
|
+
# from_json_parse uses the Event#from_json method to deserialize and directly produce events
|
48
|
+
def from_json_parse(json, &block)
|
49
|
+
LogStash::Event.from_json(json).each { |event| yield event }
|
50
|
+
rescue LogStash::Json::ParserError => e
|
51
|
+
@logger.warn("JSON parse error, original data now in message field", :error => e, :data => json)
|
52
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
46
53
|
end
|
47
54
|
|
48
|
-
|
49
|
-
def
|
50
|
-
|
51
|
-
LogStash::Json.load(
|
52
|
-
|
53
|
-
|
55
|
+
# legacy_parse uses the LogStash::Json class to deserialize json
|
56
|
+
def legacy_parse(json, &block)
|
57
|
+
# ignore empty/blank lines which LogStash::Json#load returns as nil
|
58
|
+
o = LogStash::Json.load(json)
|
59
|
+
yield(LogStash::Event.new(o)) if o
|
60
|
+
rescue LogStash::Json::ParserError => e
|
61
|
+
@logger.warn("JSON parse error, original data now in message field", :error => e, :data => json)
|
62
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
54
63
|
end
|
64
|
+
|
65
|
+
# keep compatibility with all v2.x distributions. only in 2.3 will the Event#from_json method be introduced
|
66
|
+
# and we need to keep compatibility for all v2 releases.
|
67
|
+
alias_method :parse, LogStash::Event.respond_to?(:from_json) ? :from_json_parse : :legacy_parse
|
55
68
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-json_stream'
|
4
|
-
s.version = '1.
|
4
|
+
s.version = '1.1.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Reads and writes non JSON Streams"
|
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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -25,5 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_runtime_dependency 'logstash-codec-line', '>= 2.1.0'
|
26
26
|
|
27
27
|
s.add_development_dependency 'logstash-devutils'
|
28
|
+
|
28
29
|
end
|
29
30
|
|
@@ -8,11 +8,23 @@ require "insist"
|
|
8
8
|
describe LogStash::Codecs::JSONStream do
|
9
9
|
|
10
10
|
class LogStash::Codecs::JSONStream
|
11
|
-
public :
|
11
|
+
public :from_json_parse # use method without error logging for better visibility of errors
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:codec_options) { {} }
|
15
15
|
|
16
|
+
context "#decode" do
|
17
|
+
it "should return an event from json data" do
|
18
|
+
data = {"foo" => "bar", "baz" => {"bah" => ["a","b","c"]}}
|
19
|
+
subject.decode(LogStash::Json.dump(data)) do |event|
|
20
|
+
insist { event.is_a? LogStash::Event }
|
21
|
+
insist { event.get("foo") } == data["foo"]
|
22
|
+
insist { event.get("baz") } == data["baz"]
|
23
|
+
insist { event.get("bah") } == data["bah"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
16
28
|
context "default parser choice" do
|
17
29
|
subject do
|
18
30
|
LogStash::Codecs::JSONStream.new(codec_options)
|
@@ -51,12 +63,11 @@ EOS
|
|
51
63
|
end
|
52
64
|
|
53
65
|
it "should read multiple events from data" do
|
54
|
-
events = events_from_file('log-stream.
|
55
|
-
insist { events.size } ==
|
66
|
+
events = events_from_file('log-stream.real-formatted')
|
67
|
+
insist { events.size } == 4
|
56
68
|
|
57
69
|
events.each do |event|
|
58
70
|
insist { event.is_a? LogStash::Event }
|
59
|
-
insist { event.get("logGroup") } == "test-core"
|
60
71
|
insist { event.get("messageType") } == "DATA_MESSAGE"
|
61
72
|
insist { event.get("logEvents").size } != 0
|
62
73
|
event.get("logEvents").each do |event|
|
@@ -85,7 +96,7 @@ EOS
|
|
85
96
|
def events_from_string data
|
86
97
|
events = []
|
87
98
|
data_without_formatting = data.gsub(/(\n|\s{2,})/, '')
|
88
|
-
subject.
|
99
|
+
subject.decode(data_without_formatting) { |event| events << event }
|
89
100
|
events
|
90
101
|
end
|
91
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-json_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Herweg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|