logstash-core 5.6.16-java → 6.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +4 -7
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/version.rb +4 -8
  5. data/lib/logstash-core_jars.rb +12 -26
  6. data/lib/logstash/agent.rb +261 -246
  7. data/lib/logstash/api/commands/default_metadata.rb +1 -1
  8. data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
  9. data/lib/logstash/api/commands/node.rb +3 -2
  10. data/lib/logstash/api/commands/stats.rb +3 -2
  11. data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
  12. data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
  13. data/lib/logstash/bootstrap_check/default_config.rb +17 -0
  14. data/lib/logstash/compiler.rb +38 -0
  15. data/lib/logstash/compiler/lscl.rb +566 -0
  16. data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
  17. data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
  18. data/lib/logstash/config/config_ast.rb +4 -82
  19. data/lib/logstash/config/mixin.rb +73 -41
  20. data/lib/logstash/config/pipeline_config.rb +48 -0
  21. data/lib/logstash/config/source/base.rb +16 -0
  22. data/lib/logstash/config/source/local.rb +215 -0
  23. data/lib/logstash/config/source_loader.rb +125 -0
  24. data/lib/logstash/converge_result.rb +103 -0
  25. data/lib/logstash/environment.rb +6 -19
  26. data/lib/logstash/errors.rb +2 -0
  27. data/lib/logstash/execution_context.rb +4 -7
  28. data/lib/logstash/filter_delegator.rb +6 -9
  29. data/lib/logstash/inputs/base.rb +0 -2
  30. data/lib/logstash/instrument/collector.rb +5 -7
  31. data/lib/logstash/instrument/metric_store.rb +12 -12
  32. data/lib/logstash/instrument/metric_type/mean.rb +0 -5
  33. data/lib/logstash/instrument/namespaced_metric.rb +0 -4
  34. data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
  35. data/lib/logstash/instrument/null_metric.rb +0 -10
  36. data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
  37. data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
  38. data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
  39. data/lib/logstash/instrument/periodic_pollers.rb +1 -3
  40. data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
  41. data/lib/logstash/logging/logger.rb +15 -47
  42. data/lib/logstash/namespace.rb +0 -1
  43. data/lib/logstash/output_delegator.rb +5 -7
  44. data/lib/logstash/outputs/base.rb +0 -2
  45. data/lib/logstash/pipeline.rb +159 -87
  46. data/lib/logstash/pipeline_action.rb +13 -0
  47. data/lib/logstash/pipeline_action/base.rb +29 -0
  48. data/lib/logstash/pipeline_action/create.rb +47 -0
  49. data/lib/logstash/pipeline_action/reload.rb +48 -0
  50. data/lib/logstash/pipeline_action/stop.rb +23 -0
  51. data/lib/logstash/plugin.rb +0 -1
  52. data/lib/logstash/plugins/hooks_registry.rb +6 -0
  53. data/lib/logstash/plugins/registry.rb +0 -1
  54. data/lib/logstash/program.rb +14 -0
  55. data/lib/logstash/queue_factory.rb +5 -1
  56. data/lib/logstash/runner.rb +58 -80
  57. data/lib/logstash/settings.rb +3 -27
  58. data/lib/logstash/state_resolver.rb +41 -0
  59. data/lib/logstash/util/java_version.rb +6 -0
  60. data/lib/logstash/util/safe_uri.rb +12 -148
  61. data/lib/logstash/util/thread_dump.rb +4 -7
  62. data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
  63. data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
  64. data/lib/logstash/version.rb +10 -8
  65. data/locales/en.yml +3 -54
  66. data/logstash-core.gemspec +8 -35
  67. data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
  68. data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
  69. data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
  70. data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
  71. data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
  72. data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
  73. data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
  74. data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
  75. data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
  76. data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
  77. data/spec/api/spec_helper.rb +106 -0
  78. data/spec/logstash/agent/converge_spec.rb +286 -0
  79. data/spec/logstash/agent/metrics_spec.rb +244 -0
  80. data/spec/logstash/agent_spec.rb +213 -225
  81. data/spec/logstash/compiler/compiler_spec.rb +584 -0
  82. data/spec/logstash/config/config_ast_spec.rb +8 -47
  83. data/spec/logstash/config/mixin_spec.rb +2 -42
  84. data/spec/logstash/config/pipeline_config_spec.rb +75 -0
  85. data/spec/logstash/config/source/local_spec.rb +395 -0
  86. data/spec/logstash/config/source_loader_spec.rb +122 -0
  87. data/spec/logstash/converge_result_spec.rb +179 -0
  88. data/spec/logstash/event_spec.rb +0 -66
  89. data/spec/logstash/execution_context_spec.rb +8 -12
  90. data/spec/logstash/filter_delegator_spec.rb +12 -24
  91. data/spec/logstash/inputs/base_spec.rb +7 -5
  92. data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
  93. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
  94. data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
  95. data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
  96. data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
  97. data/spec/logstash/output_delegator_spec.rb +11 -20
  98. data/spec/logstash/outputs/base_spec.rb +7 -5
  99. data/spec/logstash/pipeline_action/create_spec.rb +83 -0
  100. data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
  101. data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
  102. data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
  103. data/spec/logstash/pipeline_spec.rb +81 -137
  104. data/spec/logstash/plugin_spec.rb +2 -1
  105. data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
  106. data/spec/logstash/queue_factory_spec.rb +13 -1
  107. data/spec/logstash/runner_spec.rb +29 -140
  108. data/spec/logstash/settings/writable_directory_spec.rb +10 -13
  109. data/spec/logstash/settings_spec.rb +0 -91
  110. data/spec/logstash/state_resolver_spec.rb +156 -0
  111. data/spec/logstash/timestamp_spec.rb +2 -6
  112. data/spec/logstash/util/java_version_spec.rb +22 -0
  113. data/spec/logstash/util/safe_uri_spec.rb +0 -56
  114. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
  115. data/spec/support/helpers.rb +9 -11
  116. data/spec/support/matchers.rb +96 -6
  117. data/spec/support/mocks_classes.rb +80 -0
  118. data/spec/support/shared_contexts.rb +2 -27
  119. metadata +100 -149
  120. data/lib/logstash/config/loader.rb +0 -107
  121. data/lib/logstash/config/modules_common.rb +0 -103
  122. data/lib/logstash/config/source/modules.rb +0 -55
  123. data/lib/logstash/config/string_escape.rb +0 -27
  124. data/lib/logstash/dependency_report.rb +0 -131
  125. data/lib/logstash/dependency_report_runner.rb +0 -17
  126. data/lib/logstash/elasticsearch_client.rb +0 -142
  127. data/lib/logstash/instrument/global_metrics.rb +0 -13
  128. data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
  129. data/lib/logstash/modules/cli_parser.rb +0 -74
  130. data/lib/logstash/modules/elasticsearch_config.rb +0 -22
  131. data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
  132. data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
  133. data/lib/logstash/modules/file_reader.rb +0 -36
  134. data/lib/logstash/modules/kibana_base.rb +0 -24
  135. data/lib/logstash/modules/kibana_client.rb +0 -124
  136. data/lib/logstash/modules/kibana_config.rb +0 -105
  137. data/lib/logstash/modules/kibana_dashboards.rb +0 -36
  138. data/lib/logstash/modules/kibana_importer.rb +0 -17
  139. data/lib/logstash/modules/kibana_resource.rb +0 -10
  140. data/lib/logstash/modules/kibana_settings.rb +0 -40
  141. data/lib/logstash/modules/logstash_config.rb +0 -120
  142. data/lib/logstash/modules/resource_base.rb +0 -38
  143. data/lib/logstash/modules/scaffold.rb +0 -52
  144. data/lib/logstash/modules/settings_merger.rb +0 -23
  145. data/lib/logstash/modules/util.rb +0 -17
  146. data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
  147. data/lib/logstash/util/environment_variables.rb +0 -43
  148. data/spec/logstash/config/loader_spec.rb +0 -38
  149. data/spec/logstash/config/string_escape_spec.rb +0 -24
  150. data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
  151. data/spec/logstash/modules/logstash_config_spec.rb +0 -56
  152. data/spec/logstash/modules/scaffold_spec.rb +0 -234
  153. data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
  154. data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
  155. data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
  156. data/versions-gem-copy.yml +0 -12
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+ require "logstash/config/source_loader"
3
+ require "logstash/config/source/base"
4
+ require_relative "../../support/helpers"
5
+
6
+ def temporary_pipeline_config(id, source, reader = "random_reader")
7
+ config_part = org.logstash.common.SourceWithMetadata.new("local", "...", "input {} output {}")
8
+ LogStash::Config::PipelineConfig.new(source, id, [config_part], LogStash::SETTINGS)
9
+ end
10
+
11
+ class DummySource < LogStash::Config::Source::Base
12
+ def pipeline_configs
13
+ [temporary_pipeline_config("dummy_source_id", self.class)]
14
+ end
15
+
16
+ def match?
17
+ @settings.get("path.config") =~ /dummy/
18
+ end
19
+ end
20
+
21
+ class AnotherDummySource < LogStash::Config::Source::Base
22
+ def pipeline_configs
23
+ [temporary_pipeline_config("another_dummy_source_id", self.class)]
24
+ end
25
+
26
+ def match?
27
+ @settings.get("path.config") =~ /another/
28
+ end
29
+ end
30
+
31
+ class FailingSource < LogStash::Config::Source::Base
32
+ def pipeline_configs
33
+ raise "Something went wrong"
34
+ end
35
+
36
+ def match?
37
+ @settings.get("path.config") =~ /fail/
38
+ end
39
+ end
40
+
41
+ describe LogStash::Config::SourceLoader do
42
+ subject { described_class.new }
43
+
44
+ it "default to local source" do
45
+ expect(subject.sources.size).to eq(0)
46
+ end
47
+
48
+ it "allows to override the available source loaders" do
49
+ subject.configure_sources(DummySource)
50
+ expect(subject.sources.size).to eq(1)
51
+ expect(subject.sources).to include(DummySource)
52
+ end
53
+
54
+ it "allows to add a new sources" do
55
+ subject.add_source(DummySource)
56
+ subject.add_source(LogStash::Config::Source::Local)
57
+
58
+ expect(subject.sources.size).to eq(2)
59
+ expect(subject.sources).to include(DummySource, LogStash::Config::Source::Local)
60
+ end
61
+
62
+ context "when no source match" do
63
+ let(:settings) { mock_settings("path.config" => "make it not match") } # match both regex
64
+
65
+ it "raises an exception" do
66
+ subject.configure_sources([DummySource.new(settings), AnotherDummySource.new(settings)])
67
+
68
+ expect { subject.fetch }.to raise_error
69
+ end
70
+ end
71
+
72
+ context "when source loader match" do
73
+ context "when an happen in the source" do
74
+ let(:settings) { mock_settings("path.config" => "dummy fail") }
75
+
76
+ it "wraps the error in a failed result" do
77
+ subject.configure_sources([DummySource.new(settings), FailingSource.new(settings)])
78
+
79
+ result = subject.fetch
80
+
81
+ expect(result.success?).to be_falsey
82
+ expect(result.error).not_to be_nil
83
+ end
84
+ end
85
+
86
+ context "when multiple match" do
87
+ let(:settings) { mock_settings("path.config" => "another dummy") } # match both regex
88
+
89
+ it "return the loaders with the matched sources" do
90
+ subject.configure_sources([DummySource.new(settings), AnotherDummySource.new(settings)])
91
+
92
+ result = subject.fetch
93
+
94
+ expect(result.success?).to be_truthy
95
+ expect(result.response.size).to eq(2)
96
+ expect(result.response.collect(&:pipeline_id)).to include("dummy_source_id", "another_dummy_source_id")
97
+ end
98
+
99
+ context "when duplicate id is returned" do
100
+ it "fails to return pipeline" do
101
+ subject.configure_sources([AnotherDummySource.new(settings), AnotherDummySource.new(settings)])
102
+ result = subject.fetch
103
+ expect(result.success?).to be_falsey
104
+ end
105
+ end
106
+ end
107
+
108
+ context "when one match" do
109
+ let(:settings) { mock_settings("path.config" => "another") } # match both regex
110
+
111
+ it "return the loaders with the matched sources" do
112
+ subject.configure_sources([DummySource.new(settings), AnotherDummySource.new(settings)])
113
+
114
+ result = subject.fetch
115
+
116
+ expect(result.success?).to be_truthy
117
+ expect(result.response.size).to eq(1)
118
+ expect(result.response.collect(&:pipeline_id)).to include("another_dummy_source_id")
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,179 @@
1
+ # encoding: utf-8
2
+ require "logstash/converge_result"
3
+ require "logstash/pipeline_action/stop"
4
+ require "spec_helper"
5
+
6
+ describe LogStash::ConvergeResult do
7
+ let(:expected_actions_count) { 2 }
8
+ let(:action) { LogStash::PipelineAction::Stop.new(:main) }
9
+
10
+ subject { described_class.new(expected_actions_count) }
11
+
12
+
13
+ context "When the action was executed" do
14
+ it "returns the time of execution" do
15
+ expect(LogStash::ConvergeResult::FailedAction.new("testing").executed_at.class).to eq(LogStash::Timestamp)
16
+ expect(LogStash::ConvergeResult::SuccessfulAction.new.executed_at.class).to eq(LogStash::Timestamp)
17
+ end
18
+ end
19
+
20
+ context "conversion of action result" do
21
+ let(:action) { LogStash::PipelineAction::Stop.new(:an_action) }
22
+
23
+ context "booleans" do
24
+ context "True" do
25
+ it "converts to a `SuccessfulAction`" do
26
+ subject.add(action, true)
27
+ expect(subject.successful_actions.keys).to include(action)
28
+ end
29
+ end
30
+
31
+ context "False" do
32
+ it "converts to a `FailedAction`" do
33
+ subject.add(action, false)
34
+ expect(subject.failed_actions.keys).to include(action)
35
+ expect(subject.failed_actions.values.pop.message).to match(/Could not execute action: #{action}/)
36
+ end
37
+ end
38
+ end
39
+
40
+ context "`ActionResult` classes" do
41
+ context "SuccessfulAction" do
42
+ let(:result) { LogStash::ConvergeResult::SuccessfulAction.new }
43
+
44
+ it "doesn't convert the class" do
45
+ subject.add(action, result)
46
+ expect(subject.successful_actions.keys).to include(action)
47
+ expect(subject.successful_actions.values).to include(result)
48
+ end
49
+ end
50
+
51
+ context "FailedAction" do
52
+ let(:result) { LogStash::ConvergeResult::FailedAction.new("could be worse") }
53
+
54
+ it "doesn't convert the class" do
55
+ subject.add(action, result)
56
+ expect(subject.failed_actions.keys).to include(action)
57
+ expect(subject.failed_actions.values).to include(result)
58
+ end
59
+ end
60
+ end
61
+
62
+ context "Exception" do
63
+ it "converts to a `FailedAction" do
64
+ begin
65
+ raise ArgumentError, "hello world"
66
+ rescue => e
67
+ subject.add(action, e)
68
+
69
+ expect(subject.failed_actions.keys).to include(action)
70
+ failed_action = subject.failed_actions.values.pop
71
+
72
+ expect(failed_action.message).to eq("hello world")
73
+ expect(failed_action.backtrace).not_to be_nil
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ context "when not all the actions are executed" do
80
+ context "#complete?" do
81
+ it "returns false" do
82
+ expect(subject.complete?).to be_falsey
83
+ end
84
+ end
85
+
86
+ context "#success?" do
87
+ it "returns false" do
88
+ expect(subject.success?).to be_falsey
89
+ end
90
+ end
91
+ end
92
+
93
+ context "when all the actions are executed" do
94
+ context "all succesfull" do
95
+ let(:success_action) { LogStash::PipelineAction::Stop.new(:success) }
96
+ let(:success_action_2) { LogStash::PipelineAction::Stop.new(:success_2) }
97
+
98
+ before do
99
+ subject.add(success_action, true)
100
+ subject.add(success_action_2, true)
101
+ end
102
+
103
+ context "#success?" do
104
+ it "returns true" do
105
+ expect(subject.success?).to be_truthy
106
+ end
107
+ end
108
+
109
+ context "#complete?" do
110
+ it "returns true" do
111
+ expect(subject.complete?).to be_truthy
112
+ end
113
+ end
114
+
115
+ context "filtering on the actions result" do
116
+ it "returns the successful actions" do
117
+ expect(subject.successful_actions.size).to eq(2)
118
+ expect(subject.successful_actions.keys).to include(success_action, success_action_2)
119
+ end
120
+
121
+ it "returns the failed actions" do
122
+ expect(subject.failed_actions.size).to eq(0)
123
+ end
124
+ end
125
+ end
126
+
127
+ context "not successfully" do
128
+ let(:success_action) { LogStash::PipelineAction::Stop.new(:success) }
129
+ let(:failed_action) { LogStash::PipelineAction::Stop.new(:failed) }
130
+
131
+ before do
132
+ subject.add(failed_action, false)
133
+ subject.add(success_action, true)
134
+ end
135
+
136
+ context "#success?" do
137
+ it "returns false" do
138
+ expect(subject.success?).to be_falsey
139
+ end
140
+ end
141
+
142
+ context "#complete?" do
143
+ it "returns true" do
144
+ expect(subject.complete?).to be_truthy
145
+ end
146
+ end
147
+
148
+ context "#total" do
149
+ it "returns the number of actions" do
150
+ expect(subject.total).to eq(2)
151
+ end
152
+ end
153
+
154
+ context "#fails_count" do
155
+ it "returns the number of actions" do
156
+ expect(subject.fails_count).to eq(1)
157
+ end
158
+ end
159
+
160
+ context "#success_count" do
161
+ it "returns the number of actions" do
162
+ expect(subject.success_count).to eq(1)
163
+ end
164
+ end
165
+
166
+ context "filtering on the actions result" do
167
+ it "returns the successful actions" do
168
+ expect(subject.successful_actions.size).to eq(1)
169
+ expect(subject.successful_actions.keys).to include(success_action)
170
+ end
171
+
172
+ it "returns the failed actions" do
173
+ expect(subject.failed_actions.size).to eq(1)
174
+ expect(subject.failed_actions.keys).to include(failed_action)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -84,15 +84,6 @@ describe LogStash::Event do
84
84
  expect(e.get("foo")).to eq("bar")
85
85
  end
86
86
 
87
- it "should propagate changes to mutable strings to java APIs" do
88
- e = LogStash::Event.new()
89
- e.to_java.setField("foo", "bar")
90
- expect(e.get("foo")).to eq("bar")
91
- e.get("foo").gsub!(/bar/, 'pff')
92
- expect(e.get("foo")).to eq("pff")
93
- expect(e.to_java.getField("foo")).to eq("pff")
94
- end
95
-
96
87
  it "should set deep hash values" do
97
88
  e = LogStash::Event.new()
98
89
  expect(e.set("[foo][bar]", "baz")).to eq("baz")
@@ -352,61 +343,4 @@ describe LogStash::Event do
352
343
  expect { subject.baz() }.to raise_error(NoMethodError, /undefined method `baz' for/)
353
344
  end
354
345
  end
355
-
356
- describe "#clone" do
357
- let(:fieldref) { "[@metadata][fancy]" }
358
- let(:event1) { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => "pants" }) }
359
- let(:event2) { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => {"fancy2" => "pants2"} }) }
360
- let(:event3) { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => {"fancy2" => {"fancy3" => "pants2"}} }) }
361
- let(:event4) { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => {"fancy2" => ["pants1", "pants2"]} }) }
362
- let(:event5) { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => "pants", "smarty" => "pants2" }) }
363
-
364
- it "should clone metadata fields" do
365
- cloned = event1.clone
366
- expect(cloned.get(fieldref)).to eq("pants")
367
- expect(cloned.to_hash_with_metadata).to include("@metadata")
368
- end
369
-
370
- it "should clone metadata fields with nested json" do
371
- cloned = event2.clone
372
- expect(cloned.get(fieldref)).to eq({"fancy2" => "pants2"})
373
- expect(cloned.get("hello")).to eq("world")
374
- expect(cloned.to_hash).not_to include("@metadata")
375
- expect(cloned.to_hash_with_metadata).to include("@metadata")
376
- end
377
-
378
- it "should clone metadata fields with 2-level nested json" do
379
- cloned = event3.clone
380
- expect(cloned.get(fieldref)).to eq({"fancy2" => {"fancy3" => "pants2"}})
381
- expect(cloned.to_hash).not_to include("@metadata")
382
- expect(cloned.to_hash_with_metadata).to include("@metadata")
383
- end
384
-
385
- it "should clone metadata fields with nested json and array value" do
386
- cloned = event4.clone
387
- expect(cloned.get(fieldref)).to eq({"fancy2" => ["pants1", "pants2"]})
388
- expect(cloned.to_hash_with_metadata).to include("@metadata")
389
- end
390
-
391
- it "should clone metadata fields with multiple keys" do
392
- cloned = event5.clone
393
- expect(cloned.get(fieldref)).to eq("pants")
394
- expect(cloned.get("[@metadata][smarty]")).to eq("pants2")
395
- expect(cloned.to_hash_with_metadata).to include("@metadata")
396
- end
397
-
398
- it "mutating cloned event should not affect the original event" do
399
- cloned = event1.clone
400
- cloned.set("hello", "foobar")
401
- expect(cloned.get("hello")).to eq("foobar")
402
- expect(event1.get("hello")).to eq("world")
403
- end
404
-
405
- it "mutating cloned event's metadata should not affect the original event metadata" do
406
- cloned = event1.clone
407
- cloned.set("[@metadata][fancy]", "foobar")
408
- expect(cloned.get("[@metadata][fancy]")).to eq("foobar")
409
- expect(event1.get("[@metadata][fancy]")).to eq("pants")
410
- end
411
- end
412
346
  end
@@ -1,32 +1,28 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
- require "logstash/util/dead_letter_queue_manager"
4
3
  require "logstash/execution_context"
5
4
 
6
5
  describe LogStash::ExecutionContext do
7
6
  let(:pipeline) { double("pipeline") }
8
7
  let(:pipeline_id) { :main }
9
- let(:plugin_id) { "plugin_id" }
10
- let(:plugin_type) { "plugin_type" }
11
- let(:dlq_writer) { LogStash::Util::DummyDeadLetterQueueWriter.new }
12
-
8
+ let(:agent) { double("agent") }
9
+
13
10
  before do
11
+ allow(pipeline).to receive(:agent).and_return(agent)
14
12
  allow(pipeline).to receive(:pipeline_id).and_return(pipeline_id)
15
13
  end
16
14
 
17
- subject { described_class.new(pipeline, plugin_id, plugin_type, dlq_writer) }
15
+ subject { described_class.new(pipeline, agent) }
18
16
 
19
17
  it "returns the `pipeline_id`" do
20
18
  expect(subject.pipeline_id).to eq(pipeline_id)
21
19
  end
22
-
20
+
23
21
  it "returns the pipeline" do
24
22
  expect(subject.pipeline).to eq(pipeline)
25
23
  end
26
-
27
- it "returns the plugin-specific dlq writer" do
28
- expect(subject.dlq_writer.plugin_type).to eq(plugin_type)
29
- expect(subject.dlq_writer.plugin_id).to eq(plugin_id)
30
- expect(subject.dlq_writer.inner_writer).to eq(dlq_writer)
24
+
25
+ it "returns the agent" do
26
+ expect(subject.agent).to eq(agent)
31
27
  end
32
28
  end
@@ -4,35 +4,23 @@ require "logstash/filter_delegator"
4
4
  require "logstash/instrument/null_metric"
5
5
  require "logstash/event"
6
6
  require "logstash/execution_context"
7
+ require "support/shared_contexts"
7
8
 
8
9
  describe LogStash::FilterDelegator do
9
-
10
- class MockGauge
11
- def increment(_)
12
- end
13
- end
14
-
15
10
  include_context "execution_context"
16
-
11
+
17
12
  let(:logger) { double(:logger) }
18
13
  let(:filter_id) { "my-filter" }
19
14
  let(:config) do
20
15
  { "host" => "127.0.0.1", "id" => filter_id }
21
16
  end
22
17
  let(:collector) { [] }
23
- let(:counter_in) { MockGauge.new }
24
- let(:counter_out) { MockGauge.new }
25
- let(:counter_time) { MockGauge.new }
26
18
  let(:metric) { LogStash::Instrument::NamespacedNullMetric.new(collector, :null) }
27
19
  let(:events) { [LogStash::Event.new, LogStash::Event.new] }
28
- let(:default_execution_context) { LogStash::ExecutionContext.new(:main, filter_id, "filter",
29
- LogStash::Util::DummyDeadLetterQueueWriter.new) }
30
20
 
31
21
  before :each do
22
+ allow(pipeline).to receive(:id).and_return(pipeline_id)
32
23
  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
24
  end
37
25
 
38
26
  let(:plugin_klass) do
@@ -43,11 +31,11 @@ describe LogStash::FilterDelegator do
43
31
  end
44
32
  end
45
33
 
46
- subject { described_class.new(logger, plugin_klass, metric, default_execution_context, config) }
34
+ subject { described_class.new(logger, plugin_klass, metric, execution_context, config) }
47
35
 
48
36
  it "create a plugin with the passed options" do
49
37
  expect(plugin_klass).to receive(:new).with(config).and_return(plugin_klass.new(config))
50
- described_class.new(logger, plugin_klass, metric, default_execution_context, config)
38
+ described_class.new(logger, plugin_klass, metric, execution_context, config)
51
39
  end
52
40
 
53
41
  context "when the plugin support flush" do
@@ -72,7 +60,7 @@ describe LogStash::FilterDelegator do
72
60
  context "when the flush return events" do
73
61
  it "increments the out" do
74
62
  subject.multi_filter([LogStash::Event.new])
75
- expect(counter_out).to receive(:increment).with(1)
63
+ expect(metric).to receive(:increment).with(:out, 1)
76
64
  subject.flush({})
77
65
  end
78
66
  end
@@ -90,12 +78,12 @@ describe LogStash::FilterDelegator do
90
78
  end
91
79
 
92
80
  it "has incremented :in" do
93
- expect(counter_in).to receive(:increment).with(events.size)
81
+ expect(metric).to receive(:increment).with(:in, events.size)
94
82
  subject.multi_filter(events)
95
83
  end
96
84
 
97
85
  it "has not incremented :out" do
98
- expect(counter_out).not_to receive(:increment).with(anything)
86
+ expect(metric).not_to receive(:increment).with(:out, anything)
99
87
  subject.multi_filter(events)
100
88
  end
101
89
  end
@@ -121,8 +109,8 @@ describe LogStash::FilterDelegator do
121
109
  end
122
110
 
123
111
  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)
112
+ expect(metric).to receive(:increment).with(:in, events.size)
113
+ expect(metric).to receive(:increment).with(:out, events.size * 2)
126
114
 
127
115
  subject.multi_filter(events)
128
116
  end
@@ -150,8 +138,8 @@ describe LogStash::FilterDelegator do
150
138
  end
151
139
 
152
140
  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)
141
+ expect(metric).to receive(:increment).with(:in, events.size)
142
+ expect(metric).to receive(:increment).with(:out, events.size)
155
143
 
156
144
  subject.multi_filter(events)
157
145
  end