logstash-core 5.4.3-java → 5.5.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core/logstash-core.jar +0 -0
  3. data/lib/logstash-core/version.rb +1 -1
  4. data/lib/logstash/api/commands/hot_threads_reporter.rb +2 -2
  5. data/lib/logstash/api/commands/node.rb +0 -1
  6. data/lib/logstash/api/commands/stats.rb +0 -1
  7. data/lib/logstash/config/mixin.rb +5 -43
  8. data/lib/logstash/config/modules_common.rb +71 -0
  9. data/lib/logstash/elasticsearch_client.rb +120 -0
  10. data/lib/logstash/environment.rb +14 -3
  11. data/lib/logstash/errors.rb +1 -0
  12. data/lib/logstash/execution_context.rb +11 -3
  13. data/lib/logstash/inputs/base.rb +2 -0
  14. data/lib/logstash/instrument/global_metrics.rb +13 -0
  15. data/lib/logstash/instrument/metric_type/mean.rb +5 -0
  16. data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
  17. data/lib/logstash/logging/logger.rb +26 -1
  18. data/lib/logstash/modules/cli_parser.rb +74 -0
  19. data/lib/logstash/modules/elasticsearch_config.rb +22 -0
  20. data/lib/logstash/modules/elasticsearch_resource.rb +10 -0
  21. data/lib/logstash/modules/file_reader.rb +36 -0
  22. data/lib/logstash/modules/importer.rb +37 -0
  23. data/lib/logstash/modules/kibana_base_resource.rb +10 -0
  24. data/lib/logstash/modules/kibana_config.rb +104 -0
  25. data/lib/logstash/modules/kibana_resource.rb +10 -0
  26. data/lib/logstash/modules/logstash_config.rb +48 -0
  27. data/lib/logstash/modules/resource_base.rb +37 -0
  28. data/lib/logstash/modules/scaffold.rb +44 -0
  29. data/lib/logstash/namespace.rb +1 -0
  30. data/lib/logstash/outputs/base.rb +2 -0
  31. data/lib/logstash/pipeline.rb +18 -4
  32. data/lib/logstash/plugin.rb +1 -0
  33. data/lib/logstash/plugins/registry.rb +5 -0
  34. data/lib/logstash/runner.rb +42 -2
  35. data/lib/logstash/settings.rb +7 -1
  36. data/lib/logstash/timestamp.rb +4 -0
  37. data/lib/logstash/util/dead_letter_queue_manager.rb +61 -0
  38. data/lib/logstash/util/safe_uri.rb +130 -11
  39. data/lib/logstash/util/thread_dump.rb +3 -1
  40. data/lib/logstash/util/wrapped_acked_queue.rb +24 -6
  41. data/lib/logstash/util/wrapped_synchronous_queue.rb +19 -5
  42. data/lib/logstash/version.rb +1 -1
  43. data/locales/en.yml +46 -0
  44. data/logstash-core.gemspec +7 -2
  45. data/spec/{api/lib/commands/stats.rb → logstash/api/commands/stats_spec.rb} +7 -2
  46. data/spec/{api/lib → logstash/api}/errors_spec.rb +1 -1
  47. data/spec/{api/lib/api → logstash/api/modules}/logging_spec.rb +1 -10
  48. data/spec/{api/lib/api → logstash/api/modules}/node_plugins_spec.rb +2 -3
  49. data/spec/{api/lib/api → logstash/api/modules}/node_spec.rb +6 -7
  50. data/spec/{api/lib/api → logstash/api/modules}/node_stats_spec.rb +2 -2
  51. data/spec/{api/lib/api → logstash/api/modules}/plugins_spec.rb +4 -3
  52. data/spec/{api/lib/api → logstash/api/modules}/root_spec.rb +3 -3
  53. data/spec/{api/lib → logstash/api}/rack_app_spec.rb +0 -0
  54. data/spec/logstash/config/mixin_spec.rb +2 -2
  55. data/spec/logstash/execution_context_spec.rb +20 -1
  56. data/spec/logstash/filter_delegator_spec.rb +2 -1
  57. data/spec/logstash/inputs/base_spec.rb +1 -1
  58. data/spec/logstash/output_delegator_spec.rb +2 -1
  59. data/spec/logstash/outputs/base_spec.rb +1 -1
  60. data/spec/logstash/pipeline_dlq_commit_spec.rb +107 -0
  61. data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
  62. data/spec/logstash/plugin_spec.rb +1 -1
  63. data/spec/logstash/plugins/registry_spec.rb +22 -5
  64. data/spec/logstash/runner_spec.rb +122 -19
  65. data/spec/logstash/settings_spec.rb +91 -0
  66. data/spec/logstash/timestamp_spec.rb +6 -0
  67. data/spec/support/helpers.rb +80 -1
  68. data/spec/support/matchers.rb +13 -0
  69. data/spec/support/shared_contexts.rb +38 -0
  70. data/spec/support/shared_examples.rb +1 -1
  71. metadata +95 -40
  72. data/spec/api/lib/api/support/resource_dsl_methods.rb +0 -87
  73. data/spec/api/spec_helper.rb +0 -111
@@ -20,6 +20,12 @@ describe LogStash::Timestamp do
20
20
  expect(t.time.to_i).to eq(now.to_i)
21
21
  end
22
22
 
23
+ it "should have consistent behaviour across == and .eql?" do
24
+ its_xmas = Time.utc(2015, 12, 25, 0, 0, 0)
25
+ expect(LogStash::Timestamp.new(its_xmas)).to eql(LogStash::Timestamp.new(its_xmas))
26
+ expect(LogStash::Timestamp.new(its_xmas)).to be ==(LogStash::Timestamp.new(its_xmas))
27
+ end
28
+
23
29
  it "should raise exception on invalid format" do
24
30
  expect{LogStash::Timestamp.new("foobar")}.to raise_error
25
31
  end
@@ -8,9 +8,88 @@ ensure
8
8
  end
9
9
 
10
10
  def clear_data_dir
11
- data_path = agent_settings.get("path.data")
11
+ if defined?(agent_settings)
12
+ data_path = agent_settings.get("path.data")
13
+ else
14
+ data_path = LogStash::SETTINGS.get("path.data")
15
+ end
16
+
12
17
  Dir.foreach(data_path) do |f|
13
18
  next if f == "." || f == ".." || f == ".gitkeep"
14
19
  FileUtils.rm_rf(File.join(data_path, f))
15
20
  end
16
21
  end
22
+
23
+ def mock_settings(settings_values={})
24
+ settings = LogStash::SETTINGS.clone
25
+
26
+ settings_values.each do |key, value|
27
+ settings.set(key, value)
28
+ end
29
+
30
+ settings
31
+ end
32
+
33
+ def make_test_agent(settings=mock_settings)
34
+ ::LogStash::Agent.new(settings)
35
+ end
36
+
37
+ def mock_pipeline(pipeline_id, reloadable = true, config_hash = nil)
38
+ config_string = "input { stdin { id => '#{pipeline_id}' }}"
39
+ settings = mock_settings("pipeline.id" => pipeline_id.to_s,
40
+ "config.string" => config_string,
41
+ "config.reload.automatic" => reloadable)
42
+ pipeline = LogStash::Pipeline.new(config_string, settings)
43
+ pipeline
44
+ end
45
+
46
+ def mock_pipeline_config(pipeline_id, config_string = nil, settings = {})
47
+ config_string = "input { stdin { id => '#{pipeline_id}' }}" if config_string.nil?
48
+
49
+ # This is for older tests when we already have a config
50
+ unless settings.is_a?(LogStash::Settings)
51
+ settings.merge!({ "pipeline.id" => pipeline_id.to_s })
52
+ settings = mock_settings(settings)
53
+ end
54
+
55
+ config_part = org.logstash.common.SourceWithMetadata.new("config_string", "config_string", config_string)
56
+
57
+ LogStash::Config::PipelineConfig.new(LogStash::Config::Source::Local, pipeline_id, config_part, settings)
58
+ end
59
+
60
+ def start_agent(agent)
61
+ agent_task = Stud::Task.new do
62
+ begin
63
+ agent.execute
64
+ rescue => e
65
+ raise "Start Agent exception: #{e}"
66
+ end
67
+ end
68
+
69
+ sleep(0.1) unless subject.running?
70
+ agent_task
71
+ end
72
+
73
+ def temporary_file(content, file_name = Time.now.to_i.to_s, directory = Stud::Temporary.pathname)
74
+ FileUtils.mkdir_p(directory)
75
+ target = ::File.join(directory, file_name)
76
+
77
+ File.open(target, "w+") do |f|
78
+ f.write(content)
79
+ end
80
+ target
81
+ end
82
+
83
+ RSpec::Matchers.define :ir_eql do |expected|
84
+ match do |actual|
85
+ next unless expected.java_kind_of?(org.logstash.config.ir.SourceComponent) && actual.java_kind_of?(org.logstash.config.ir.SourceComponent)
86
+
87
+ expected.sourceComponentEquals(actual)
88
+ end
89
+
90
+ failure_message do |actual|
91
+ "actual value \n#{actual.to_s}\nis not .sourceComponentEquals to the expected value: \n#{expected.to_s}\n"
92
+ end
93
+ end
94
+
95
+ SUPPORT_DIR = Pathname.new(::File.join(::File.dirname(__FILE__), "support"))
@@ -28,3 +28,16 @@ RSpec::Matchers.define :implement_interface_of do |type, key, value|
28
28
  "Expecting `#{expected}` to implements instance methods of `#{actual}`, missing methods: #{missing_methods.join(",")}"
29
29
  end
30
30
  end
31
+
32
+ RSpec::Matchers.define :be_a_config_loading_error_hash do |regex|
33
+ match do |hash|
34
+ expect(hash).to include(:error)
35
+ error = hash[:error]
36
+ expect(error).to be_a(LogStash::ConfigLoadingError)
37
+ expect(error.message).to match(regex)
38
+ end
39
+
40
+ match_when_negated do
41
+ raise "Not implemented"
42
+ end
43
+ end
@@ -0,0 +1,38 @@
1
+ shared_context "execution_context" do
2
+ let(:pipeline) { double("pipeline") }
3
+ let(:pipeline_id) { :main }
4
+ let(:agent) { double("agent") }
5
+ let(:plugin_id) { :plugin_id }
6
+ let(:plugin_type) { :plugin_type }
7
+ let(:dlq_writer) { double("dlq_writer") }
8
+ let(:execution_context) do
9
+ ::LogStash::ExecutionContext.new(pipeline, agent, plugin_id, plugin_type, dlq_writer)
10
+ end
11
+
12
+ before do
13
+ allow(pipeline).to receive(:pipeline_id).and_return(pipeline_id)
14
+ allow(pipeline).to receive(:agent).and_return(agent)
15
+ end
16
+ end
17
+
18
+ shared_context "api setup" do
19
+ before :all do
20
+ clear_data_dir
21
+ settings = mock_settings
22
+ config_string = "input { generator {id => 'api-generator-pipeline' count => 100 } } output { dummyoutput {} }"
23
+ settings.set("config.string", config_string)
24
+ @agent = make_test_agent(settings)
25
+ @agent.register_pipeline(settings)
26
+ @agent.execute
27
+ end
28
+
29
+ after :all do
30
+ @agent.shutdown
31
+ end
32
+
33
+ include Rack::Test::Methods
34
+
35
+ def app()
36
+ described_class.new(nil, @agent)
37
+ end
38
+ end
@@ -97,7 +97,7 @@ end
97
97
 
98
98
  shared_examples "not found" do
99
99
  it "should return a 404 to unknown request" do
100
- do_request { get "/i_want_to_believe-#{Time.now.to_i}" }
100
+ get "/i_want_to_believe-#{Time.now.to_i}"
101
101
  expect(last_response.content_type).to eq("application/json")
102
102
  expect(last_response).not_to be_ok
103
103
  expect(last_response.status).to eq(404)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.3
4
+ version: 5.5.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.0.5
103
+ - !ruby/object:Gem::Dependency
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '='
107
+ - !ruby/object:Gem::Version
108
+ version: 1.6.6
109
+ name: rack
110
+ prerelease: false
111
+ type: :runtime
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: 1.6.6
103
117
  - !ruby/object:Gem::Dependency
104
118
  requirement: !ruby/object:Gem::Requirement
105
119
  requirements:
@@ -139,7 +153,7 @@ dependencies:
139
153
  requirements:
140
154
  - - '='
141
155
  - !ruby/object:Gem::Version
142
- version: 0.9.16
156
+ version: 0.9.19
143
157
  name: jruby-openssl
144
158
  prerelease: false
145
159
  type: :runtime
@@ -147,7 +161,7 @@ dependencies:
147
161
  requirements:
148
162
  - - '='
149
163
  - !ruby/object:Gem::Version
150
- version: 0.9.16
164
+ version: 0.9.19
151
165
  - !ruby/object:Gem::Dependency
152
166
  requirement: !ruby/object:Gem::Requirement
153
167
  requirements:
@@ -162,20 +176,6 @@ dependencies:
162
176
  - - '='
163
177
  - !ruby/object:Gem::Version
164
178
  version: 0.10.6
165
- - !ruby/object:Gem::Dependency
166
- requirement: !ruby/object:Gem::Requirement
167
- requirements:
168
- - - "~>"
169
- - !ruby/object:Gem::Version
170
- version: 0.4.2
171
- name: jrmonitor
172
- prerelease: false
173
- type: :runtime
174
- version_requirements: !ruby/object:Gem::Requirement
175
- requirements:
176
- - - "~>"
177
- - !ruby/object:Gem::Version
178
- version: 0.4.2
179
179
  - !ruby/object:Gem::Dependency
180
180
  requirement: !ruby/object:Gem::Requirement
181
181
  requirements:
@@ -288,6 +288,46 @@ dependencies:
288
288
  - - "~>"
289
289
  - !ruby/object:Gem::Version
290
290
  version: 3.3.9
291
+ - !ruby/object:Gem::Dependency
292
+ requirement: !ruby/object:Gem::Requirement
293
+ requirements:
294
+ - - "~>"
295
+ - !ruby/object:Gem::Version
296
+ version: '5.0'
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: 5.0.4
300
+ name: elasticsearch
301
+ prerelease: false
302
+ type: :runtime
303
+ version_requirements: !ruby/object:Gem::Requirement
304
+ requirements:
305
+ - - "~>"
306
+ - !ruby/object:Gem::Version
307
+ version: '5.0'
308
+ - - ">="
309
+ - !ruby/object:Gem::Version
310
+ version: 5.0.4
311
+ - !ruby/object:Gem::Dependency
312
+ requirement: !ruby/object:Gem::Requirement
313
+ requirements:
314
+ - - ">="
315
+ - !ruby/object:Gem::Version
316
+ version: 0.5.4
317
+ - - "<"
318
+ - !ruby/object:Gem::Version
319
+ version: 1.0.0
320
+ name: manticore
321
+ prerelease: false
322
+ type: :runtime
323
+ version_requirements: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: 0.5.4
328
+ - - "<"
329
+ - !ruby/object:Gem::Version
330
+ version: 1.0.0
291
331
  description: The core components of logstash, the scalable log and event management tool
292
332
  email:
293
333
  - info@elastic.co
@@ -330,6 +370,8 @@ files:
330
370
  - lib/logstash/config/grammar.rb
331
371
  - lib/logstash/config/loader.rb
332
372
  - lib/logstash/config/mixin.rb
373
+ - lib/logstash/config/modules_common.rb
374
+ - lib/logstash/elasticsearch_client.rb
333
375
  - lib/logstash/environment.rb
334
376
  - lib/logstash/errors.rb
335
377
  - lib/logstash/event.rb
@@ -340,6 +382,7 @@ files:
340
382
  - lib/logstash/inputs/base.rb
341
383
  - lib/logstash/inputs/threadable.rb
342
384
  - lib/logstash/instrument/collector.rb
385
+ - lib/logstash/instrument/global_metrics.rb
343
386
  - lib/logstash/instrument/metric.rb
344
387
  - lib/logstash/instrument/metric_store.rb
345
388
  - lib/logstash/instrument/metric_type.rb
@@ -364,6 +407,17 @@ files:
364
407
  - lib/logstash/logging.rb
365
408
  - lib/logstash/logging/json.rb
366
409
  - lib/logstash/logging/logger.rb
410
+ - lib/logstash/modules/cli_parser.rb
411
+ - lib/logstash/modules/elasticsearch_config.rb
412
+ - lib/logstash/modules/elasticsearch_resource.rb
413
+ - lib/logstash/modules/file_reader.rb
414
+ - lib/logstash/modules/importer.rb
415
+ - lib/logstash/modules/kibana_base_resource.rb
416
+ - lib/logstash/modules/kibana_config.rb
417
+ - lib/logstash/modules/kibana_resource.rb
418
+ - lib/logstash/modules/logstash_config.rb
419
+ - lib/logstash/modules/resource_base.rb
420
+ - lib/logstash/modules/scaffold.rb
367
421
  - lib/logstash/namespace.rb
368
422
  - lib/logstash/output_delegator.rb
369
423
  - lib/logstash/output_delegator_strategies/legacy.rb
@@ -397,6 +451,7 @@ files:
397
451
  - lib/logstash/util/buftok.rb
398
452
  - lib/logstash/util/byte_value.rb
399
453
  - lib/logstash/util/charset.rb
454
+ - lib/logstash/util/dead_letter_queue_manager.rb
400
455
  - lib/logstash/util/decorators.rb
401
456
  - lib/logstash/util/duration_formatter.rb
402
457
  - lib/logstash/util/environment_variables.rb
@@ -419,20 +474,18 @@ files:
419
474
  - lib/logstash/webserver.rb
420
475
  - locales/en.yml
421
476
  - logstash-core.gemspec
422
- - spec/api/lib/api/logging_spec.rb
423
- - spec/api/lib/api/node_plugins_spec.rb
424
- - spec/api/lib/api/node_spec.rb
425
- - spec/api/lib/api/node_stats_spec.rb
426
- - spec/api/lib/api/plugins_spec.rb
427
- - spec/api/lib/api/root_spec.rb
428
- - spec/api/lib/api/support/resource_dsl_methods.rb
429
- - spec/api/lib/commands/stats.rb
430
- - spec/api/lib/errors_spec.rb
431
- - spec/api/lib/rack_app_spec.rb
432
- - spec/api/spec_helper.rb
433
477
  - spec/conditionals_spec.rb
434
478
  - spec/logstash/acked_queue_concurrent_stress_spec.rb
435
479
  - spec/logstash/agent_spec.rb
480
+ - spec/logstash/api/commands/stats_spec.rb
481
+ - spec/logstash/api/errors_spec.rb
482
+ - spec/logstash/api/modules/logging_spec.rb
483
+ - spec/logstash/api/modules/node_plugins_spec.rb
484
+ - spec/logstash/api/modules/node_spec.rb
485
+ - spec/logstash/api/modules/node_stats_spec.rb
486
+ - spec/logstash/api/modules/plugins_spec.rb
487
+ - spec/logstash/api/modules/root_spec.rb
488
+ - spec/logstash/api/rack_app_spec.rb
436
489
  - spec/logstash/codecs/base_spec.rb
437
490
  - spec/logstash/config/config_ast_spec.rb
438
491
  - spec/logstash/config/cpu_core_strategy_spec.rb
@@ -467,6 +520,7 @@ files:
467
520
  - spec/logstash/output_delegator_spec.rb
468
521
  - spec/logstash/outputs/base_spec.rb
469
522
  - spec/logstash/patches_spec.rb
523
+ - spec/logstash/pipeline_dlq_commit_spec.rb
470
524
  - spec/logstash/pipeline_pq_file_spec.rb
471
525
  - spec/logstash/pipeline_reporter_spec.rb
472
526
  - spec/logstash/pipeline_spec.rb
@@ -504,6 +558,7 @@ files:
504
558
  - spec/support/helpers.rb
505
559
  - spec/support/matchers.rb
506
560
  - spec/support/mocks_classes.rb
561
+ - spec/support/shared_contexts.rb
507
562
  - spec/support/shared_examples.rb
508
563
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
509
564
  licenses:
@@ -536,20 +591,18 @@ signing_key:
536
591
  specification_version: 4
537
592
  summary: logstash-core - The core components of logstash
538
593
  test_files:
539
- - spec/api/lib/api/logging_spec.rb
540
- - spec/api/lib/api/node_plugins_spec.rb
541
- - spec/api/lib/api/node_spec.rb
542
- - spec/api/lib/api/node_stats_spec.rb
543
- - spec/api/lib/api/plugins_spec.rb
544
- - spec/api/lib/api/root_spec.rb
545
- - spec/api/lib/api/support/resource_dsl_methods.rb
546
- - spec/api/lib/commands/stats.rb
547
- - spec/api/lib/errors_spec.rb
548
- - spec/api/lib/rack_app_spec.rb
549
- - spec/api/spec_helper.rb
550
594
  - spec/conditionals_spec.rb
551
595
  - spec/logstash/acked_queue_concurrent_stress_spec.rb
552
596
  - spec/logstash/agent_spec.rb
597
+ - spec/logstash/api/commands/stats_spec.rb
598
+ - spec/logstash/api/errors_spec.rb
599
+ - spec/logstash/api/modules/logging_spec.rb
600
+ - spec/logstash/api/modules/node_plugins_spec.rb
601
+ - spec/logstash/api/modules/node_spec.rb
602
+ - spec/logstash/api/modules/node_stats_spec.rb
603
+ - spec/logstash/api/modules/plugins_spec.rb
604
+ - spec/logstash/api/modules/root_spec.rb
605
+ - spec/logstash/api/rack_app_spec.rb
553
606
  - spec/logstash/codecs/base_spec.rb
554
607
  - spec/logstash/config/config_ast_spec.rb
555
608
  - spec/logstash/config/cpu_core_strategy_spec.rb
@@ -584,6 +637,7 @@ test_files:
584
637
  - spec/logstash/output_delegator_spec.rb
585
638
  - spec/logstash/outputs/base_spec.rb
586
639
  - spec/logstash/patches_spec.rb
640
+ - spec/logstash/pipeline_dlq_commit_spec.rb
587
641
  - spec/logstash/pipeline_pq_file_spec.rb
588
642
  - spec/logstash/pipeline_reporter_spec.rb
589
643
  - spec/logstash/pipeline_spec.rb
@@ -621,4 +675,5 @@ test_files:
621
675
  - spec/support/helpers.rb
622
676
  - spec/support/matchers.rb
623
677
  - spec/support/mocks_classes.rb
678
+ - spec/support/shared_contexts.rb
624
679
  - spec/support/shared_examples.rb
@@ -1,87 +0,0 @@
1
- # Ruby doesn't have common class for boolean,
2
- # And to simplify the ResourceDSLMethods check it make sense to have it.
3
- module Boolean; end
4
- class TrueClass
5
- include Boolean
6
- end
7
- class FalseClass
8
- include Boolean
9
- end
10
-
11
- module ResourceDSLMethods
12
- # Convert a nested hash to a mapping of key paths to expected classes
13
- def hash_to_mapping(h, path=[], mapping={})
14
- h.each do |k,v|
15
- if v.is_a?(Hash)
16
- hash_to_mapping(v, path + [k], mapping)
17
- else
18
- full_path = path + [k]
19
- mapping[full_path] = v
20
- end
21
- end
22
- mapping
23
- end
24
-
25
- def test_api(expected, path)
26
- context "GET #{path}" do
27
- let(:payload) { LogStash::Json.load(last_response.body) }
28
-
29
- before(:all) do
30
- do_request { get path }
31
- end
32
-
33
- it "should respond OK" do
34
- expect(last_response).to be_ok
35
- end
36
-
37
-
38
- describe "the default metadata" do
39
- it "should include the host" do
40
- expect(payload["host"]).to eql(Socket.gethostname)
41
- end
42
-
43
- it "should include the version" do
44
- expect(payload["version"]).to eql(LOGSTASH_CORE_VERSION)
45
- end
46
-
47
- it "should include the http address" do
48
- expect(payload["http_address"]).to eql("#{Socket.gethostname}:#{::LogStash::WebServer::DEFAULT_PORTS.first}")
49
- end
50
-
51
- it "should include the node name" do
52
- expect(payload["name"]).to eql(@runner.agent.name)
53
- end
54
-
55
- it "should include the node id" do
56
- expect(payload["id"]).to eql(@runner.agent.id)
57
- end
58
- end
59
-
60
- hash_to_mapping(expected).each do |resource_path,klass|
61
- dotted = resource_path.join(".")
62
-
63
- it "should set '#{dotted}' at '#{path}' to be a '#{klass}'" do
64
- expect(last_response).to be_ok # fail early if need be
65
- resource_path_value = resource_path.reduce(payload) do |acc,v|
66
- expect(acc.has_key?(v)).to eql(true), "Expected to find value '#{v}' in structure '#{acc}', but could not. Payload was '#{payload}'"
67
- acc[v]
68
- end
69
- expect(resource_path_value).to be_a(klass), "could not find '#{dotted}' in #{payload}"
70
- end
71
- end
72
- end
73
-
74
- yield if block_given? # Add custom expectations
75
- end
76
-
77
- def test_api_and_resources(expected, xopts={})
78
- xopts[:exclude_from_root] ||= []
79
- root_expectation = expected.clone
80
- xopts[:exclude_from_root].each {|k| root_expectation.delete(k)}
81
- test_api(root_expectation, "/")
82
-
83
- expected.keys.each do |key|
84
- test_api({key => expected[key]}, "/#{key}")
85
- end
86
- end
87
- end