diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e69a7f..64863f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.2.3 + - Update behaviour of `decode_size_limit_bytes` to do not apply any limitation to the length of a line, eventually tagging the event if it's set. [#45](https://github.com/logstash-plugins/logstash-codec-json_lines/pull/45) + ## 3.2.2 - Fix: updated the way to check if the `decode_size_limit_bytes` has been explicitly customised. [#47](https://github.com/logstash-plugins/logstash-codec-json_lines/pull/47) diff --git a/lib/logstash/codecs/json_lines.rb b/lib/logstash/codecs/json_lines.rb index c0a9795..e518a95 100644 --- a/lib/logstash/codecs/json_lines.rb +++ b/lib/logstash/codecs/json_lines.rb @@ -69,6 +69,13 @@ def decode(data, &block) @buffer.extract(data).each do |line| parse_json(@converter.convert(line), &block) end + rescue java.lang.IllegalStateException => e + if e.message == "input buffer full" && @decode_size_limit_bytes != "none" + yield event_factory.new_event("message" => "Payload bigger than #{@decode_size_limit_bytes} bytes", "tags" => ["_jsonparsetoobigfailure"]) + else + # re-raise the error if doesn't correspond to the buffer overflow condition + raise e + end end def encode(event) diff --git a/logstash-codec-json_lines.gemspec b/logstash-codec-json_lines.gemspec index 00a5a38..a3d9a04 100644 --- a/logstash-codec-json_lines.gemspec +++ b/logstash-codec-json_lines.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-codec-json_lines' - s.version = '3.2.2' + s.version = '3.2.3' s.licenses = ['Apache License (2.0)'] s.summary = "Reads and writes newline-delimited JSON" 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" diff --git a/spec/codecs/json_lines_spec.rb b/spec/codecs/json_lines_spec.rb index 7fc9ff5..7e7a96f 100644 --- a/spec/codecs/json_lines_spec.rb +++ b/spec/codecs/json_lines_spec.rb @@ -127,11 +127,12 @@ subject.decode(maximum_payload) }.not_to raise_error end - + it "should raise an error if the max bytes are exceeded" do - expect { - subject.decode(maximum_payload << "z") - }.to raise_error(java.lang.IllegalStateException, "input buffer full") + subject.decode(maximum_payload << "z") do |event| + expect(event.get("tags")).to include("_jsonparsetoobigfailure") + expect(event.get("message")).to eq("Payload bigger than #{subject.decode_size_limit_bytes} bytes") + end end end