logstash-codec-multiline 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/codecs/multiline.rb +46 -12
- data/logstash-codec-multiline.gemspec +1 -1
- data/spec/codecs/multiline_spec.rb +48 -1
- data/spec/supports/helpers.rb +14 -0
- metadata +24 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40099b6b6fa37c2e7eada7dd7bd49097f67267ba
|
4
|
+
data.tar.gz: d0fb10c0893b4a736bd2913c9b8b9207fc3a9536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9847d7a7c4be62cec6527062cbf0ec663015221c0f27ec1e54238622d4d1fd96d52d28c1263be91848b83f90d4852975f760611d7eb90a377fc318dbd42f3c57
|
7
|
+
data.tar.gz: c097ad89ff4b7853f016c75d7e8ac4270dfe83e766a4df88ce23fc93b45ba46ccba94a4cd1a616e0fac9809b11b9359f5c48bdcc0583e626c46f9f04053d6f4a
|
@@ -114,10 +114,23 @@ class LogStash::Codecs::Multiline < LogStash::Codecs::Base
|
|
114
114
|
# to events that actually have multiple lines in them.
|
115
115
|
config :multiline_tag, :validate => :string, :default => "multiline"
|
116
116
|
|
117
|
+
# The accumulation of events can make logstash exit with an out of memory error
|
118
|
+
# if event boundaries are not correctly defined. This settings make sure to flush
|
119
|
+
# multiline events after reaching a number of lines, it is used in combination
|
120
|
+
# max_bytes.
|
121
|
+
config :max_lines, :validate => :number, :default => 500
|
122
|
+
|
123
|
+
# The accumulation of events can make logstash exit with an out of memory error
|
124
|
+
# if event boundaries are not correctly defined. This settings make sure to flush
|
125
|
+
# multiline events after reaching a number of bytes, it is used in combination
|
126
|
+
# max_lines.
|
127
|
+
config :max_bytes, :validate => :bytes, :default => "10 MiB"
|
128
|
+
|
117
129
|
public
|
118
130
|
def register
|
119
131
|
require "grok-pure" # rubygem 'jls-grok'
|
120
132
|
require 'logstash/patterns/core'
|
133
|
+
|
121
134
|
# Detect if we are running from a jarfile, pick the right path.
|
122
135
|
patterns_path = []
|
123
136
|
patterns_path += [LogStash::Patterns::Core.path]
|
@@ -139,14 +152,14 @@ class LogStash::Codecs::Multiline < LogStash::Codecs::Base
|
|
139
152
|
@grok.compile(@pattern)
|
140
153
|
@logger.debug("Registered multiline plugin", :type => @type, :config => @config)
|
141
154
|
|
142
|
-
|
155
|
+
reset_buffer
|
156
|
+
|
143
157
|
@handler = method("do_#{@what}".to_sym)
|
144
158
|
|
145
159
|
@converter = LogStash::Util::Charset.new(@charset)
|
146
160
|
@converter.logger = @logger
|
147
161
|
end # def register
|
148
162
|
|
149
|
-
public
|
150
163
|
def decode(text, &block)
|
151
164
|
text = @converter.convert(text)
|
152
165
|
|
@@ -163,31 +176,52 @@ class LogStash::Codecs::Multiline < LogStash::Codecs::Base
|
|
163
176
|
|
164
177
|
def buffer(text)
|
165
178
|
@time = LogStash::Timestamp.now if @buffer.empty?
|
179
|
+
@buffer_bytes += text.bytesize
|
166
180
|
@buffer << text
|
167
181
|
end
|
168
182
|
|
169
183
|
def flush(&block)
|
170
|
-
if @buffer.any?
|
171
|
-
|
172
|
-
|
173
|
-
event.tag @multiline_tag if @multiline_tag && @buffer.size > 1
|
174
|
-
|
175
|
-
yield event
|
176
|
-
@buffer = []
|
184
|
+
if @buffer.any?
|
185
|
+
yield merge_events
|
186
|
+
reset_buffer
|
177
187
|
end
|
178
188
|
end
|
179
189
|
|
190
|
+
def merge_events
|
191
|
+
event = LogStash::Event.new(LogStash::Event::TIMESTAMP => @time, "message" => @buffer.join(NL))
|
192
|
+
event.tag @multiline_tag if @multiline_tag && @buffer.size > 1
|
193
|
+
event.tag "multiline_codec_max_bytes_reached" if over_maximun_bytes?
|
194
|
+
event.tag "multiline_codec_max_lines_reached" if over_maximun_lines?
|
195
|
+
event
|
196
|
+
end
|
197
|
+
|
198
|
+
def reset_buffer
|
199
|
+
@buffer = []
|
200
|
+
@buffer_bytes = 0
|
201
|
+
end
|
202
|
+
|
180
203
|
def do_next(text, matched, &block)
|
181
204
|
buffer(text)
|
182
|
-
flush(&block) if !matched
|
205
|
+
flush(&block) if !matched || buffer_over_limits?
|
183
206
|
end
|
184
207
|
|
185
208
|
def do_previous(text, matched, &block)
|
186
|
-
flush(&block) if !matched
|
209
|
+
flush(&block) if !matched || buffer_over_limits?
|
187
210
|
buffer(text)
|
188
211
|
end
|
189
212
|
|
190
|
-
|
213
|
+
def over_maximun_lines?
|
214
|
+
@buffer.size > @max_lines
|
215
|
+
end
|
216
|
+
|
217
|
+
def over_maximun_bytes?
|
218
|
+
@buffer_bytes >= @max_bytes
|
219
|
+
end
|
220
|
+
|
221
|
+
def buffer_over_limits?
|
222
|
+
over_maximun_lines? || over_maximun_bytes?
|
223
|
+
end
|
224
|
+
|
191
225
|
def encode(event)
|
192
226
|
# Nothing to do.
|
193
227
|
@on_event.call(event, event)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-multiline'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.7'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "The multiline codec will collapse multiline messages and merge them into a single event."
|
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/plugin install gemname. This gem is not a stand-alone program"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
2
|
require "logstash/codecs/multiline"
|
4
3
|
require "logstash/event"
|
5
4
|
require "insist"
|
5
|
+
require_relative "../supports/helpers.rb"
|
6
6
|
|
7
7
|
describe LogStash::Codecs::Multiline do
|
8
8
|
context "#decode" do
|
@@ -171,4 +171,51 @@ describe LogStash::Codecs::Multiline do
|
|
171
171
|
|
172
172
|
end
|
173
173
|
end
|
174
|
+
|
175
|
+
context "with non closed multiline events" do
|
176
|
+
let(:random_number_of_events) { rand(300..1000) }
|
177
|
+
let(:sample_event) { "- Sample event" }
|
178
|
+
let(:events) { decode_events }
|
179
|
+
let(:unmerged_events_count) { events.collect { |event| event["message"].split(LogStash::Codecs::Multiline::NL).size }.inject(&:+) }
|
180
|
+
|
181
|
+
context "break on maximum_lines" do
|
182
|
+
let(:max_lines) { rand(10..100) }
|
183
|
+
let(:options) {
|
184
|
+
{
|
185
|
+
"pattern" => "^-",
|
186
|
+
"what" => "previous",
|
187
|
+
"max_lines" => max_lines,
|
188
|
+
"max_bytes" => "2 mb"
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
it "flushes on a maximum lines" do
|
193
|
+
expect(unmerged_events_count).to eq(random_number_of_events)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "tags the event" do
|
197
|
+
expect(events.first["tags"]).to include("multiline_codec_max_lines_reached")
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "break on maximum bytes" do
|
202
|
+
let(:max_bytes) { rand(30..100) }
|
203
|
+
let(:options) {
|
204
|
+
{
|
205
|
+
"pattern" => "^-",
|
206
|
+
"what" => "previous",
|
207
|
+
"max_lines" => 20000,
|
208
|
+
"max_bytes" => max_bytes
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
it "flushes on a maximum bytes size" do
|
213
|
+
expect(unmerged_events_count).to eq(random_number_of_events)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "tags the event" do
|
217
|
+
expect(events.first["tags"]).to include("multiline_codec_max_bytes_reached")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
174
221
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "lib/logstash/codecs/multiline"
|
2
|
+
|
3
|
+
def decode_events
|
4
|
+
multiline = LogStash::Codecs::Multiline.new(options)
|
5
|
+
|
6
|
+
events = []
|
7
|
+
random_number_of_events.times do |n|
|
8
|
+
multiline.decode(sample_event) { |event| events << event }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Grab the in-memory-event
|
12
|
+
multiline.flush { |event| events << event }
|
13
|
+
events
|
14
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-multiline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elasticsearch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - '>='
|
17
18
|
- !ruby/object:Gem::Version
|
@@ -19,10 +20,7 @@ dependencies:
|
|
19
20
|
- - <
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 2.0.0
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
type: :runtime
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,48 +28,50 @@ dependencies:
|
|
30
28
|
- - <
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: 2.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-patterns-core
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
44
|
version: '0'
|
39
|
-
name: logstash-patterns-core
|
40
45
|
prerelease: false
|
41
46
|
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jls-grok
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
|
-
- -
|
51
|
+
- - ~>
|
45
52
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
47
|
-
- !ruby/object:Gem::Dependency
|
53
|
+
version: 0.11.1
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
50
56
|
- - ~>
|
51
57
|
- !ruby/object:Gem::Version
|
52
58
|
version: 0.11.1
|
53
|
-
name: jls-grok
|
54
59
|
prerelease: false
|
55
60
|
type: :runtime
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: logstash-devutils
|
56
63
|
version_requirements: !ruby/object:Gem::Requirement
|
57
64
|
requirements:
|
58
|
-
- -
|
65
|
+
- - '>='
|
59
66
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0
|
61
|
-
- !ruby/object:Gem::Dependency
|
67
|
+
version: '0'
|
62
68
|
requirement: !ruby/object:Gem::Requirement
|
63
69
|
requirements:
|
64
70
|
- - '>='
|
65
71
|
- !ruby/object:Gem::Version
|
66
72
|
version: '0'
|
67
|
-
name: logstash-devutils
|
68
73
|
prerelease: false
|
69
74
|
type: :development
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - '>='
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
75
|
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
76
76
|
email: info@elasticsearch.com
|
77
77
|
executables: []
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/logstash/codecs/multiline.rb
|
88
88
|
- logstash-codec-multiline.gemspec
|
89
89
|
- spec/codecs/multiline_spec.rb
|
90
|
+
- spec/supports/helpers.rb
|
90
91
|
homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
|
91
92
|
licenses:
|
92
93
|
- Apache License (2.0)
|
@@ -109,9 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.1.9
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: The multiline codec will collapse multiline messages and merge them into a single event.
|
116
117
|
test_files:
|
117
118
|
- spec/codecs/multiline_spec.rb
|
119
|
+
- spec/supports/helpers.rb
|