logstash-core 5.0.2-java → 5.1.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +9 -0
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/logstash-core.rb +22 -0
  5. data/lib/logstash-core/version.rb +1 -1
  6. data/lib/logstash-core_jars.rb +20 -0
  7. data/lib/logstash/agent.rb +65 -14
  8. data/lib/logstash/api/commands/default_metadata.rb +2 -1
  9. data/lib/logstash/api/commands/stats.rb +3 -2
  10. data/lib/logstash/config/file.rb +0 -1
  11. data/lib/logstash/config/loader.rb +1 -0
  12. data/lib/logstash/config/mixin.rb +2 -6
  13. data/lib/logstash/environment.rb +25 -2
  14. data/lib/logstash/event_dispatcher.rb +40 -0
  15. data/lib/logstash/filter_delegator.rb +1 -1
  16. data/lib/logstash/filters/base.rb +10 -2
  17. data/lib/logstash/instrument/metric_store.rb +0 -1
  18. data/lib/logstash/instrument/metric_type/base.rb +0 -1
  19. data/lib/logstash/instrument/namespaced_null_metric.rb +54 -0
  20. data/lib/logstash/instrument/null_metric.rb +55 -46
  21. data/lib/logstash/instrument/periodic_poller/jvm.rb +26 -3
  22. data/lib/logstash/instrument/periodic_poller/load_average.rb +47 -0
  23. data/lib/logstash/instrument/snapshot.rb +0 -1
  24. data/lib/logstash/java_integration.rb +0 -1
  25. data/lib/logstash/logging/logger.rb +37 -4
  26. data/lib/logstash/outputs/base.rb +1 -1
  27. data/lib/logstash/patches.rb +1 -0
  28. data/lib/logstash/patches/exception_to_json.rb +5 -0
  29. data/lib/logstash/pipeline.rb +50 -17
  30. data/lib/logstash/plugin.rb +14 -48
  31. data/lib/logstash/plugins/hooks_registry.rb +57 -0
  32. data/lib/logstash/plugins/registry.rb +208 -45
  33. data/lib/logstash/runner.rb +10 -5
  34. data/lib/logstash/settings.rb +101 -9
  35. data/lib/logstash/universal_plugin.rb +13 -0
  36. data/lib/logstash/util/byte_value.rb +60 -0
  37. data/lib/logstash/util/loggable.rb +14 -2
  38. data/lib/logstash/util/safe_uri.rb +1 -0
  39. data/lib/logstash/util/time_value.rb +70 -0
  40. data/lib/logstash/util/wrapped_acked_queue.rb +347 -0
  41. data/lib/logstash/util/wrapped_synchronous_queue.rb +17 -33
  42. data/lib/logstash/version.rb +1 -1
  43. data/locales/en.yml +1 -1
  44. data/logstash-core.gemspec +13 -18
  45. data/spec/api/lib/api/node_stats_spec.rb +3 -1
  46. data/spec/api/lib/api/support/resource_dsl_methods.rb +14 -6
  47. data/spec/api/spec_helper.rb +1 -0
  48. data/spec/conditionals_spec.rb +3 -2
  49. data/spec/logstash/agent_spec.rb +142 -62
  50. data/spec/logstash/environment_spec.rb +38 -0
  51. data/spec/logstash/event_dispatcher_spec.rb +76 -0
  52. data/spec/logstash/filter_delegator_spec.rb +2 -1
  53. data/spec/logstash/instrument/namespaced_null_metric_spec.rb +33 -0
  54. data/spec/logstash/instrument/null_metric_spec.rb +9 -5
  55. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +40 -0
  56. data/spec/logstash/instrument/periodic_poller/load_average_spec.rb +91 -0
  57. data/spec/logstash/output_delegator_spec.rb +2 -1
  58. data/spec/logstash/patches_spec.rb +15 -4
  59. data/spec/logstash/pipeline_pq_file_spec.rb +131 -0
  60. data/spec/logstash/pipeline_spec.rb +21 -17
  61. data/spec/logstash/plugin_spec.rb +4 -16
  62. data/spec/logstash/plugins/hooks_registry_spec.rb +60 -0
  63. data/spec/logstash/plugins/registry_spec.rb +22 -14
  64. data/spec/logstash/settings/bytes_spec.rb +53 -0
  65. data/spec/logstash/settings/time_value_spec.rb +31 -0
  66. data/spec/logstash/settings/writable_directory_spec.rb +125 -0
  67. data/spec/logstash/settings_spec.rb +39 -0
  68. data/spec/logstash/util/byte_value_spec.rb +33 -0
  69. data/spec/logstash/util/time_value_spec.rb +59 -0
  70. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +2 -2
  71. data/spec/logstash/webserver_spec.rb +4 -7
  72. data/spec/support/helpers.rb +8 -0
  73. data/spec/support/mocks_classes.rb +61 -31
  74. metadata +73 -20
  75. data/lib/jars.rb +0 -7
  76. data/lib/logstash/config/registry.rb +0 -13
  77. data/lib/logstash/inputs/metrics.rb +0 -47
  78. data/spec/logstash/inputs/metrics_spec.rb +0 -51
  79. data/vendor/jars/com/fasterxml/jackson/core/jackson-core/2.7.4/jackson-core-2.7.4.jar +0 -0
  80. data/vendor/jars/com/fasterxml/jackson/core/jackson-databind/2.7.4/jackson-databind-2.7.4.jar +0 -0
  81. data/vendor/jars/org/apache/logging/log4j/log4j-1.2-api/2.6.2/log4j-1.2-api-2.6.2.jar +0 -0
  82. data/vendor/jars/org/apache/logging/log4j/log4j-api/2.6.2/log4j-api-2.6.2.jar +0 -0
  83. data/vendor/jars/org/apache/logging/log4j/log4j-core/2.6.2/log4j-core-2.6.2.jar +0 -0
  84. data/vendor/jars/org/logstash/logstash-core/5.0.2/logstash-core-5.0.2.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f86c1c793b45c1e8757388c7520d098f6f1bb7d
4
- data.tar.gz: b05ed9d9784cd5e56b67df54a2c5786cbcd86fed
3
+ metadata.gz: c1c528ad65660126cc95b61d32483ba720122505
4
+ data.tar.gz: ed0b7dbcd0d18786caa99f1eacc6b44cf6def997
5
5
  SHA512:
6
- metadata.gz: 1edcabdf1f7b5176c1de416af340ce427e04280af8c1655bff40ba6e5f32d07c9866ff9dbe98a212fc37d4a39657d9be22cad2a7dcde81150909ae6bba0158b5
7
- data.tar.gz: 088175a7b550c772cb56b982bc0d37de92e9ec01db6be34e784d525b35fd0a84b530f1d01f2f52b5b32e09cb72b628b9e1e55f8402a8d52245c490919f9678c8
6
+ metadata.gz: acd07b85def1d3754b60f147c5403a7cb624e0bee8a812dfffe7e6dc09ecb2b651d8a689f243a2efaec965b1a3b4a42eafe1f9d442dfa5626e9cc9ae3713ef90
7
+ data.tar.gz: 410e63863b1679c7c6be251b3a08f278cb990f77fc26e0fc2236e79a87eeb7a154553ded30876cf3983aa4d4b2c654592c9a889b4cffa8fb8978822f193a9716
data/gemspec_jars.rb ADDED
@@ -0,0 +1,9 @@
1
+ # This file is generated by Gradle as part of the build process. It extracts the build.gradle
2
+ # runtime dependencies to generate this gemspec dependencies file to be eval'ed by the gemspec
3
+ # for the jar-dependencies requirements.
4
+
5
+ gem.requirements << "jar org.apache.logging.log4j:log4j-1.2-api, 2.6.2"
6
+ gem.requirements << "jar org.apache.logging.log4j:log4j-api, 2.6.2"
7
+ gem.requirements << "jar org.apache.logging.log4j:log4j-core, 2.6.2"
8
+ gem.requirements << "jar com.fasterxml.jackson.core:jackson-core, 2.7.4"
9
+ gem.requirements << "jar com.fasterxml.jackson.core:jackson-databind, 2.7.4"
Binary file
@@ -1,3 +1,25 @@
1
1
  # encoding: utf-8
2
+
3
+ require "java"
4
+
2
5
  module LogStash
3
6
  end
7
+
8
+ require "logstash-core_jars"
9
+
10
+ # local dev setup
11
+ classes_dir = File.expand_path("../../../build/classes/main", __FILE__)
12
+ resources_dir = File.expand_path("../../../build/resources/main", __FILE__)
13
+
14
+ if File.directory?(classes_dir) && File.directory?(resources_dir)
15
+ # if in local dev setup, add target to classpath
16
+ $CLASSPATH << classes_dir unless $CLASSPATH.include?(classes_dir)
17
+ $CLASSPATH << resources_dir unless $CLASSPATH.include?(resources_dir)
18
+ else
19
+ # otherwise use included jar
20
+ begin
21
+ require "logstash-core/logstash-core.jar"
22
+ rescue Exception => e
23
+ raise("Error loading logstash-core/logstash-core.jar file, cause: #{e.message}")
24
+ end
25
+ end
@@ -5,4 +5,4 @@
5
5
  # Note to authors: this should not include dashes because 'gem' barfs if
6
6
  # you include a dash in the version string.
7
7
 
8
- LOGSTASH_CORE_VERSION = "5.0.2"
8
+ LOGSTASH_CORE_VERSION = "5.1.1.1"
@@ -0,0 +1,20 @@
1
+ # this is a generated file, to avoid over-writing it just delete this comment
2
+ begin
3
+ require 'jar_dependencies'
4
+ rescue LoadError
5
+ require 'org/apache/logging/log4j/log4j-core/2.6.2/log4j-core-2.6.2.jar'
6
+ require 'org/apache/logging/log4j/log4j-api/2.6.2/log4j-api-2.6.2.jar'
7
+ require 'com/fasterxml/jackson/core/jackson-core/2.7.4/jackson-core-2.7.4.jar'
8
+ require 'org/apache/logging/log4j/log4j-1.2-api/2.6.2/log4j-1.2-api-2.6.2.jar'
9
+ require 'com/fasterxml/jackson/core/jackson-annotations/2.7.0/jackson-annotations-2.7.0.jar'
10
+ require 'com/fasterxml/jackson/core/jackson-databind/2.7.4/jackson-databind-2.7.4.jar'
11
+ end
12
+
13
+ if defined? Jars
14
+ require_jar( 'org.apache.logging.log4j', 'log4j-core', '2.6.2' )
15
+ require_jar( 'org.apache.logging.log4j', 'log4j-api', '2.6.2' )
16
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-core', '2.7.4' )
17
+ require_jar( 'org.apache.logging.log4j', 'log4j-1.2-api', '2.6.2' )
18
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-annotations', '2.7.0' )
19
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-databind', '2.7.4' )
20
+ end
@@ -9,6 +9,7 @@ require "logstash/instrument/collector"
9
9
  require "logstash/instrument/metric"
10
10
  require "logstash/pipeline"
11
11
  require "logstash/webserver"
12
+ require "logstash/event_dispatcher"
12
13
  require "stud/trap"
13
14
  require "logstash/config/loader"
14
15
  require "uri"
@@ -21,12 +22,12 @@ class LogStash::Agent
21
22
  include LogStash::Util::Loggable
22
23
  STARTED_AT = Time.now.freeze
23
24
 
24
- attr_reader :metric, :node_name, :pipelines, :settings, :webserver
25
+ attr_reader :metric, :name, :pipelines, :settings, :webserver, :dispatcher
25
26
  attr_accessor :logger
26
27
 
27
28
  # initialize method for LogStash::Agent
28
29
  # @param params [Hash] potential parameters are:
29
- # :node_name [String] - identifier for the agent
30
+ # :name [String] - identifier for the agent
30
31
  # :auto_reload [Boolean] - enable reloading of pipelines
31
32
  # :reload_interval [Integer] - reload pipelines every X seconds
32
33
  def initialize(settings = LogStash::SETTINGS)
@@ -35,10 +36,12 @@ class LogStash::Agent
35
36
  @auto_reload = setting("config.reload.automatic")
36
37
 
37
38
  @pipelines = {}
38
- @node_name = setting("node.name")
39
+ @name = setting("node.name")
39
40
  @http_host = setting("http.host")
40
41
  @http_port = setting("http.port")
41
42
  @http_environment = setting("http.environment")
43
+ # Generate / load the persistent uuid
44
+ id
42
45
 
43
46
  @config_loader = LogStash::Config::Loader.new(@logger)
44
47
  @reload_interval = setting("config.reload.interval")
@@ -50,6 +53,10 @@ class LogStash::Agent
50
53
  configure_metrics_collectors
51
54
 
52
55
  @reload_metric = metric.namespace([:stats, :pipelines])
56
+
57
+ @dispatcher = LogStash::EventDispatcher.new(self)
58
+ LogStash::PLUGIN_REGISTRY.hooks.register_emitter(self.class, dispatcher)
59
+ dispatcher.fire(:after_initialize)
53
60
  end
54
61
 
55
62
  def execute
@@ -97,7 +104,8 @@ class LogStash::Agent
97
104
 
98
105
  def reload_state!
99
106
  @upgrade_mutex.synchronize do
100
- @pipelines.each do |pipeline_id, _|
107
+ @pipelines.each do |pipeline_id, pipeline|
108
+ next if pipeline.settings.get("config.reload.automatic") == false
101
109
  begin
102
110
  reload_pipeline!(pipeline_id)
103
111
  rescue => e
@@ -130,8 +138,42 @@ class LogStash::Agent
130
138
  shutdown_pipelines
131
139
  end
132
140
 
133
- def node_uuid
134
- @node_uuid ||= SecureRandom.uuid
141
+ def id
142
+ return @id if @id
143
+
144
+ uuid = nil
145
+ if ::File.exists?(id_path)
146
+ begin
147
+ uuid = ::File.open(id_path) {|f| f.each_line.first.chomp }
148
+ rescue => e
149
+ logger.warn("Could not open persistent UUID file!",
150
+ :path => id_path,
151
+ :error => e.message,
152
+ :class => e.class.name)
153
+ end
154
+ end
155
+
156
+ if !uuid
157
+ uuid = SecureRandom.uuid
158
+ logger.info("No persistent UUID file found. Generating new UUID",
159
+ :uuid => uuid,
160
+ :path => id_path)
161
+ begin
162
+ ::File.open(id_path, 'w') {|f| f.write(uuid) }
163
+ rescue => e
164
+ logger.warn("Could not write persistent UUID file! Will use ephemeral UUID",
165
+ :uuid => uuid,
166
+ :path => id_path,
167
+ :error => e.message,
168
+ :class => e.class.name)
169
+ end
170
+ end
171
+
172
+ @id = uuid
173
+ end
174
+
175
+ def id_path
176
+ @id_path ||= ::File.join(settings.get("path.data"), "uuid")
135
177
  end
136
178
 
137
179
  def running_pipelines?
@@ -161,7 +203,7 @@ class LogStash::Agent
161
203
  @logger.debug("Agent: Configuring metric collection")
162
204
  LogStash::Instrument::Metric.new(@collector)
163
205
  else
164
- LogStash::Instrument::NullMetric.new
206
+ LogStash::Instrument::NullMetric.new(@collector)
165
207
  end
166
208
 
167
209
 
@@ -244,12 +286,12 @@ class LogStash::Agent
244
286
  return unless pipeline.is_a?(LogStash::Pipeline)
245
287
  return if pipeline.ready?
246
288
  @logger.debug("starting pipeline", :id => id)
247
- Thread.new do
289
+ t = Thread.new do
248
290
  LogStash::Util.set_thread_name("pipeline.#{id}")
249
291
  begin
250
292
  pipeline.run
251
293
  rescue => e
252
- @reload_metric.namespace([id.to_sym, :reloads]) do |n|
294
+ @reload_metric.namespace([id.to_sym, :reloads]).tap do |n|
253
295
  n.increment(:failures)
254
296
  n.gauge(:last_error, { :message => e.message, :backtrace => e.backtrace})
255
297
  n.gauge(:last_failure_timestamp, LogStash::Timestamp.now)
@@ -257,7 +299,15 @@ class LogStash::Agent
257
299
  @logger.error("Pipeline aborted due to error", :exception => e, :backtrace => e.backtrace)
258
300
  end
259
301
  end
260
- sleep 0.01 until pipeline.ready?
302
+ while true do
303
+ if !t.alive?
304
+ return false
305
+ elsif pipeline.ready?
306
+ return true
307
+ else
308
+ sleep 0.01
309
+ end
310
+ end
261
311
  end
262
312
 
263
313
  def stop_pipeline(id)
@@ -289,10 +339,11 @@ class LogStash::Agent
289
339
  stop_pipeline(pipeline_id)
290
340
  reset_pipeline_metrics(pipeline_id)
291
341
  @pipelines[pipeline_id] = new_pipeline
292
- start_pipeline(pipeline_id)
293
- @reload_metric.namespace([pipeline_id.to_sym, :reloads]).tap do |n|
294
- n.increment(:successes)
295
- n.gauge(:last_success_timestamp, LogStash::Timestamp.now)
342
+ if start_pipeline(pipeline_id) # pipeline started successfuly
343
+ @reload_metric.namespace([pipeline_id.to_sym, :reloads]).tap do |n|
344
+ n.increment(:successes)
345
+ n.gauge(:last_success_timestamp, LogStash::Timestamp.now)
346
+ end
296
347
  end
297
348
  end
298
349
 
@@ -7,7 +7,8 @@ module LogStash
7
7
  module Commands
8
8
  class DefaultMetadata < Commands::Base
9
9
  def all
10
- {:host => host, :version => version, :http_address => http_address}
10
+ {:host => host, :version => version, :http_address => http_address,
11
+ :id => service.agent.id, :name => service.agent.name}
11
12
  end
12
13
 
13
14
  def host
@@ -15,7 +15,8 @@ module LogStash
15
15
  :peak_count
16
16
  ),
17
17
  :mem => memory,
18
- :gc => gc
18
+ :gc => gc,
19
+ :uptime_in_millis => service.get_shallow(:jvm, :uptime_in_millis)
19
20
  }
20
21
  end
21
22
 
@@ -26,7 +27,7 @@ module LogStash
26
27
  :peak_open_file_descriptors,
27
28
  :max_file_descriptors,
28
29
  [:mem, [:total_virtual_in_bytes]],
29
- [:cpu, [:total_in_millis, :percent]]
30
+ [:cpu, [:total_in_millis, :percent, :load_average]]
30
31
  )
31
32
  end
32
33
 
@@ -2,7 +2,6 @@
2
2
  require "logstash/namespace"
3
3
  require "logstash/config/grammar"
4
4
  require "logstash/config/config_ast"
5
- require "logstash/config/registry"
6
5
  require "logstash/errors"
7
6
  require "logger"
8
7
 
@@ -66,6 +66,7 @@ module LogStash; module Config; class Loader
66
66
  config = ""
67
67
  if Dir.glob(path).length == 0
68
68
  @logger.info("No config files found in path", :path => path)
69
+ return config
69
70
  end
70
71
 
71
72
  encoding_issue_files = []
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/namespace"
3
- require "logstash/config/registry"
4
3
  require "logstash/plugins/registry"
5
4
  require "logstash/logging"
6
5
  require "logstash/util/password"
@@ -73,6 +72,7 @@ module LogStash::Config::Mixin
73
72
  "in the future. #{extra} If you have any questions " +
74
73
  "about this, please visit the #logstash channel " +
75
74
  "on freenode irc.", :name => name, :plugin => self)
75
+
76
76
  end
77
77
  if opts && opts[:obsolete]
78
78
  extra = opts[:obsolete].is_a?(String) ? opts[:obsolete] : ""
@@ -181,11 +181,7 @@ module LogStash::Config::Mixin
181
181
  # If no name given (nil), return the current name.
182
182
  def config_name(name = nil)
183
183
  @config_name = name if !name.nil?
184
- LogStash::Config::Registry.registry[@config_name] = self
185
- if self.respond_to?("plugin_type")
186
- declare_plugin(self.plugin_type, @config_name)
187
- end
188
- return @config_name
184
+ @config_name
189
185
  end
190
186
  alias_method :config_plugin, :config_name
191
187
 
@@ -23,7 +23,7 @@ module LogStash
23
23
  Setting::Boolean.new("config.test_and_exit", false),
24
24
  Setting::Boolean.new("config.reload.automatic", false),
25
25
  Setting::Numeric.new("config.reload.interval", 3), # in seconds
26
- Setting::Boolean.new("metric.collect", true) {|v| v == true }, # metric collection cannot be disabled
26
+ Setting::Boolean.new("metric.collect", true),
27
27
  Setting::String.new("pipeline.id", "main"),
28
28
  Setting::PositiveInteger.new("pipeline.workers", LogStash::Config::CpuCoreStrategy.maximum),
29
29
  Setting::PositiveInteger.new("pipeline.output.workers", 1),
@@ -40,14 +40,33 @@ module LogStash
40
40
  Setting::String.new("http.host", "127.0.0.1"),
41
41
  Setting::PortRange.new("http.port", 9600..9700),
42
42
  Setting::String.new("http.environment", "production"),
43
+ Setting::String.new("queue.type", "memory", true, ["persisted", "memory", "memory_acked"]),
44
+ Setting::Bytes.new("queue.page_capacity", "250mb"),
45
+ Setting::Bytes.new("queue.max_bytes", "1024mb"),
46
+ Setting::Numeric.new("queue.max_events", 0), # 0 is unlimited
47
+ Setting::Numeric.new("queue.checkpoint.acks", 1024), # 0 is unlimited
48
+ Setting::Numeric.new("queue.checkpoint.writes", 1024), # 0 is unlimited
49
+ Setting::Numeric.new("queue.checkpoint.interval", 1000), # 0 is no time-based checkpointing
50
+ Setting::TimeValue.new("slowlog.threshold.warn", "-1"),
51
+ Setting::TimeValue.new("slowlog.threshold.info", "-1"),
52
+ Setting::TimeValue.new("slowlog.threshold.debug", "-1"),
53
+ Setting::TimeValue.new("slowlog.threshold.trace", "-1")
43
54
  ].each {|setting| SETTINGS.register(setting) }
44
55
 
56
+ # Compute the default queue path based on `path.data`
57
+ default_queue_file_path = ::File.join(SETTINGS.get("path.data"), "queue")
58
+ SETTINGS.register Setting::WritableDirectory.new("path.queue", default_queue_file_path)
59
+
45
60
  module Environment
46
61
  extend self
47
62
 
48
63
  LOGSTASH_CORE = ::File.expand_path(::File.join(::File.dirname(__FILE__), "..", ".."))
49
64
  LOGSTASH_ENV = (ENV["LS_ENV"] || 'production').to_s.freeze
50
65
 
66
+ LINUX_OS_RE = /linux/
67
+ WINDOW_OS_RE = /mswin|msys|mingw|cygwin|bccwin|wince|emc/
68
+ MACOS_OS_RE = /darwin/
69
+
51
70
  def env
52
71
  LOGSTASH_ENV
53
72
  end
@@ -110,7 +129,11 @@ module LogStash
110
129
  end
111
130
 
112
131
  def windows?
113
- ::Gem.win_platform?
132
+ RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE
133
+ end
134
+
135
+ def linux?
136
+ RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE
114
137
  end
115
138
 
116
139
  def locales_path(path)
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ class EventDispatcher
4
+ java_import "java.util.concurrent.CopyOnWriteArrayList"
5
+
6
+ attr_reader :emitter
7
+
8
+ def initialize(emitter)
9
+ @emitter = emitter
10
+ @listeners = CopyOnWriteArrayList.new
11
+ end
12
+
13
+ # This operation is slow because we use a CopyOnWriteArrayList
14
+ # But the majority of the addition will be done at bootstrap time
15
+ # So add_listener shouldn't be called often at runtime.
16
+ #
17
+ # On the other hand the notification could be called really often.
18
+ def add_listener(listener)
19
+ @listeners.add(listener)
20
+ end
21
+
22
+ # This operation is slow because we use a `CopyOnWriteArrayList` as the backend, instead of a
23
+ # ConcurrentHashMap, but since we are mostly adding stuff and iterating the `CopyOnWriteArrayList`
24
+ # should provide a better performance.
25
+ #
26
+ # See note on add_listener, this method shouldn't be called really often.
27
+ def remove_listener(listener)
28
+ @listeners.remove(listener)
29
+ end
30
+
31
+ def fire(method_name, *arguments)
32
+ @listeners.each do |listener|
33
+ if listener.respond_to?(method_name)
34
+ listener.send(method_name, emitter, *arguments)
35
+ end
36
+ end
37
+ end
38
+ alias_method :execute, :fire
39
+ end
40
+ end
@@ -20,7 +20,7 @@ module LogStash
20
20
  @filter = klass.new(plugin_args)
21
21
 
22
22
  # Scope the metrics to the plugin
23
- namespaced_metric = metric.namespace("#{@klass.config_name}_#{@id}".to_sym)
23
+ namespaced_metric = metric.namespace(@id.to_sym)
24
24
  @filter.metric = namespaced_metric
25
25
 
26
26
  @metric_events = namespaced_metric.namespace(:events)
@@ -139,6 +139,14 @@ class LogStash::Filters::Base < LogStash::Plugin
139
139
  raise "#{self.class}#filter must be overidden"
140
140
  end # def filter
141
141
 
142
+ public
143
+ def do_filter(event, &block)
144
+ time = java.lang.System.nanoTime
145
+ filter(event, &block)
146
+ @slow_logger.on_event("event processing time", @original_params, event, java.lang.System.nanoTime - time)
147
+ end
148
+
149
+
142
150
  # in 1.5.0 multi_filter is meant to be used in the generated filter function in LogStash::Config::AST::Plugin only
143
151
  # and is temporary until we refactor the filter method interface to accept events list and return events list,
144
152
  # just list in multi_filter see https://github.com/elastic/logstash/issues/2872.
@@ -153,7 +161,7 @@ class LogStash::Filters::Base < LogStash::Plugin
153
161
  events.each do |event|
154
162
  unless event.cancelled?
155
163
  result << event
156
- filter(event){|new_event| result << new_event}
164
+ do_filter(event){|new_event| result << new_event}
157
165
  end
158
166
  end
159
167
  result
@@ -161,7 +169,7 @@ class LogStash::Filters::Base < LogStash::Plugin
161
169
 
162
170
  public
163
171
  def execute(event, &block)
164
- filter(event, &block)
172
+ do_filter(event, &block)
165
173
  end # def execute
166
174
 
167
175
  public