logstash-core 5.6.16-java → 6.0.0.alpha1-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 (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,36 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require_relative "kibana_base"
5
-
6
- module LogStash module Modules class KibanaDashboards < KibanaBase
7
- include LogStash::Util::Loggable
8
-
9
- attr_reader :import_path, :content
10
-
11
- # content is a list of kibana file resources
12
- def initialize(import_path, content)
13
- @import_path, @content = import_path, content
14
- end
15
-
16
- def import(client)
17
- # e.g. curl "http://localhost:5601/api/kibana/dashboards/import"
18
- # extract and prepare all objects
19
- objects = []
20
- content.each do |resource|
21
- hash = {
22
- "id" => resource.content_id,
23
- "type" => resource.content_type,
24
- "version" => 1,
25
- "attributes" => resource.content_as_object
26
- }
27
- objects << hash
28
- end
29
- body = {:version => client.version, :objects => objects}
30
- response = client.post(import_path, body)
31
- if response.failed?
32
- logger.error("Attempted POST failed", :url_path => import_path, :response => response.body)
33
- end
34
- response
35
- end
36
- end end end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
-
5
- module LogStash module Modules class KibanaImporter
6
- include LogStash::Util::Loggable
7
-
8
- def initialize(client)
9
- @client = client
10
- end
11
-
12
- def put(via_kibana)
13
- path = via_kibana.import_path
14
- logger.debug("Attempting POST", :url_path => path, :content => via_kibana.content)
15
- via_kibana.import(@client)
16
- end
17
- end end end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require_relative "resource_base"
4
-
5
- module LogStash module Modules class KibanaResource
6
- include ResourceBase
7
- def import_path
8
- base + "/" + content_type + "/" + content_id
9
- end
10
- end end end
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require_relative "kibana_base"
5
-
6
- module LogStash module Modules class KibanaSettings < KibanaBase
7
- include LogStash::Util::Loggable
8
-
9
- class Setting
10
- attr_reader :name, :value
11
- def initialize(name, value)
12
- @name, @value = name, value
13
- end
14
- end
15
-
16
- attr_reader :import_path, :content
17
-
18
- # content is an array of Setting required for this module
19
- def initialize(import_path, content)
20
- @import_path, @content = import_path, content
21
- end
22
-
23
- def import(client)
24
- # e.g. curl "http://localhost:5601/api/kibana/settings"
25
- # 6.0.0-alpha3 -> {"settings":{"buildNum":{"userValue":15613},"defaultIndex":{"userValue":"arcsight-*"}}}
26
- # 5.4 -> {"settings":{"defaultIndex":{"userValue":"cef-*"},"metrics:max_buckets":{"userValue":"600000"}}}
27
- # array of Setting objects
28
- # The POST api body { "changes": { "defaultIndex": "arcsight-*", "metrics:max_buckets": "400" } }
29
- settings = {}
30
- content.each do |setting|
31
- settings[setting.name] = "#{setting.value}"
32
- end
33
- body = {"changes" => settings}
34
- response = client.post(import_path, body)
35
- if response.failed?
36
- logger.error("Attempted POST failed", :url_path => import_path, :response => response.body)
37
- end
38
- response
39
- end
40
- end end end
@@ -1,120 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require_relative "file_reader"
4
- require "logstash/settings"
5
-
6
- module LogStash module Modules class LogStashConfig
7
- # We name it `modul` here because `module` has meaning in Ruby.
8
- def initialize(modul, settings)
9
- @directory = ::File.join(modul.directory, "logstash")
10
- @name = modul.module_name
11
- @settings = settings
12
- end
13
-
14
- def template
15
- ::File.join(@directory, "#{@name}.conf.erb")
16
- end
17
-
18
- def configured_inputs(default = [], aliases = {})
19
- name = "var.inputs"
20
- values = get_setting(LogStash::Setting::SplittableStringArray.new(name, String, default))
21
-
22
- aliases.each { |k,v| values << v if values.include?(k) }
23
- aliases.invert.each { |k,v| values << v if values.include?(k) }
24
- values.flatten.uniq
25
- end
26
-
27
- def alias_settings_keys!(aliases)
28
- aliased_settings = alias_matching_keys(aliases, @settings)
29
- @settings = alias_matching_keys(aliases.invert, aliased_settings)
30
- end
31
-
32
- def array_to_string(array)
33
- "[#{array.collect { |i| "'#{i}'" }.join(", ")}]"
34
- end
35
-
36
- def csv_string(array)
37
- "'#{array.join(',')}'"
38
- end
39
-
40
- def get_setting(setting_class)
41
- raw_value = @settings[setting_class.name]
42
- # If we dont check for NIL, the Settings class will try to coerce the value
43
- # and most of the it will fails when a NIL value is explicitely set.
44
- # This will be fixed once we wrap the plugins settings into a Settings class
45
- setting_class.set(raw_value) unless raw_value.nil?
46
- setting_class.value
47
- end
48
-
49
- def setting(name, default)
50
- # by default we use the more permissive setting which is a `NullableString`
51
- # This is fine because the end format of the logstash configuration is a string representation
52
- # of the pipeline. There is a good reason why I think we should use the settings classes, we
53
- # can `preprocess` a template and generate a configuration from the defined settings
54
- # validate the values and replace them in the template.
55
- case default
56
- when String
57
- get_setting(LogStash::Setting::NullableString.new(name, default.to_s))
58
- when Numeric
59
- get_setting(LogStash::Setting::Numeric.new(name, default))
60
- else
61
- get_setting(LogStash::Setting::NullableString.new(name, default.to_s))
62
- end
63
- end
64
-
65
- def elasticsearch_output_config(type_string = nil)
66
- hosts = array_to_string(get_setting(LogStash::Setting::SplittableStringArray.new("var.elasticsearch.hosts", String, ["localhost:9200"])))
67
- index = "#{@name}-#{setting("var.elasticsearch.index_suffix", "%{+YYYY.MM.dd}")}"
68
- user = @settings["var.elasticsearch.username"]
69
- password = @settings["var.elasticsearch.password"]
70
- lines = ["hosts => #{hosts}", "index => \"#{index}\""]
71
- lines.push(user ? "user => \"#{user}\"" : nil)
72
- lines.push(password ? "password => \"#{password}\"" : nil)
73
- lines.push(type_string ? "document_type => #{type_string}" : nil)
74
- lines.push("ssl => #{@settings.fetch('var.elasticsearch.ssl.enabled', false)}")
75
- if cacert = @settings["var.elasticsearch.ssl.certificate_authority"]
76
- lines.push("cacert => \"#{cacert}\"") if cacert
77
- end
78
- # NOTE: the first line should be indented in the conf.erb
79
- <<-CONF
80
- elasticsearch {
81
- #{lines.compact.join("\n ")}
82
- manage_template => false
83
- }
84
- CONF
85
- end
86
-
87
- def config_string
88
- # process the template and settings
89
- # send back as a string
90
- renderer = ERB.new(FileReader.read(template))
91
- renderer.result(binding)
92
- end
93
-
94
- private
95
- # For a first version we are copying the values of the original hash,
96
- # this might become problematic if we users changes the values of the
97
- # settings in the template, which could result in an inconsistent view of the original data
98
- #
99
- # For v1 of the feature I think its an OK compromise, v2 we have a more advanced hash that
100
- # support alias.
101
- def alias_matching_keys(aliases, target)
102
- aliased_target = target.dup
103
-
104
- aliases.each do |matching_key_prefix, new_key_prefix|
105
- target.each do |k, v|
106
- re = /^#{matching_key_prefix}\./
107
-
108
- if k =~ re
109
- alias_key = k.gsub(re, "#{new_key_prefix}.")
110
-
111
- # If the user setup the same values twices with different values lets just halt.
112
- raise "Cannot create an alias, the destination key has already a value set: original key: #{k}, alias key: #{alias_key}" if (!aliased_target[alias_key].nil? && aliased_target[alias_key] != v)
113
- aliased_target[alias_key] = v unless v.nil?
114
- end
115
- end
116
- end
117
-
118
- aliased_target
119
- end
120
- end end end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/json"
4
- require_relative "file_reader"
5
-
6
- module LogStash module Modules module ResourceBase
7
- attr_reader :base, :content_type, :content_path, :content_id
8
-
9
- def initialize(base, content_type, content_path, content = nil, content_id = nil)
10
- @base, @content_type, @content_path = base, content_type, content_path
11
- @content_id = content_id || ::File.basename(@content_path, ".*")
12
- # content at this time will be a JSON string
13
- @content = content
14
- if !@content.nil?
15
- @content_as_object = LogStash::Json.load(@content) rescue {}
16
- end
17
- end
18
-
19
- def content
20
- @content ||= FileReader.read(@content_path)
21
- end
22
-
23
- def to_s
24
- "#{base}, #{content_type}, #{content_path}, #{content_id}"
25
- end
26
-
27
- def content_as_object
28
- @content_as_object ||= FileReader.read_json(@content_path) rescue nil
29
- end
30
-
31
- def <=>(other)
32
- to_s <=> other.to_s
33
- end
34
-
35
- def ==(other)
36
- to_s == other.to_s
37
- end
38
- end end end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require "logstash/util/loggable"
5
- require "erb"
6
-
7
- require_relative "elasticsearch_config"
8
- require_relative "kibana_config"
9
- require_relative "logstash_config"
10
-
11
- module LogStash module Modules class Scaffold
12
- include LogStash::Util::Loggable
13
-
14
- attr_reader :directory, :module_name, :kibana_version_parts
15
- attr_reader :kibana_configuration, :logstash_configuration, :elasticsearch_configuration
16
-
17
- def initialize(name, directory)
18
- @module_name = name
19
- @directory = directory # this is the 'configuration folder in the GEM root.'
20
- @kibana_version_parts = "5.6.0".split('.') # this is backup in case kibana client fails to connect
21
- logger.info("Initializing module", :module_name => name, :directory => directory)
22
- end
23
-
24
- def add_kibana_version(version_parts)
25
- @kibana_version_parts = version_parts
26
- end
27
-
28
- def import(import_engine, kibana_import_engine)
29
- @elasticsearch_configuration.resources.each do |resource|
30
- import_engine.put(resource)
31
- end
32
- @kibana_configuration.resources.each do |resource|
33
- kibana_import_engine.put(resource)
34
- end
35
- end
36
-
37
- def with_settings(module_settings)
38
- @logstash_configuration = LogStashConfig.new(self, module_settings)
39
- @kibana_configuration = KibanaConfig.new(self, module_settings)
40
- @elasticsearch_configuration = ElasticsearchConfig.new(self, module_settings)
41
- self
42
- end
43
-
44
- def config_string()
45
- # settings should be set earlier by the caller.
46
- # settings should be the subset from the YAML file with a structure like
47
- # {"name" => "plugin name", "k1" => "v1", "k2" => "v2"}, etc.
48
- return nil if @logstash_configuration.nil?
49
- @logstash_configuration.config_string
50
- end
51
- end end end # class LogStash::Modules::Scaffold
52
-
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
-
4
- module LogStash module Modules class SettingsMerger
5
- def self.merge(cli_settings, yml_settings)
6
- # both args are arrays of hashes, e.g.
7
- # [{"name"=>"mod1", "var.input.tcp.port"=>"3333"}, {"name"=>"mod2"}]
8
- # [{"name"=>"mod1", "var.input.tcp.port"=>2222, "var.kibana.username"=>"rupert", "var.kibana.password"=>"fotherington"}, {"name"=>"mod3", "var.input.tcp.port"=>4445}]
9
- merged = []
10
- # union and group_by preserves order
11
- # union will also coalesce identical hashes
12
- union_of_settings = (cli_settings | yml_settings)
13
- grouped_by_name = union_of_settings.group_by{|e| e["name"]}
14
- grouped_by_name.each do |name, array|
15
- if array.size == 2
16
- merged << array.first.merge(array.last)
17
- else
18
- merged.concat(array)
19
- end
20
- end
21
- merged
22
- end
23
- end end end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- require_relative "scaffold"
3
-
4
- # This module function should be used when gems or
5
- # x-pack defines modules in their folder structures.
6
- module LogStash module Modules module Util
7
- def self.register_local_modules(path)
8
- modules_path = ::File.join(path, "modules")
9
- ::Dir.foreach(modules_path) do |item|
10
- # Ignore unix relative path ids
11
- next if item == '.' or item == '..'
12
- # Ignore non-directories
13
- next if !::File.directory?(::File.join(modules_path, ::File::Separator, item))
14
- LogStash::PLUGIN_REGISTRY.add(:modules, item, Scaffold.new(item, ::File.join(modules_path, item, "configuration")))
15
- end
16
- end
17
- end end end
@@ -1,61 +0,0 @@
1
- require 'logstash/environment'
2
-
3
- module LogStash; module Util
4
- class PluginDeadLetterQueueWriter
5
-
6
- attr_reader :plugin_id, :plugin_type, :inner_writer
7
-
8
- def initialize(inner_writer, plugin_id, plugin_type)
9
- @plugin_id = plugin_id
10
- @plugin_type = plugin_type
11
- @inner_writer = inner_writer
12
- end
13
-
14
- def write(logstash_event, reason)
15
- if @inner_writer && @inner_writer.is_open
16
- @inner_writer.writeEntry(logstash_event.to_java, @plugin_type, @plugin_id, reason)
17
- end
18
- end
19
-
20
- def close
21
- if @inner_writer && @inner_writer.is_open
22
- @inner_writer.close
23
- end
24
- end
25
- end
26
-
27
- class DummyDeadLetterQueueWriter
28
- # class uses to represent a writer when dead_letter_queue is disabled
29
- def initialize
30
- end
31
-
32
- def write(logstash_event, reason)
33
- # noop
34
- end
35
-
36
- def is_open
37
- false
38
- end
39
-
40
- def close
41
- # noop
42
- end
43
- end
44
-
45
- class DeadLetterQueueFactory
46
- java_import org.logstash.common.DeadLetterQueueFactory
47
-
48
- def self.get(pipeline_id)
49
- if LogStash::SETTINGS.get("dead_letter_queue.enable")
50
- return DeadLetterQueueWriter.new(
51
- DeadLetterQueueFactory.getWriter(pipeline_id, LogStash::SETTINGS.get("path.dead_letter_queue"), LogStash::SETTINGS.get('dead_letter_queue.max_bytes')))
52
- else
53
- return DeadLetterQueueWriter.new(nil)
54
- end
55
- end
56
-
57
- def self.close(pipeline_id)
58
- DeadLetterQueueFactory.close(pipeline_id)
59
- end
60
- end
61
- end end
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
- module ::LogStash::Util::EnvironmentVariables
3
-
4
- ENV_PLACEHOLDER_REGEX = /\${(?<name>[a-zA-Z_.][a-zA-Z0-9_.]*)(:(?<default>[^}]*))?}/
5
-
6
- # Recursive method to replace environment variable references in parameters
7
- def deep_replace(value)
8
- if value.is_a?(Hash)
9
- value.each do |valueHashKey, valueHashValue|
10
- value[valueHashKey.to_s] = deep_replace(valueHashValue)
11
- end
12
- else
13
- if value.is_a?(Array)
14
- value.each_index do | valueArrayIndex|
15
- value[valueArrayIndex] = deep_replace(value[valueArrayIndex])
16
- end
17
- else
18
- return replace_env_placeholders(value)
19
- end
20
- end
21
- end
22
-
23
- # Replace all environment variable references in 'value' param by environment variable value and return updated value
24
- # Process following patterns : $VAR, ${VAR}, ${VAR:defaultValue}
25
- def replace_env_placeholders(value)
26
- return value unless value.is_a?(String)
27
-
28
- value.gsub(ENV_PLACEHOLDER_REGEX) do |placeholder|
29
- # Note: Ruby docs claim[1] Regexp.last_match is thread-local and scoped to
30
- # the call, so this should be thread-safe.
31
- #
32
- # [1] http://ruby-doc.org/core-2.1.1/Regexp.html#method-c-last_match
33
- name = Regexp.last_match(:name)
34
- default = Regexp.last_match(:default)
35
-
36
- replacement = ENV.fetch(name, default)
37
- if replacement.nil?
38
- raise LogStash::ConfigurationError, "Cannot evaluate `#{placeholder}`. Environment variable `#{name}` is not set and there is no default value given."
39
- end
40
- replacement
41
- end
42
- end # def replace_env_placeholders
43
- end