logstash-core 6.0.1-java → 6.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +1 -1
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/logstash-core.rb +14 -2
  5. data/lib/logstash-core_jars.rb +4 -2
  6. data/lib/logstash/agent.rb +8 -2
  7. data/lib/logstash/api/modules/node.rb +11 -5
  8. data/lib/logstash/api/modules/stats.rb +13 -7
  9. data/lib/logstash/compiler.rb +6 -10
  10. data/lib/logstash/compiler/lscl.rb +10 -1
  11. data/lib/logstash/compiler/lscl/helpers.rb +3 -1
  12. data/lib/logstash/config/mixin.rb +2 -2
  13. data/lib/logstash/environment.rb +1 -6
  14. data/lib/logstash/errors.rb +1 -1
  15. data/lib/logstash/event.rb +0 -2
  16. data/lib/logstash/filter_delegator.rb +1 -2
  17. data/lib/logstash/instrument/metric_type/counter.rb +1 -1
  18. data/lib/logstash/instrument/metric_type/gauge.rb +1 -1
  19. data/lib/logstash/instrument/wrapped_write_client.rb +1 -1
  20. data/lib/logstash/java_filter_delegator.rb +79 -0
  21. data/lib/logstash/java_pipeline.rb +690 -0
  22. data/lib/logstash/json.rb +4 -29
  23. data/lib/logstash/output_delegator.rb +3 -2
  24. data/lib/logstash/patches/bugfix_jruby_2558.rb +1 -1
  25. data/lib/logstash/pipeline.rb +32 -89
  26. data/lib/logstash/pipeline_action/create.rb +8 -2
  27. data/lib/logstash/pipeline_action/reload.rb +6 -1
  28. data/lib/logstash/pipeline_reporter.rb +2 -1
  29. data/lib/logstash/pipeline_settings.rb +1 -0
  30. data/lib/logstash/plugins/plugin_factory.rb +100 -0
  31. data/lib/logstash/plugins/registry.rb +18 -7
  32. data/lib/logstash/queue_factory.rb +3 -1
  33. data/lib/logstash/runner.rb +13 -56
  34. data/lib/logstash/settings.rb +2 -2
  35. data/lib/logstash/timestamp.rb +0 -1
  36. data/lib/logstash/util.rb +13 -21
  37. data/lib/logstash/util/java_version.rb +0 -1
  38. data/lib/logstash/util/settings_helper.rb +79 -0
  39. data/lib/logstash/util/{environment_variables.rb → substitution_variables.rb} +10 -8
  40. data/lib/logstash/util/wrapped_acked_queue.rb +17 -108
  41. data/lib/logstash/util/wrapped_synchronous_queue.rb +38 -178
  42. data/locales/en.yml +2 -0
  43. data/spec/conditionals_spec.rb +235 -80
  44. data/spec/logstash/api/modules/node_spec.rb +11 -0
  45. data/spec/logstash/compiler/compiler_spec.rb +28 -2
  46. data/spec/logstash/environment_spec.rb +0 -5
  47. data/spec/logstash/event_spec.rb +7 -2
  48. data/spec/logstash/filter_delegator_spec.rb +1 -1
  49. data/spec/logstash/filters/base_spec.rb +30 -28
  50. data/spec/logstash/instrument/wrapped_write_client_spec.rb +2 -2
  51. data/spec/logstash/java_filter_delegator_spec.rb +176 -0
  52. data/spec/logstash/java_pipeline_spec.rb +933 -0
  53. data/spec/logstash/json_spec.rb +27 -45
  54. data/spec/logstash/plugins/registry_spec.rb +7 -0
  55. data/spec/logstash/queue_factory_spec.rb +5 -2
  56. data/spec/logstash/settings_spec.rb +1 -1
  57. data/spec/logstash/util/java_version_spec.rb +1 -3
  58. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +27 -24
  59. data/spec/logstash/webserver_spec.rb +3 -6
  60. data/spec/support/helpers.rb +5 -0
  61. data/spec/support/pipeline/pipeline_helpers.rb +97 -0
  62. data/versions-gem-copy.yml +5 -2
  63. metadata +14 -5
  64. data/lib/logstash/patches/rubygems.rb +0 -38
@@ -46,6 +46,17 @@ describe LogStash::Api::Modules::Node do
46
46
  end
47
47
  end
48
48
 
49
+ context "broken params in URL" do
50
+
51
+ before(:all) do
52
+ get "/hot_threads?human=?threads=5"
53
+ end
54
+
55
+ it "should return http status 400" do
56
+ expect(last_response.status).to eq(400)
57
+ end
58
+ end
59
+
49
60
  context "when asking for human output" do
50
61
  [
51
62
  "/hot_threads?human",
@@ -47,7 +47,7 @@ describe LogStash::Compiler do
47
47
  end
48
48
  end
49
49
 
50
- subject(:pipeline) { described_class.compile_sources(sources_with_metadata, settings) }
50
+ subject(:pipeline) { described_class.compile_sources(sources_with_metadata, false) }
51
51
 
52
52
  it "should generate a hash" do
53
53
  expect(pipeline.unique_hash).to be_a(String)
@@ -100,7 +100,7 @@ describe LogStash::Compiler do
100
100
  describe "compiling imperative" do
101
101
  let(:source_id) { "fake_sourcefile" }
102
102
  let(:source_with_metadata) { org.logstash.common.SourceWithMetadata.new(source_protocol, source_id, 0, 0, source) }
103
- subject(:compiled) { described_class.compile_imperative(source_with_metadata, settings) }
103
+ subject(:compiled) { described_class.compile_imperative(source_with_metadata, settings.get_value("config.support_escapes")) }
104
104
 
105
105
  context "when config.support_escapes" do
106
106
  let(:parser) { LogStashCompilerLSCLGrammarParser.new }
@@ -194,6 +194,32 @@ describe LogStash::Compiler do
194
194
  end
195
195
  end
196
196
 
197
+ describe "a plugin with multiple array parameter types" do
198
+ let(:plugin_source) { "generator { aarg => [1] aarg => [2] aarg => [3]}" }
199
+ let(:expected_plugin_args) do
200
+ {
201
+ "aarg" => [1, 2, 3]
202
+ }
203
+ end
204
+
205
+ it "should contain the plugin" do
206
+ expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator", expected_plugin_args))
207
+ end
208
+ end
209
+
210
+ describe "a plugin with multiple parameter types that converge to an array" do
211
+ let(:plugin_source) { "generator { aarg => [1] aarg => 2 aarg => '3' aarg => [4] }"}
212
+ let(:expected_plugin_args) do
213
+ {
214
+ "aarg" => [1, 2, "3", 4]
215
+ }
216
+ end
217
+
218
+ it "should contain the plugin" do
219
+ expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator", expected_plugin_args))
220
+ end
221
+ end
222
+
197
223
  describe "a filter plugin that repeats a Hash directive" do
198
224
  let(:source) { "input { } filter { #{plugin_source} } output { } " }
199
225
  subject(:c_plugin) { compiled[:filter] }
@@ -10,11 +10,6 @@ describe LogStash::Environment do
10
10
  let(:default_runtime_location) { File.join(default_jars_location,"runtime-jars","*.jar") }
11
11
  let(:default_test_location) { File.join(default_jars_location,"test-jars","*.jar") }
12
12
 
13
- it "raises an exception if jruby is not available" do
14
- expect(subject).to receive(:jruby?).and_return(false)
15
- expect { subject.load_runtime_jars! }.to raise_error
16
- end
17
-
18
13
  it "find runtime jars in the default location" do
19
14
  expect(subject).to receive(:find_jars).with(default_runtime_location).and_return([])
20
15
  subject.load_runtime_jars!
@@ -10,6 +10,11 @@ TIMESTAMP = "@timestamp"
10
10
 
11
11
  describe LogStash::Event do
12
12
  context "to_json" do
13
+ it "should correctly serialize RubyNil values a Null values" do
14
+ e = LogStash::Event.new({ "null_value" => nil, TIMESTAMP => "2015-05-28T23:02:05.350Z"})
15
+ expect(JSON.parse(e.to_json)).to eq(JSON.parse("{\"null_value\":null,\"@timestamp\":\"2015-05-28T23:02:05.350Z\",\"@version\":\"1\"}"))
16
+ end
17
+
13
18
  it "should serialize simple values" do
14
19
  e = LogStash::Event.new({"foo" => "bar", "bar" => 1, "baz" => 1.0, TIMESTAMP => "2015-05-28T23:02:05.350Z"})
15
20
  expect(JSON.parse(e.to_json)).to eq(JSON.parse("{\"foo\":\"bar\",\"bar\":1,\"baz\":1.0,\"@timestamp\":\"2015-05-28T23:02:05.350Z\",\"@version\":\"1\"}"))
@@ -141,7 +146,7 @@ describe LogStash::Event do
141
146
  end
142
147
 
143
148
  it "should set XXJavaProxy Jackson crafted" do
144
- proxy = org.logstash.Util.getMapFixtureJackson()
149
+ proxy = org.logstash.RspecTestUtils.getMapFixtureJackson()
145
150
  # proxy is {"string": "foo", "int": 42, "float": 42.42, "array": ["bar","baz"], "hash": {"string":"quux"} }
146
151
  e = LogStash::Event.new()
147
152
  e.set("[proxy]", proxy)
@@ -154,7 +159,7 @@ describe LogStash::Event do
154
159
  end
155
160
 
156
161
  it "should set XXJavaProxy hand crafted" do
157
- proxy = org.logstash.Util.getMapFixtureHandcrafted()
162
+ proxy = org.logstash.RspecTestUtils.getMapFixtureHandcrafted()
158
163
  # proxy is {"string": "foo", "int": 42, "float": 42.42, "array": ["bar","baz"], "hash": {"string":"quux"} }
159
164
  e = LogStash::Event.new()
160
165
  e.set("[proxy]", proxy)
@@ -14,7 +14,7 @@ describe LogStash::FilterDelegator do
14
14
  end
15
15
 
16
16
  include_context "execution_context"
17
-
17
+
18
18
  let(:logger) { double(:logger) }
19
19
  let(:filter_id) { "my-filter" }
20
20
  let(:config) do
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
  require "logstash/json"
4
+ require 'support/pipeline/pipeline_helpers'
4
5
 
5
6
  # use a dummy NOOP filter to test Filters::Base
6
7
  class LogStash::Filters::NOOP < LogStash::Filters::Base
@@ -50,6 +51,7 @@ describe LogStash::Filters::Base do
50
51
  end
51
52
 
52
53
  describe LogStash::Filters::NOOP do
54
+ extend PipelineHelpers
53
55
 
54
56
  describe "adding multiple values to one field" do
55
57
  config <<-CONFIG
@@ -61,7 +63,7 @@ describe LogStash::Filters::NOOP do
61
63
  }
62
64
  CONFIG
63
65
 
64
- sample "example" do
66
+ sample_one("example") do
65
67
  insist { subject.get("new_field") } == ["new_value", "new_value_2"]
66
68
  end
67
69
  end
@@ -75,7 +77,7 @@ describe LogStash::Filters::NOOP do
75
77
  }
76
78
  CONFIG
77
79
 
78
- sample("type" => "noop") do
80
+ sample_one("type" => "noop") do
79
81
  insist { subject.get("tags") } == ["test"]
80
82
  end
81
83
  end
@@ -89,11 +91,11 @@ describe LogStash::Filters::NOOP do
89
91
  }
90
92
  CONFIG
91
93
 
92
- sample("type" => "noop") do
94
+ sample_one("type" => "noop") do
93
95
  insist { subject.get("tags") } == ["test"]
94
96
  end
95
97
 
96
- sample("type" => "noop", "tags" => ["t1", "t2"]) do
98
+ sample_one("type" => "noop", "tags" => ["t1", "t2"]) do
97
99
  insist { subject.get("tags") } == ["t1", "t2", "test"]
98
100
  end
99
101
  end
@@ -107,11 +109,11 @@ describe LogStash::Filters::NOOP do
107
109
  }
108
110
  CONFIG
109
111
 
110
- sample("type" => "noop") do
112
+ sample_one("type" => "noop") do
111
113
  insist { subject.get("tags") } == ["bar"]
112
114
  end
113
115
 
114
- sample("type" => "noop", "tags" => "foo") do
116
+ sample_one("type" => "noop", "tags" => "foo") do
115
117
  insist { subject.get("tags") } == ["foo", "bar"]
116
118
  end
117
119
  end
@@ -125,7 +127,7 @@ describe LogStash::Filters::NOOP do
125
127
  }
126
128
  CONFIG
127
129
 
128
- sample("type" => "noop", "tags" => "foo") do
130
+ sample_one("type" => "noop", "tags" => "foo") do
129
131
  # this is completely weird but seems to be already expected in other specs
130
132
  insist { subject.get("tags") } == ["foo", "foo"]
131
133
  end
@@ -140,19 +142,19 @@ describe LogStash::Filters::NOOP do
140
142
  }
141
143
  CONFIG
142
144
 
143
- sample("type" => "noop") do
145
+ sample_one("type" => "noop") do
144
146
  insist { subject.get("tags") } == ["test"]
145
147
  end
146
148
 
147
- sample("type" => "noop", "tags" => ["t1"]) do
149
+ sample_one("type" => "noop", "tags" => ["t1"]) do
148
150
  insist { subject.get("tags") } == ["t1", "test"]
149
151
  end
150
152
 
151
- sample("type" => "noop", "tags" => ["t1", "t2"]) do
153
+ sample_one("type" => "noop", "tags" => ["t1", "t2"]) do
152
154
  insist { subject.get("tags") } == ["t1", "t2", "test"]
153
155
  end
154
156
 
155
- sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
157
+ sample_one("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
156
158
  insist { subject.get("tags") } == ["t1", "t2", "t3", "test"]
157
159
  end
158
160
  end
@@ -166,39 +168,39 @@ describe LogStash::Filters::NOOP do
166
168
  }
167
169
  CONFIG
168
170
 
169
- sample("type" => "noop", "tags" => "foo") do
171
+ sample_one("type" => "noop", "tags" => "foo") do
170
172
  insist { subject.get("tags") } == ["foo"]
171
173
  end
172
174
 
173
- sample("type" => "noop", "tags" => "t2") do
175
+ sample_one("type" => "noop", "tags" => "t2") do
174
176
  insist { subject.get("tags") } == []
175
177
  end
176
178
 
177
- sample("type" => "noop", "tags" => ["t2"]) do
179
+ sample_one("type" => "noop", "tags" => ["t2"]) do
178
180
  insist { subject.get("tags") } == []
179
181
  end
180
182
 
181
- sample("type" => "noop", "tags" => ["t4"]) do
183
+ sample_one("type" => "noop", "tags" => ["t4"]) do
182
184
  insist { subject.get("tags") } == ["t4"]
183
185
  end
184
186
 
185
- sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
187
+ sample_one("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
186
188
  insist { subject.get("tags") } == ["t1"]
187
189
  end
188
190
 
189
191
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
190
192
  # see https://github.com/elastic/logstash/issues/2261
191
- sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\", \"t3\"]}")) do
193
+ sample_one(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\", \"t3\"]}")) do
192
194
  insist { subject.get("tags") } == ["t1"]
193
195
  end
194
196
 
195
- sample("type" => "noop", "tags" => ["t1", "t2"]) do
197
+ sample_one("type" => "noop", "tags" => ["t1", "t2"]) do
196
198
  insist { subject.get("tags") } == ["t1"]
197
199
  end
198
200
 
199
201
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
200
202
  # see https://github.com/elastic/logstash/issues/2261
201
- sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\"]}")) do
203
+ sample_one(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\"]}")) do
202
204
  insist { subject.get("tags") } == ["t1"]
203
205
  end
204
206
  end
@@ -212,13 +214,13 @@ describe LogStash::Filters::NOOP do
212
214
  }
213
215
  CONFIG
214
216
 
215
- sample("type" => "noop", "tags" => ["t1", "goaway", "t3"], "blackhole" => "goaway") do
217
+ sample_one("type" => "noop", "tags" => ["t1", "goaway", "t3"], "blackhole" => "goaway") do
216
218
  insist { subject.get("tags") } == ["t1", "t3"]
217
219
  end
218
220
 
219
221
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
220
222
  # see https://github.com/elastic/logstash/issues/2261
221
- sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"goaway\", \"t3\"], \"blackhole\":\"goaway\"}")) do
223
+ sample_one(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"goaway\", \"t3\"], \"blackhole\":\"goaway\"}")) do
222
224
  insist { subject.get("tags") } == ["t1", "t3"]
223
225
  end
224
226
  end
@@ -232,17 +234,17 @@ describe LogStash::Filters::NOOP do
232
234
  }
233
235
  CONFIG
234
236
 
235
- sample("type" => "noop", "t4" => "four") do
237
+ sample_one("type" => "noop", "t4" => "four") do
236
238
  insist { subject }.include?("t4")
237
239
  end
238
240
 
239
- sample("type" => "noop", "t1" => "one", "t2" => "two", "t3" => "three") do
241
+ sample_one("type" => "noop", "t1" => "one", "t2" => "two", "t3" => "three") do
240
242
  insist { subject }.include?("t1")
241
243
  reject { subject }.include?("t2")
242
244
  reject { subject }.include?("t3")
243
245
  end
244
246
 
245
- sample("type" => "noop", "t1" => "one", "t2" => "two") do
247
+ sample_one("type" => "noop", "t1" => "one", "t2" => "two") do
246
248
  insist { subject }.include?("t1")
247
249
  reject { subject }.include?("t2")
248
250
  end
@@ -257,7 +259,7 @@ describe LogStash::Filters::NOOP do
257
259
  }
258
260
  CONFIG
259
261
 
260
- sample("tags" => "foo") do
262
+ sample_one("tags" => "foo") do
261
263
  reject { subject }.include?("tags")
262
264
  end
263
265
  end
@@ -271,7 +273,7 @@ describe LogStash::Filters::NOOP do
271
273
  }
272
274
  CONFIG
273
275
 
274
- sample("type" => "noop", "t1" => {"t2" => "two", "t3" => "three"}) do
276
+ sample_one("type" => "noop", "t1" => {"t2" => "two", "t3" => "three"}) do
275
277
  insist { subject }.include?("t1")
276
278
  reject { subject }.include?("[t1][t2]")
277
279
  insist { subject }.include?("[t1][t3]")
@@ -287,7 +289,7 @@ describe LogStash::Filters::NOOP do
287
289
  }
288
290
  CONFIG
289
291
 
290
- sample("type" => "noop", "t1" => ["t2", "t3"]) do
292
+ sample_one("type" => "noop", "t1" => ["t2", "t3"]) do
291
293
  insist { subject }.include?("t1")
292
294
  insist { subject.get("[t1][0]") } == "t3"
293
295
  end
@@ -302,7 +304,7 @@ describe LogStash::Filters::NOOP do
302
304
  }
303
305
  CONFIG
304
306
 
305
- sample("type" => "noop", "blackhole" => "go", "go" => "away") do
307
+ sample_one("type" => "noop", "blackhole" => "go", "go" => "away") do
306
308
  insist { subject }.include?("blackhole")
307
309
  reject { subject }.include?("go")
308
310
  end
@@ -47,7 +47,7 @@ describe LogStash::Instrument::WrappedWriteClient do
47
47
  end
48
48
 
49
49
  it "pushes batch to the `WriteClient`" do
50
- batch = write_client.get_new_batch
50
+ batch = []
51
51
  batch << event
52
52
 
53
53
  pusher_thread = Thread.new(subject, batch) do |_subject, _batch|
@@ -101,7 +101,7 @@ describe LogStash::Instrument::WrappedWriteClient do
101
101
  end
102
102
 
103
103
  context "WrappedSynchronousQueue" do
104
- let(:queue) { LogStash::Util::WrappedSynchronousQueue.new }
104
+ let(:queue) { LogStash::Util::WrappedSynchronousQueue.new(1024) }
105
105
 
106
106
  before do
107
107
  read_client.set_events_metric(metric.namespace([:stats, :events]))
@@ -0,0 +1,176 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/java_filter_delegator"
4
+ require "logstash/instrument/null_metric"
5
+ require "logstash/event"
6
+ require "logstash/execution_context"
7
+ require "support/shared_contexts"
8
+
9
+ describe LogStash::JavaFilterDelegator do
10
+
11
+ class MockGauge
12
+ def increment(_)
13
+ end
14
+ end
15
+
16
+ include_context "execution_context"
17
+
18
+ let(:logger) { double(:logger) }
19
+ let(:filter_id) { "my-filter" }
20
+ let(:config) do
21
+ { "host" => "127.0.0.1", "id" => filter_id }
22
+ end
23
+ let(:collector) { [] }
24
+ let(:counter_in) { MockGauge.new }
25
+ let(:counter_out) { MockGauge.new }
26
+ let(:counter_time) { MockGauge.new }
27
+ let(:metric) { LogStash::Instrument::NamespacedNullMetric.new(collector, :null) }
28
+ let(:events) { [LogStash::Event.new, LogStash::Event.new] }
29
+
30
+ before :each do
31
+ allow(pipeline).to receive(:id).and_return(pipeline_id)
32
+ allow(metric).to receive(:namespace).with(anything).and_return(metric)
33
+ allow(metric).to receive(:counter).with(:in).and_return(counter_in)
34
+ allow(metric).to receive(:counter).with(:out).and_return(counter_out)
35
+ allow(metric).to receive(:counter).with(:duration_in_millis).and_return(counter_time)
36
+ end
37
+
38
+ let(:plugin_klass) do
39
+ Class.new(LogStash::Filters::Base) do
40
+ config_name "super_plugin"
41
+ config :host, :validate => :string
42
+ def register; end
43
+ end
44
+ end
45
+
46
+ subject { described_class.new(logger, plugin_klass, metric, execution_context, config) }
47
+
48
+ it "create a plugin with the passed options" do
49
+ expect(plugin_klass).to receive(:new).with(config).and_return(plugin_klass.new(config))
50
+ described_class.new(logger, plugin_klass, metric, execution_context, config)
51
+ end
52
+
53
+ context "when the plugin support flush" do
54
+ let(:plugin_klass) do
55
+ Class.new(LogStash::Filters::Base) do
56
+ config_name "super_plugin"
57
+ config :host, :validate => :string
58
+ def register; end
59
+ def flush(options = {}); @events ; end
60
+ def filter(event)
61
+ @events ||= []
62
+ @events << event
63
+ event.cancel
64
+ end
65
+ end
66
+ end
67
+
68
+ it "defines a flush method" do
69
+ expect(subject.respond_to?(:flush)).to be_truthy
70
+ end
71
+
72
+ context "when the flush return events" do
73
+ it "increments the out" do
74
+ subject.multi_filter([LogStash::Event.new])
75
+ expect(counter_out).to receive(:increment).with(1)
76
+ subject.flush({})
77
+ end
78
+ end
79
+
80
+ context "when the flush doesn't return anything" do
81
+ it "doesnt increment the out" do
82
+ expect(metric).not_to receive(:increment)
83
+ subject.flush({})
84
+ end
85
+ end
86
+
87
+ context "when the filter buffer events" do
88
+ before do
89
+ allow(metric).to receive(:increment).with(anything, anything)
90
+ end
91
+
92
+ it "has incremented :in" do
93
+ expect(counter_in).to receive(:increment).with(events.size)
94
+ subject.multi_filter(events)
95
+ end
96
+
97
+ it "has not incremented :out" do
98
+ expect(counter_out).not_to receive(:increment).with(anything)
99
+ subject.multi_filter(events)
100
+ end
101
+ end
102
+
103
+ context "when the filter create more events" do
104
+ let(:plugin_klass) do
105
+ Class.new(LogStash::Filters::Base) do
106
+ config_name "super_plugin"
107
+ config :host, :validate => :string
108
+ def register; end
109
+ def flush(options = {}); @events ; end
110
+
111
+ # naive split filter implementation
112
+ def filter(event)
113
+ event.cancel
114
+ 2.times { yield LogStash::Event.new }
115
+ end
116
+ end
117
+ end
118
+
119
+ before do
120
+ allow(metric).to receive(:increment).with(anything, anything)
121
+ end
122
+
123
+ it "increments the in/out of the metric" do
124
+ expect(counter_in).to receive(:increment).with(events.size)
125
+ expect(counter_out).to receive(:increment).with(events.size * 2)
126
+
127
+ subject.multi_filter(events)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "when the plugin doesnt support flush" do
133
+ let(:plugin_klass) do
134
+ Class.new(LogStash::Filters::Base) do
135
+ config_name "super_plugin"
136
+ config :host, :validate => :string
137
+ def register; end
138
+ def filter(event)
139
+ event
140
+ end
141
+ end
142
+ end
143
+
144
+ before do
145
+ allow(metric).to receive(:increment).with(anything, anything)
146
+ end
147
+
148
+ it "doesnt define a flush method" do
149
+ expect(subject.has_flush).to be_falsey
150
+ end
151
+
152
+ it "increments the in/out of the metric" do
153
+ expect(counter_in).to receive(:increment).with(events.size)
154
+ expect(counter_out).to receive(:increment).with(events.size)
155
+
156
+ subject.multi_filter(events)
157
+ end
158
+ end
159
+
160
+ context "#config_name" do
161
+ it "proxy the config_name to the class method" do
162
+ expect(subject.config_name).to eq("super_plugin")
163
+ end
164
+ end
165
+
166
+ context "delegate methods to the original plugin" do
167
+ # I am not testing the behavior of these methods
168
+ # this is done in the plugin tests. I just want to make sure
169
+ # the proxy delegates the methods.
170
+ LogStash::JavaFilterDelegator::DELEGATED_METHODS.each do |method|
171
+ it "delegate method: `#{method}` to the filter" do
172
+ expect(subject.respond_to?(method))
173
+ end
174
+ end
175
+ end
176
+ end