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
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "logstash/config/loader"
4
-
5
- describe LogStash::Config::Loader do
6
- let(:logger) { double("logger") }
7
- subject { described_class.new(logger) }
8
-
9
- context "when local" do
10
- before { expect(subject).to receive(:local_config).with(path) }
11
-
12
- context "unix" do
13
- let(:path) { './test.conf' }
14
- it 'works with relative path' do
15
- subject.load_config(path)
16
- end
17
- end
18
-
19
- context "windows" do
20
- let(:path) { '.\test.conf' }
21
- it 'work with relative windows path' do
22
- subject.load_config(path)
23
- end
24
- end
25
- end
26
-
27
- context "when remote" do
28
- context 'supported scheme' do
29
- let(:path) { "http://test.local/superconfig.conf" }
30
- let(:dummy_config) { 'input {}' }
31
-
32
- before { expect(Net::HTTP).to receive(:get) { dummy_config } }
33
- it 'works with http' do
34
- expect(subject.load_config(path)).to eq("#{dummy_config}\n")
35
- end
36
- end
37
- end
38
- end
@@ -1,24 +0,0 @@
1
-
2
- require "logstash/config/string_escape"
3
-
4
- describe LogStash::Config::StringEscape do
5
- let(:result) { described_class.process_escapes(text) }
6
-
7
- table = {
8
- '\\"' => '"',
9
- "\\'" => "'",
10
- "\\n" => "\n",
11
- "\\r" => "\r",
12
- "\\t" => "\t",
13
- "\\\\" => "\\",
14
- }
15
-
16
- table.each do |input, expected|
17
- context "when processing #{input.inspect}" do
18
- let(:text) { input }
19
- it "should produce #{expected.inspect}" do
20
- expect(result).to be == expected
21
- end
22
- end
23
- end
24
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "logstash/instrument/periodic_poller/dlq"
4
- require "logstash/instrument/collector"
5
-
6
- describe LogStash::Instrument::PeriodicPoller::DeadLetterQueue do
7
- subject { LogStash::Instrument::PeriodicPoller::DeadLetterQueue }
8
-
9
- let(:metric) { LogStash::Instrument::Metric.new(LogStash::Instrument::Collector.new) }
10
- let(:agent) { double("agent")}
11
- let(:options) { {} }
12
- subject(:dlq) { described_class.new(metric, agent, options) }
13
-
14
- it "should initialize cleanly" do
15
- expect { dlq }.not_to raise_error
16
- end
17
- end
@@ -1,56 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/modules/logstash_config"
3
-
4
- describe LogStash::Modules::LogStashConfig do
5
- let(:mod) { instance_double("Modules", :directory => Stud::Temporary.directory, :module_name => "testing") }
6
- let(:settings) { {"var.logstash.testing.pants" => "fancy" }}
7
- subject { described_class.new(mod, settings) }
8
-
9
- describe "configured inputs" do
10
- context "when no inputs is send" do
11
- it "returns the default" do
12
- expect(subject.configured_inputs(["kafka"])).to include("kafka")
13
- end
14
- end
15
-
16
- context "when inputs are send" do
17
- let(:settings) { { "var.inputs" => "tcp" } }
18
-
19
- it "returns the configured inputs" do
20
- expect(subject.configured_inputs(["kafka"])).to include("tcp")
21
- end
22
-
23
- context "when alias is specified" do
24
- let(:settings) { { "var.inputs" => "smartconnector" } }
25
-
26
- it "returns the configured inputs" do
27
- expect(subject.configured_inputs(["kafka"], { "smartconnector" => "tcp" })).to include("tcp", "smartconnector")
28
- end
29
- end
30
- end
31
- end
32
-
33
- describe "array to logstash array string" do
34
- it "return an escaped string" do
35
- expect(subject.array_to_string(["hello", "ninja"])).to eq("['hello', 'ninja']")
36
- end
37
- end
38
-
39
- describe "alias modules options" do
40
- let(:alias_table) do
41
- { "var.logstash.testing" => "var.logstash.better" }
42
- end
43
-
44
- before do
45
- subject.alias_settings_keys!(alias_table)
46
- end
47
-
48
- it "allow to retrieve settings" do
49
- expect(subject.setting("var.logstash.better.pants", "dont-exist")).to eq("fancy")
50
- end
51
-
52
- it "allow to retrieve settings with the original name" do
53
- expect(subject.setting("var.logstash.testing.pants", "dont-exist")).to eq("fancy")
54
- end
55
- end
56
- end
@@ -1,234 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require "logstash/namespace"
4
- require "logstash/elasticsearch_client"
5
- require "logstash/modules/kibana_client"
6
- require "logstash/modules/kibana_config"
7
- require "logstash/modules/scaffold"
8
- require "logstash/modules/elasticsearch_importer"
9
- require "logstash/modules/kibana_importer"
10
-
11
- require_relative "../../support/helpers"
12
-
13
- describe LogStash::Modules::Scaffold do
14
- let(:base_dir) { "gem-home" }
15
- let(:mname) { "foo" }
16
- subject(:test_module) { described_class.new(mname, base_dir) }
17
- let(:module_settings) do
18
- {
19
- "var.elasticsearch.hosts" => "es.mycloud.com:9200",
20
- "var.elasticsearch.user" => "foo",
21
- "var.elasticsearch.password" => "password",
22
- "var.input.tcp.port" => 5606,
23
- }
24
- end
25
- let(:dashboard_hash) do
26
- {
27
- "hits" => 0,
28
- "timeRestore" => false,
29
- "description" => "",
30
- "title" => "Filebeat Apache2 Dashboard",
31
- "uiStateJSON" => "{}",
32
- "panelsJSON" => '[{"col":1,"id":"foo-c","panelIndex":1,"row":1,"size_x":12,"size_y":3,"type":"visualization"},{"id":"foo-d","type":"search","panelIndex":7,"size_x":12,"size_y":3,"col":1,"row":11,"columns":["apache2.error.client","apache2.error.level","apache2.error.module","apache2.error.message"],"sort":["@timestamp","desc"]}]',
33
- "optionsJSON" => "{}",
34
- "version" => 1,
35
- "kibanaSavedObjectMeta" => {
36
- "searchSourceJSON" => "{}"
37
- }
38
- }
39
- end
40
- let(:viz_hash) do
41
- {
42
- "visState" => "",
43
- "description" => "",
44
- "title" => "foo-c",
45
- "uiStateJSON" => "",
46
- "version" => 1,
47
- "savedSearchId" => "foo-e",
48
- "kibanaSavedObjectMeta" => {}
49
- }
50
- end
51
- let(:index_pattern_hash) do
52
- {
53
- "title" => "foo-*",
54
- "timeFieldName" =>"time",
55
- "fieldFormatMap" => "{some map}",
56
- "fields" => "[some array]"
57
- }
58
- end
59
- context "logstash operation" do
60
- let(:ls_conf) do
61
- <<-ERB
62
- input {
63
- tcp {
64
- port => <%= setting("var.input.tcp.port", 45) %>
65
- host => <%= setting("var.input.tcp.host", "localhost") %>
66
- type => <%= setting("var.input.tcp.type", "server") %>
67
- }
68
- }
69
- filter {
70
-
71
- }
72
- output {
73
- <%= elasticsearch_output_config() %>
74
- }
75
- ERB
76
- end
77
-
78
- before do
79
- allow(LogStash::Modules::FileReader).to receive(:read).and_return(ls_conf)
80
- end
81
-
82
- it "provides a logstash config" do
83
- expect(test_module.logstash_configuration).to be_nil
84
- test_module.with_settings(module_settings)
85
- expect(test_module.logstash_configuration).not_to be_nil
86
- config_string = test_module.config_string
87
- expect(config_string).to include("port => 5606")
88
- expect(config_string).to include("hosts => ['es.mycloud.com:9200']")
89
- end
90
- end
91
-
92
- context "elasticsearch operation" do
93
- it "provides the elasticsearch mapping file paths" do
94
- test_module.with_settings(module_settings)
95
- expect(test_module.elasticsearch_configuration).not_to be_nil
96
- files = test_module.elasticsearch_configuration.resources
97
- expect(files.size).to eq(1)
98
- expect(files.first).to be_a(LogStash::Modules::ElasticsearchResource)
99
- expect(files.first.content_path).to eq("gem-home/elasticsearch/foo.json")
100
- expect(files.first.import_path).to eq("_template/foo")
101
- end
102
- end
103
-
104
- context "kibana operation" do
105
- before do
106
- # allow(LogStash::Modules::FileReader).to receive(:read_json).and_return({})
107
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/dashboard/foo.json").and_return(["Foo-Dashboard"])
108
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/dashboard/Foo-Dashboard.json").and_return(dashboard_hash)
109
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/visualization/foo-c.json").and_return(viz_hash)
110
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/search/foo-d.json").and_return({"d" => "search"})
111
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/search/foo-e.json").and_return({"e" => "search"})
112
- allow(LogStash::Modules::FileReader).to receive(:read_json).with("gem-home/kibana/index-pattern/foo.json").and_return(index_pattern_hash)
113
- end
114
-
115
- it "provides a list of importable files" do
116
- expect(test_module.kibana_configuration).to be_nil
117
- test_module.with_settings(module_settings)
118
- expect(test_module.kibana_configuration).not_to be_nil
119
- resources = test_module.kibana_configuration.resources
120
- expect(resources.size).to eq(2)
121
- resource1 = resources[0]
122
- resource2 = resources[1]
123
- expect(resource1).to be_a(LogStash::Modules::KibanaSettings)
124
- expect(resource2).to be_a(LogStash::Modules::KibanaDashboards)
125
- expect(resource1.import_path).to eq("api/kibana/settings")
126
- expect(resource1.content).to be_a(Array)
127
- expect(resource1.content.size).to eq(1)
128
-
129
- test_object = resource1.content[0]
130
- expect(test_object).to be_a(LogStash::Modules::KibanaSettings::Setting)
131
- expect(test_object.name).to eq("defaultIndex")
132
- expect(test_object.value).to eq("foo-*")
133
-
134
- expect(resource2.import_path).to eq("api/kibana/dashboards/import")
135
- expect(resource2.content).to be_a(Array)
136
- expect(resource2.content.size).to eq(5)
137
- expect(resource2.content.map{|o| o.class}.uniq).to eq([LogStash::Modules::KibanaResource])
138
-
139
- test_object = resource2.content[0]
140
- expect(test_object.content_id).to eq("foo-*")
141
- expect(test_object.content_type).to eq("index-pattern")
142
- expect(test_object.content_as_object).to eq(index_pattern_hash)
143
-
144
- test_object = resource2.content[1]
145
- expect(test_object.content_id).to eq("Foo-Dashboard")
146
- expect(test_object.content_type).to eq("dashboard")
147
- expect(test_object.content_as_object).to eq(dashboard_hash)
148
-
149
- test_object = resource2.content[2]
150
- expect(test_object.content_id).to eq("foo-c") #<- the panels can contain items from other folders
151
- expect(test_object.content_type).to eq("visualization")
152
- expect(test_object.content_as_object).to eq(viz_hash)
153
- expect(test_object.content_as_object["savedSearchId"]).to eq("foo-e")
154
-
155
- test_object = resource2.content[3]
156
- expect(test_object.content_id).to eq("foo-d") #<- the panels can contain items from other folders
157
- expect(test_object.content_type).to eq("search")
158
- expect(test_object.content_as_object).to eq("d"=>"search")
159
-
160
- test_object = resource2.content[4]
161
- expect(test_object.content_id).to eq("foo-e") # <- the visualization can contain items from the search folder
162
- expect(test_object.content_type).to eq("search")
163
- expect(test_object.content_as_object).to eq("e"=>"search")
164
- end
165
- end
166
-
167
- context "importing to elasticsearch stubbed client" do
168
- let(:mname) { "tester" }
169
- let(:base_dir) { File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "modules_test_files", "modules", "#{mname}", "configuration")) }
170
- let(:response) { double(:response) }
171
- let(:client) { double(:client) }
172
- let(:kbnclient) { double(:kbnclient) }
173
- let(:paths) { [] }
174
- let(:expected_paths) { ["_template/tester", "api/kibana/settings", "api/kibana/dashboards/import"] }
175
- let(:contents) { [] }
176
- let(:expected_objects) do
177
- [
178
- "index-pattern tester-*",
179
- "dashboard FW-Dashboard",
180
- "visualization FW-Viz-1",
181
- "visualization FW-Viz-2",
182
- "search Search-Tester"
183
- ]
184
- end
185
-
186
- before do
187
- allow(response).to receive(:status).and_return(404)
188
- allow(client).to receive(:head).and_return(response)
189
- allow(kbnclient).to receive(:version).and_return("9.8.7-6")
190
- end
191
-
192
- it "calls the import method" do
193
- expect(client).to receive(:put).once do |path, content|
194
- paths << path
195
- LogStash::ElasticsearchClient::Response.new(201, "", {})
196
- end
197
- expect(kbnclient).to receive(:post).twice do |path, content|
198
- paths << path
199
- contents << content
200
- LogStash::Modules::KibanaClient::Response.new(201, "", {})
201
- end
202
- test_module.with_settings(module_settings)
203
- test_module.import(LogStash::Modules::ElasticsearchImporter.new(client), LogStash::Modules::KibanaImporter.new(kbnclient))
204
- expect(paths).to eq(expected_paths)
205
- expect(contents[0]).to eq({"changes"=>{"defaultIndex"=>"tester-*"}})
206
- second_kbn_post = contents[1]
207
- expect(second_kbn_post[:version]).to eq("9.8.7-6")
208
- expect(second_kbn_post[:objects]).to be_a(Array)
209
- expect(second_kbn_post[:objects].size).to eq(5)
210
- objects_types_ids = second_kbn_post[:objects].map {|h| "#{h["type"]} #{h["id"]}"}
211
- expect(objects_types_ids).to eq(expected_objects)
212
- end
213
- end
214
-
215
- context "import 4 realz", :skip => "integration" do
216
- let(:mname) { "cef" }
217
- let(:base_dir) { File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "modules_test_files", "#{mname}")) }
218
- let(:module_settings) do
219
- {
220
- "var.elasticsearch.hosts" => "localhost:9200",
221
- "var.elasticsearch.user" => "foo",
222
- "var.elasticsearch.password" => "password",
223
- "var.input.tcp.port" => 5606,
224
- }
225
- end
226
- it "puts stuff in ES" do
227
- test_module.with_settings(module_settings)
228
- client = LogStash::ElasticsearchClient.build(module_settings)
229
- import_engine = LogStash::Modules::Importer.new(client)
230
- test_module.import(import_engine)
231
- expect(1).to eq(1)
232
- end
233
- end
234
- end
@@ -1,109 +0,0 @@
1
- # encoding: utf-8
2
- require "tmpdir"
3
- require "spec_helper"
4
- require "logstash/codecs/plain"
5
- require_relative "../support/mocks_classes"
6
-
7
- class SingleGeneratorInput < LogStash::Inputs::Base
8
- config_name "singlegenerator"
9
- milestone 2
10
-
11
- def register
12
- end
13
-
14
- def run(queue)
15
- queue << LogStash::Event.new
16
- end
17
-
18
- def close
19
- end
20
- end
21
-
22
- class DLQCommittingFilter < LogStash::Filters::Base
23
- config_name "dlq_commit"
24
- milestone 2
25
-
26
- def register()
27
- end
28
-
29
- def filter(event)
30
- execution_context.dlq_writer.write(event, "my reason")
31
- end
32
-
33
- def threadsafe?() true; end
34
-
35
- def close() end
36
- end
37
-
38
- describe LogStash::Pipeline do
39
- let(:pipeline_settings_obj) { LogStash::SETTINGS }
40
- let(:pipeline_settings) do
41
- {
42
- "pipeline.workers" => 2,
43
- "pipeline.id" => pipeline_id,
44
- "dead_letter_queue.enable" => enable_dlq,
45
- "path.dead_letter_queue" => Dir.mktmpdir
46
- }
47
- end
48
- let(:metric) { LogStash::Instrument::Metric.new(LogStash::Instrument::Collector.new) }
49
- let(:test_config) {
50
- <<-eos
51
- input { singlegenerator { id => input_id } }
52
-
53
- filter { dlq_commit { id => filter_id } }
54
-
55
- output { dummyoutput { id => output_id } }
56
- eos
57
- }
58
-
59
- subject { LogStash::Pipeline.new(test_config, pipeline_settings_obj, metric) }
60
-
61
- before(:each) do
62
- pipeline_settings.each {|k, v| pipeline_settings_obj.set(k, v) }
63
- allow(LogStash::Plugin).to receive(:lookup).with("input", "singlegenerator").and_return(SingleGeneratorInput)
64
- allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(LogStash::Codecs::Plain)
65
- allow(LogStash::Plugin).to receive(:lookup).with("filter", "dlq_commit").and_return(DLQCommittingFilter)
66
- allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(::LogStash::Outputs::DummyOutput)
67
- end
68
-
69
- after(:each) do
70
- FileUtils.rm_rf(pipeline_settings["path.dead_letter_queue"])
71
- end
72
-
73
- context "dlq is enabled" do
74
- let(:enable_dlq) { true }
75
- let(:pipeline_id) { "test-dlq" }
76
-
77
- it "retrieves proper pipeline-level DLQ writer" do
78
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "input_id", "singlegenerator").and_call_original
79
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "filter_id", "dlq_commit").and_call_original
80
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "output_id", "dummyoutput").and_call_original
81
- expect_any_instance_of(org.logstash.common.io.DeadLetterQueueWriter).to receive(:close).and_call_original
82
- subject.run
83
- dlq_path = java.nio.file.Paths.get(pipeline_settings_obj.get("path.dead_letter_queue"), pipeline_id)
84
- dlq_reader = org.logstash.common.io.DeadLetterQueueReader.new(dlq_path)
85
- entry = dlq_reader.pollEntry(40)
86
- expect(entry).to_not be_nil
87
- expect(entry.reason).to eq("my reason")
88
- subject.shutdown
89
- end
90
- end
91
-
92
- context "dlq is disabled" do
93
- let(:enable_dlq) { false }
94
- let(:pipeline_id) { "test-without-dlq" }
95
-
96
- it "does not write to the DLQ" do
97
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "input_id", "singlegenerator").and_call_original
98
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "filter_id", "dlq_commit").and_call_original
99
- expect(LogStash::Util::PluginDeadLetterQueueWriter).to receive(:new).with(anything, "output_id", "dummyoutput").and_call_original
100
- expect(LogStash::Util::DummyDeadLetterQueueWriter).to receive(:new).and_call_original
101
- expect_any_instance_of(LogStash::Util::DummyDeadLetterQueueWriter).to receive(:close).and_call_original
102
- subject.run
103
- dlq_path = java.nio.file.Paths.get(pipeline_settings_obj.get("path.dead_letter_queue"), pipeline_id)
104
- expect(java.nio.file.Files.exists(dlq_path)).to eq(false)
105
- subject.shutdown
106
- end
107
- end
108
-
109
- end