Skip to content

Commit 76ff6ff

Browse files
committed
Re-established previous behaviour without a default limit for 'decode_size_limit_bytes'
1 parent aed3db3 commit 76ff6ff

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

docs/index.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Therefore this codec cannot work with line oriented inputs.
3535
|=======================================================================
3636
|Setting |Input type|Required
3737
| <<plugins-{type}s-{plugin}-charset>> |<<string,string>>, one of `["ASCII-8BIT", "UTF-8", "US-ASCII", "Big5", "Big5-HKSCS", "Big5-UAO", "CP949", "Emacs-Mule", "EUC-JP", "EUC-KR", "EUC-TW", "GB2312", "GB18030", "GBK", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-8859-10", "ISO-8859-11", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15", "ISO-8859-16", "KOI8-R", "KOI8-U", "Shift_JIS", "UTF-16BE", "UTF-16LE", "UTF-32BE", "UTF-32LE", "Windows-31J", "Windows-1250", "Windows-1251", "Windows-1252", "IBM437", "IBM737", "IBM775", "CP850", "IBM852", "CP852", "IBM855", "CP855", "IBM857", "IBM860", "IBM861", "IBM862", "IBM863", "IBM864", "IBM865", "IBM866", "IBM869", "Windows-1258", "GB1988", "macCentEuro", "macCroatian", "macCyrillic", "macGreek", "macIceland", "macRoman", "macRomania", "macThai", "macTurkish", "macUkraine", "CP950", "CP951", "IBM037", "stateless-ISO-2022-JP", "eucJP-ms", "CP51932", "EUC-JIS-2004", "GB12345", "ISO-2022-JP", "ISO-2022-JP-2", "CP50220", "CP50221", "Windows-1256", "Windows-1253", "Windows-1255", "Windows-1254", "TIS-620", "Windows-874", "Windows-1257", "MacJapanese", "UTF-7", "UTF8-MAC", "UTF-16", "UTF-32", "UTF8-DoCoMo", "SJIS-DoCoMo", "UTF8-KDDI", "SJIS-KDDI", "ISO-2022-JP-KDDI", "stateless-ISO-2022-JP-KDDI", "UTF8-SoftBank", "SJIS-SoftBank", "BINARY", "CP437", "CP737", "CP775", "IBM850", "CP857", "CP860", "CP861", "CP862", "CP863", "CP864", "CP865", "CP866", "CP869", "CP1258", "Big5-HKSCS:2008", "ebcdic-cp-us", "eucJP", "euc-jp-ms", "EUC-JISX0213", "eucKR", "eucTW", "EUC-CN", "eucCN", "CP936", "ISO2022-JP", "ISO2022-JP2", "ISO8859-1", "ISO8859-2", "ISO8859-3", "ISO8859-4", "ISO8859-5", "ISO8859-6", "CP1256", "ISO8859-7", "CP1253", "ISO8859-8", "CP1255", "ISO8859-9", "CP1254", "ISO8859-10", "ISO8859-11", "CP874", "ISO8859-13", "CP1257", "ISO8859-14", "ISO8859-15", "ISO8859-16", "CP878", "MacJapan", "ASCII", "ANSI_X3.4-1968", "646", "CP65000", "CP65001", "UTF-8-MAC", "UTF-8-HFS", "UCS-2BE", "UCS-4BE", "UCS-4LE", "CP932", "csWindows31J", "SJIS", "PCK", "CP1250", "CP1251", "CP1252", "external", "locale"]`|No
38+
| <<plugins-{type}s-{plugin}-decode_size_limit_bytes>> |<<string,string>>|No
3839
| <<plugins-{type}s-{plugin}-delimiter>> |<<string,string>>|No
3940
| <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
4041
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
@@ -58,6 +59,17 @@ actual encoding of the text and logstash will convert it for you.
5859

5960
For nxlog users, you'll want to set this to `CP1252`
6061

62+
[id="plugins-{type}s-{plugin}-decode_size_limit_bytes"]
63+
===== `decode_size_limit_bytes`
64+
65+
* Value type is <<string,string>>
66+
* Default value is "none"
67+
68+
Maximum number of bytes for a single line before tagging the event as failure and
69+
moving forward with a partial string up to this size.
70+
A possible suggested value 20MB, types as string `"20971520"`, which is quite large for a JSON document.
71+
Default value is `none` which means no limit.
72+
6173
[id="plugins-{type}s-{plugin}-delimiter"]
6274
===== `delimiter`
6375

lib/logstash/codecs/json_lines.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
4242
# Change the delimiter that separates lines
4343
config :delimiter, :validate => :string, :default => "\n"
4444

45-
# Maximum number of bytes for a single line before a fatal exception is raised
46-
# which will stop Logsash.
47-
# The default is 20MB which is quite large for a JSON document
48-
config :decode_size_limit_bytes, :validate => :number, :default => 20 * (1024 * 1024) # 20MB
45+
# Maximum number of bytes for a single line before tagging the event as failure and
46+
# moving forward with a partial string up to this size.
47+
# A possible suggested value 20MB, types as string "20971520", which is quite large for a JSON document.
48+
# Default value is none which means no limit.
49+
config :decode_size_limit_bytes, :validate => :string, :default => "none"
4950

5051
# Defines a target field for placing decoded fields.
5152
# If this setting is omitted, data gets stored at the root (top level) of the event.
@@ -55,7 +56,11 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
5556
public
5657

5758
def register
58-
@buffer = FileWatch::BufferedTokenizer.new(@delimiter, @decode_size_limit_bytes)
59+
if @decode_size_limit_bytes == "none"
60+
@buffer = FileWatch::BufferedTokenizer.new(@delimiter)
61+
else
62+
@buffer = FileWatch::BufferedTokenizer.new(@delimiter, @decode_size_limit_bytes.to_i)
63+
end
5964
@converter = LogStash::Util::Charset.new(@charset)
6065
@converter.logger = @logger
6166
end

spec/codecs/json_lines_spec.rb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,31 @@
118118
end
119119
end
120120

121-
describe "decode_size_limits_bytes" do
122-
let(:maximum_payload) { "a" * subject.decode_size_limit_bytes }
121+
describe "decode_size_limit_bytes" do
122+
context "when a value is defined" do
123+
let(:decode_size_limit_bytes) { 20 * 1024 * 1024 }
124+
let(:codec_options) { { "decode_size_limit_bytes" => decode_size_limit_bytes.to_s } }
125+
let(:maximum_payload) { "a" * decode_size_limit_bytes }
126+
127+
it "should not raise an error if the number of bytes is not exceeded" do
128+
expect {
129+
subject.decode(maximum_payload)
130+
}.not_to raise_error
131+
end
123132

124-
it "should not raise an error if the number of bytes is not exceeded" do
125-
expect {
126-
subject.decode(maximum_payload)
127-
}.not_to raise_error
133+
it "should raise an error if the max bytes are exceeded" do
134+
expect {
135+
subject.decode(maximum_payload << "z")
136+
}.to raise_error(java.lang.IllegalStateException, "input buffer full")
137+
end
128138
end
129-
130-
it "should raise an error if the max bytes are exceeded" do
131-
expect {
132-
subject.decode(maximum_payload << "z")
133-
}.to raise_error(java.lang.IllegalStateException, "input buffer full")
139+
140+
context "when left to default 'none' value" do
141+
it "should not raise any error for long big lines" do
142+
expect {
143+
subject.decode("a" * 30 * 1024 * 1024)
144+
}.not_to raise_error
145+
end
134146
end
135147
end
136148

0 commit comments

Comments
 (0)