logstash-codec-multiline 3.0.11 → 3.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: 3b4b30bf975e6dfb49b71d847c4502335311ff408a52ed68e59e09e80d6ed222
4
- data.tar.gz: 38c64d94b88610ec6ab7dee1664721f9d9fc2609231b91418971af3129f4fd2d
3
+ metadata.gz: a4ecbf8730e688adbacb1af57c98f7c5105b5677337b140a22b6ccb41e1468ea
4
+ data.tar.gz: 299167720ec0457af53b7f118b6e55bd6c078f6ac1b8e4978ca68872a04cbc7c
5
5
  SHA512:
6
- metadata.gz: 6e013b8f23543488f6c3381be40e622025100ed78481175f955830235f752aface0b8912202e7a88fe2f825c3e6b559de22760ee18df7a71f471ac8309677989
7
- data.tar.gz: 50bfbea034b309e1f808d6454ab0065c6c260b82637a0fd6a3b55012dfc68f2f1661c6c3afd4e92c640e5e68320892a20598ca272344d6a1e28dd223c9add911
6
+ metadata.gz: 798b7fe3f963ade7578c655a00ba2ba7ea602dced4e463b170d8d7bf8b9e0585bedda761f9ee5bbbcb8026d99e0cbc3dc22bdfc19abe063c5d3716c2b8e0fd03
7
+ data.tar.gz: b4758f3f75e0ad1e470800aff9ccf353f8f4493cbcd6b30f687ef3fa74973e5baf0aba65a25450b83b3269879065ab5878141914dd3c35998e0bad4ca631b8bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.1.0
2
+ - Feat: ECS compatibility [#69](https://github.com/logstash-plugins/logstash-codec-multiline/pull/69)
3
+
1
4
  ## 3.0.11
2
5
  - Fix: avoid long thread sleeps on codec close [#67](https://github.com/logstash-plugins/logstash-codec-multiline/pull/67)
3
6
 
data/docs/index.asciidoc CHANGED
@@ -102,13 +102,14 @@ following line.
102
102
 
103
103
 
104
104
  [id="plugins-{type}s-{plugin}-options"]
105
- ==== Multiline Codec Configuration Options
105
+ ==== Multiline codec configuration options
106
106
 
107
107
  [cols="<,<,<",options="header",]
108
108
  |=======================================================================
109
109
  |Setting |Input type|Required
110
110
  | <<plugins-{type}s-{plugin}-auto_flush_interval>> |<<number,number>>|No
111
111
  | <<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
112
+ | <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
112
113
  | <<plugins-{type}s-{plugin}-max_bytes>> |<<bytes,bytes>>|No
113
114
  | <<plugins-{type}s-{plugin}-max_lines>> |<<number,number>>|No
114
115
  | <<plugins-{type}s-{plugin}-multiline_tag>> |<<string,string>>|No
@@ -144,6 +145,19 @@ or in another character set other than `UTF-8`.
144
145
 
145
146
  This only affects "plain" format logs since JSON is `UTF-8` already.
146
147
 
148
+ [id="plugins-{type}s-{plugin}-ecs_compatibility"]
149
+ ===== `ecs_compatibility`
150
+
151
+ * Value type is <<string,string>>
152
+ * Supported values are:
153
+ ** `disabled`: plugin only sets the `message` field
154
+ ** `v1`,`v8`: Elastic Common Schema compliant behavior (`[event][original]` is also added)
155
+ * Default value depends on which version of Logstash is running:
156
+ ** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
157
+ ** Otherwise, the default value is `disabled`
158
+
159
+ Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
160
+
147
161
  [id="plugins-{type}s-{plugin}-max_bytes"]
148
162
  ===== `max_bytes`
149
163
 
@@ -3,6 +3,8 @@ require "logstash/codecs/base"
3
3
  require "logstash/util/charset"
4
4
  require "logstash/timestamp"
5
5
  require "logstash/codecs/auto_flush"
6
+ require 'logstash/plugin_mixins/ecs_compatibility_support'
7
+ require 'logstash/plugin_mixins/event_support/event_factory_adapter'
6
8
 
7
9
  # The multiline codec will collapse multiline messages and merge them into a
8
10
  # single event.
@@ -85,6 +87,10 @@ require "logstash/codecs/auto_flush"
85
87
  # following line.
86
88
  #
87
89
  module LogStash module Codecs class Multiline < LogStash::Codecs::Base
90
+
91
+ include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
92
+ include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
93
+
88
94
  config_name "multiline"
89
95
 
90
96
  # The regular expression to match.
@@ -141,6 +147,13 @@ module LogStash module Codecs class Multiline < LogStash::Codecs::Base
141
147
 
142
148
  public
143
149
 
150
+
151
+ def initialize(*params)
152
+ super
153
+
154
+ @original_field = ecs_select[disabled: nil, v1: '[event][original]']
155
+ end
156
+
144
157
  def register
145
158
  require "grok-pure" # rubygem 'jls-grok'
146
159
  require 'logstash/patterns/core'
@@ -197,8 +210,8 @@ module LogStash module Codecs class Multiline < LogStash::Codecs::Base
197
210
  text = @converter.convert(text)
198
211
  text.split("\n").each do |line|
199
212
  match = @grok.match(line)
200
- @logger.debug("Multiline", :pattern => @pattern, :text => line,
201
- :match => (match != false), :negate => @negate)
213
+ @logger.debug? && @logger.debug("Multiline", :text => line, :pattern => @pattern,
214
+ :match => (match != false), :negate => @negate)
202
215
 
203
216
  # Add negate option
204
217
  match = (match and !@negate) || (!match and @negate)
@@ -214,9 +227,9 @@ module LogStash module Codecs class Multiline < LogStash::Codecs::Base
214
227
  def flush(&block)
215
228
  if block_given? && @buffer.any?
216
229
  no_error = true
217
- events = merge_events
230
+ event = merge_events
218
231
  begin
219
- yield events
232
+ yield event
220
233
  rescue ::Exception => e
221
234
  # need to rescue everything
222
235
  # likliest cause: backpressure or timeout by exception
@@ -237,7 +250,9 @@ module LogStash module Codecs class Multiline < LogStash::Codecs::Base
237
250
  end
238
251
 
239
252
  def merge_events
240
- event = LogStash::Event.new(LogStash::Event::TIMESTAMP => @time, "message" => @buffer.join(NL))
253
+ message = @buffer.join(NL)
254
+ event = event_factory.new_event(LogStash::Event::TIMESTAMP => @time, "message" => message)
255
+ event.set @original_field, message.dup.freeze if @original_field
241
256
  event.tag @multiline_tag if !@multiline_tag.empty? && @buffer.size > 1
242
257
  event.tag "multiline_codec_max_bytes_reached" if over_maximum_bytes?
243
258
  event.tag "multiline_codec_max_lines_reached" if over_maximum_lines?
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-multiline'
4
- s.version = '3.0.11'
4
+ s.version = '3.1.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Merges multiline messages 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/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -21,7 +21,8 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
-
24
+ s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.3'
25
+ s.add_runtime_dependency 'logstash-mixin-event_support', '~> 1.0'
25
26
  s.add_runtime_dependency 'logstash-patterns-core'
26
27
  s.add_runtime_dependency 'jls-grok', '~> 0.11.1'
27
28
  s.add_runtime_dependency 'concurrent-ruby'
@@ -7,8 +7,9 @@ require_relative "../supports/helpers.rb"
7
7
  # above helper also defines a subclass of Multiline
8
8
  # called MultilineRspec that exposes the internal buffer
9
9
  # and a Logger Mock
10
+ require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
10
11
 
11
- describe LogStash::Codecs::Multiline do
12
+ describe LogStash::Codecs::Multiline, :ecs_compatibility_support do
12
13
  context "#decode" do
13
14
  let(:config) { {} }
14
15
  let(:codec) { LogStash::Codecs::Multiline.new(config).tap {|c| c.register } }
@@ -23,17 +24,35 @@ describe LogStash::Codecs::Multiline do
23
24
  end
24
25
  end
25
26
 
26
- it "should be able to handle multiline events with additional lines space-indented" do
27
- config.update("pattern" => "^\\s", "what" => "previous")
28
- lines = [ "hello world", " second line", "another first line" ]
29
- line_producer.call(lines)
30
- codec.flush { |e| events << e }
27
+ ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
28
+
29
+ before(:each) do
30
+ allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
31
+ end
32
+
33
+ let(:config) { super().merge "pattern" => "^\\s", "what" => "previous" }
34
+ let(:lines) { [ "hello world", " second line", "another first line" ] }
35
+
36
+ let(:expected_first_multiline) { "hello world\n second line" }
37
+
38
+ before do
39
+ line_producer.call(lines)
40
+ codec.flush { |e| events << e }
41
+ end
42
+
43
+ it "should be able to handle multiline events with additional lines space-indented" do
44
+ expect(events.size).to eq(2)
45
+ expect(events[0].get("message")).to eql expected_first_multiline
46
+ expect(events[0].get("tags")).to include("multiline")
47
+ expect(events[1].get("message")).to eql "another first line"
48
+ expect(events[1].get("tags")).to be_nil
49
+ end
50
+
51
+ it "sets event.original in ECS mode" do
52
+ expect(events.size).to eq(2)
53
+ expect(events[0].get("[event][original]")).to eql expected_first_multiline
54
+ end if ecs_select.active_mode != :disabled
31
55
 
32
- expect(events.size).to eq(2)
33
- expect(events[0].get("message")).to eq "hello world\n second line"
34
- expect(events[0].get("tags")).to include("multiline")
35
- expect(events[1].get("message")).to eq "another first line"
36
- expect(events[1].get("tags")).to be_nil
37
56
  end
38
57
 
39
58
  it "should allow custom tag added to multiline events" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-codec-multiline
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.11
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -20,8 +20,8 @@ dependencies:
20
20
  - !ruby/object:Gem::Version
21
21
  version: '2.99'
22
22
  name: logstash-core-plugin-api
23
- prerelease: false
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
@@ -30,6 +30,34 @@ dependencies:
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ name: logstash-mixin-ecs_compatibility_support
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ name: logstash-mixin-event_support
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
33
61
  - !ruby/object:Gem::Dependency
34
62
  requirement: !ruby/object:Gem::Requirement
35
63
  requirements:
@@ -37,8 +65,8 @@ dependencies:
37
65
  - !ruby/object:Gem::Version
38
66
  version: '0'
39
67
  name: logstash-patterns-core
40
- prerelease: false
41
68
  type: :runtime
69
+ prerelease: false
42
70
  version_requirements: !ruby/object:Gem::Requirement
43
71
  requirements:
44
72
  - - ">="
@@ -51,8 +79,8 @@ dependencies:
51
79
  - !ruby/object:Gem::Version
52
80
  version: 0.11.1
53
81
  name: jls-grok
54
- prerelease: false
55
82
  type: :runtime
83
+ prerelease: false
56
84
  version_requirements: !ruby/object:Gem::Requirement
57
85
  requirements:
58
86
  - - "~>"
@@ -65,8 +93,8 @@ dependencies:
65
93
  - !ruby/object:Gem::Version
66
94
  version: '0'
67
95
  name: concurrent-ruby
68
- prerelease: false
69
96
  type: :runtime
97
+ prerelease: false
70
98
  version_requirements: !ruby/object:Gem::Requirement
71
99
  requirements:
72
100
  - - ">="
@@ -79,8 +107,8 @@ dependencies:
79
107
  - !ruby/object:Gem::Version
80
108
  version: '0'
81
109
  name: logstash-devutils
82
- prerelease: false
83
110
  type: :development
111
+ prerelease: false
84
112
  version_requirements: !ruby/object:Gem::Requirement
85
113
  requirements:
86
114
  - - ">="
@@ -93,8 +121,8 @@ dependencies:
93
121
  - !ruby/object:Gem::Version
94
122
  version: '0'
95
123
  name: insist
96
- prerelease: false
97
124
  type: :development
125
+ prerelease: false
98
126
  version_requirements: !ruby/object:Gem::Requirement
99
127
  requirements:
100
128
  - - ">="
@@ -145,8 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
173
  - !ruby/object:Gem::Version
146
174
  version: '0'
147
175
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.6.13
176
+ rubygems_version: 3.0.6
150
177
  signing_key:
151
178
  specification_version: 4
152
179
  summary: Merges multiline messages into a single event