Skip to content

Add decode_size_limit_bytes option. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.1.0
- Add decode_size_limit_bytes option to limit the maximum size of JSON document that can be parsed

## 3.0.2
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99

Expand Down
7 changes: 6 additions & 1 deletion lib/logstash/codecs/json_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
# Change the delimiter that separates lines
config :delimiter, :validate => :string, :default => "\n"

# Maximum number of bytes for a single line before a fatal exception is raised
# which will stop Logsash.
# The default is 20MB which is quite large for a JSON document
config :decode_size_limit_bytes, :validate => :number, :default => 20 * (1024 * 1024) # 20MB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Is decode the right name? The description says this is bytes for a line, but then we call it decode which isn't something mentioned elsewhere in the docs.
  • Exceeding this will cause a fatal error in Logstash and stop the process? Is this the desired behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the size limit is exceeded, where do we show that this exception will terminate Logstash? I don't see it when I read through the code.


public

def register
@buffer = FileWatch::BufferedTokenizer.new(@delimiter)
@buffer = FileWatch::BufferedTokenizer.new(@delimiter, @decode_size_limit_bytes)
@converter = LogStash::Util::Charset.new(@charset)
@converter.logger = @logger
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-codec-json_lines.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-codec-json_lines'
s.version = '3.0.2'
s.version = '3.1.0'
s.licenses = ['Apache License (2.0)']
s.summary = "This codec will decode streamed JSON that is newline delimited."
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"
Expand Down
16 changes: 16 additions & 0 deletions spec/codecs/json_lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@
end
end

describe "decode_size_limits_bytes" do
let(:maximum_payload) { "a" * subject.decode_size_limit_bytes }

it "should not raise an error if the number of bytes is not exceeded" do
expect {
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(RuntimeError, "input buffer full")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to provide more context to this exception? input buffer full feels a little vague, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that exception is provided by the FileWatch library, so it'd require a patch there. I should probably wrap and re-raise it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just submitted https://github.com/jordansissel/ruby-filewatch/pull/82/files to enable us to catch a more precise exception.

end
end

end

context "#encode" do
Expand Down