logstash-codec-json_stream 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b844cfe3444a066af5ab9b7c0da943da2822cdd490c4b5c9bee8c2889c95cb3c
4
- data.tar.gz: a40e7766d69b01e601fdf4231b013c65c1db10e8e824b1ab2ff9fafa25dab5b6
3
+ metadata.gz: 61d4c637a37d172a265d32cf5adeeeb84b7e7d6a821c3c4a52d5613b9e7fc28e
4
+ data.tar.gz: d821b50785f069a7402a1f757bf7ee3e35229ae75184def3b60707a6defb581f
5
5
  SHA512:
6
- metadata.gz: cd984ba16e049cfedd692ad99f76462acc2ff493b359a8e3a09b8530af0cb1fcec49ef00d2823a7b5fe2221a37536b237275b89514a2fcc3da64173c47ba7636
7
- data.tar.gz: 75252622493230be43d863a66e99a7e3fbb1f219d0f1bf8571c4f6686fe780825b1b5eaa497de6b45516a04bf143b928c3f1168fed623f2dce272d7bbf9e3fc3
6
+ metadata.gz: aaef763e7882036ff02b4f9215b3aed538f90b07a0498464b1e9f546646744e981a23de6d9c87b45b76462235cf7f799d07f14cc1955a3ce4543013fbee89fe3
7
+ data.tar.gz: f6765f37c81b588e83830e1f99dae4e6941ba591051bdc1bbeb59b7d26023cde86173d046e44e4424c2b2f4089e79151c71400b6f5f689676926ff24c86237bb
@@ -1,3 +1,6 @@
1
+ ## 1.1.0
2
+ - Refactor code
3
+ - Json Parse Failure should be a warning level
1
4
  ## 1.0.0
2
5
  - Add spec tests thanks to johannesthoenes4000 & thomasklinger123
3
6
  - Add a better parsing method thanks to johannesthoenes4000
@@ -21,9 +21,10 @@ class LogStash::Codecs::JSONStream < LogStash::Codecs::Base
21
21
  end
22
22
 
23
23
  def decode(concatenated_json, &block)
24
- decode_unsafe(concatenated_json, &block)
24
+ array_json = @converter.convert("[#{concatenated_json.gsub('}{', '},{')}]")
25
+ parse(array_json, &block)
25
26
  rescue LogStash::Json::ParserError => e
26
- @logger.error("JSON parse error for json stream / concatenated json, original data now in message field", :error => e, :data => concatenated_json)
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 'concatenated_json' plugin yet")
42
+ @logger.error("Encoding is not supported by 'jsonstream' plugin yet")
42
43
  end
43
44
 
44
- def flush(&block)
45
- @logger.debug("empty flush method -- nothing to do")
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
- private
49
- def decode_unsafe(concatenated_json)
50
- array_json = @converter.convert("[#{concatenated_json.gsub('}{', '},{')}]")
51
- LogStash::Json.load(array_json).each do |decoded_event|
52
- yield(LogStash::Event.new(decoded_event))
53
- end
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.0.0'
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 :decode_unsafe # use method without error logging for better visibility of errors
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.valid-line-formatted')
55
- insist { events.size } == 5
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.decode_unsafe(data_without_formatting) { |event| events << event }
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.0.0
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: 2018-06-26 00:00:00.000000000 Z
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