logstash-core 2.4.1-java → 5.0.0.alpha1-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of logstash-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/logstash-core/version.rb +1 -1
- data/lib/logstash/agent.rb +124 -411
- data/lib/logstash/api/init.ru +31 -0
- data/lib/logstash/api/lib/app.rb +40 -0
- data/lib/logstash/api/lib/app/command.rb +29 -0
- data/lib/logstash/api/lib/app/command_factory.rb +29 -0
- data/lib/logstash/api/lib/app/commands/stats/events_command.rb +13 -0
- data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +120 -0
- data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +25 -0
- data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +15 -0
- data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +28 -0
- data/lib/logstash/api/lib/app/modules/node.rb +25 -0
- data/lib/logstash/api/lib/app/modules/node_stats.rb +51 -0
- data/lib/logstash/api/lib/app/modules/plugins.rb +15 -0
- data/lib/logstash/api/lib/app/modules/stats.rb +21 -0
- data/lib/logstash/api/lib/app/root.rb +13 -0
- data/lib/logstash/api/lib/app/service.rb +61 -0
- data/lib/logstash/api/lib/app/stats.rb +56 -0
- data/lib/logstash/api/lib/helpers/app_helpers.rb +23 -0
- data/lib/logstash/codecs/base.rb +1 -29
- data/lib/logstash/config/config_ast.rb +18 -31
- data/lib/logstash/config/loader.rb +3 -5
- data/lib/logstash/config/mixin.rb +25 -64
- data/lib/logstash/filter_delegator.rb +65 -0
- data/lib/logstash/inputs/base.rb +1 -1
- data/lib/logstash/inputs/metrics.rb +47 -0
- data/lib/logstash/instrument/collector.rb +109 -0
- data/lib/logstash/instrument/metric.rb +102 -0
- data/lib/logstash/instrument/metric_store.rb +228 -0
- data/lib/logstash/instrument/metric_type.rb +24 -0
- data/lib/logstash/instrument/metric_type/base.rb +35 -0
- data/lib/logstash/instrument/metric_type/counter.rb +29 -0
- data/lib/logstash/instrument/metric_type/gauge.rb +22 -0
- data/lib/logstash/instrument/metric_type/mean.rb +33 -0
- data/lib/logstash/instrument/namespaced_metric.rb +54 -0
- data/lib/logstash/instrument/null_metric.rb +4 -3
- data/lib/logstash/instrument/periodic_poller/base.rb +57 -0
- data/lib/logstash/instrument/periodic_poller/jvm.rb +92 -0
- data/lib/logstash/instrument/periodic_poller/os.rb +13 -0
- data/lib/logstash/instrument/periodic_poller/periodic_poller_observer.rb +19 -0
- data/lib/logstash/instrument/periodic_pollers.rb +26 -0
- data/lib/logstash/instrument/snapshot.rb +16 -0
- data/lib/logstash/json.rb +2 -3
- data/lib/logstash/namespace.rb +1 -0
- data/lib/logstash/output_delegator.rb +16 -3
- data/lib/logstash/outputs/base.rb +1 -32
- data/lib/logstash/pipeline.rb +67 -8
- data/lib/logstash/plugin.rb +57 -19
- data/lib/logstash/runner.rb +348 -84
- data/lib/logstash/util.rb +9 -0
- data/lib/logstash/util/duration_formatter.rb +15 -0
- data/lib/logstash/util/java_version.rb +2 -4
- data/lib/logstash/util/loggable.rb +29 -0
- data/lib/logstash/version.rb +1 -1
- data/lib/logstash/webserver.rb +98 -0
- data/locales/en.yml +42 -24
- data/logstash-core.gemspec +9 -6
- data/spec/api/lib/api/node_spec.rb +64 -0
- data/spec/api/lib/api/node_stats_spec.rb +68 -0
- data/spec/api/lib/api/plugins_spec.rb +57 -0
- data/spec/api/lib/api/root_spec.rb +20 -0
- data/spec/api/lib/api/stats_spec.rb +19 -0
- data/spec/api/lib/commands/events_spec.rb +17 -0
- data/spec/api/lib/commands/jvm_spec.rb +45 -0
- data/spec/api/spec_helper.rb +128 -0
- data/spec/logstash/agent_spec.rb +62 -169
- data/spec/logstash/config/config_ast_spec.rb +2 -47
- data/spec/logstash/config/mixin_spec.rb +0 -157
- data/spec/logstash/filter_delegator_spec.rb +143 -0
- data/spec/logstash/inputs/metrics_spec.rb +52 -0
- data/spec/logstash/instrument/collector_spec.rb +49 -0
- data/spec/logstash/instrument/metric_spec.rb +110 -0
- data/spec/logstash/instrument/metric_store_spec.rb +163 -0
- data/spec/logstash/instrument/metric_type/counter_spec.rb +40 -0
- data/spec/logstash/instrument/metric_type/gauge_spec.rb +40 -0
- data/spec/logstash/instrument/namespaced_metric_spec.rb +25 -0
- data/spec/logstash/instrument/null_metric_spec.rb +9 -51
- data/spec/logstash/json_spec.rb +14 -0
- data/spec/logstash/output_delegator_spec.rb +6 -3
- data/spec/logstash/outputs/base_spec.rb +0 -107
- data/spec/logstash/pipeline_spec.rb +204 -33
- data/spec/logstash/plugin_spec.rb +80 -15
- data/spec/logstash/runner_spec.rb +134 -38
- data/spec/logstash/shutdown_watcher_spec.rb +0 -1
- data/spec/logstash/util/duration_formatter_spec.rb +11 -0
- data/spec/logstash/util/java_version_spec.rb +10 -2
- data/spec/logstash/util_spec.rb +28 -0
- data/spec/support/matchers.rb +30 -0
- metadata +154 -20
- data/lib/logstash/logging/json.rb +0 -21
- data/lib/logstash/special_agent.rb +0 -8
- data/lib/logstash/util/safe_uri.rb +0 -50
- data/spec/logstash/codecs/base_spec.rb +0 -74
- data/spec/static/i18n_spec.rb +0 -25
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/util/loggable"
|
3
|
+
require "logstash/event"
|
4
|
+
|
5
|
+
module LogStash module Instrument
|
6
|
+
class Snapshot
|
7
|
+
include LogStash::Util::Loggable
|
8
|
+
|
9
|
+
attr_reader :metric_store, :created_at
|
10
|
+
|
11
|
+
def initialize(metric_store, created_at = Time.now)
|
12
|
+
@metric_store = metric_store
|
13
|
+
@created_at = created_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end; end
|
data/lib/logstash/json.rb
CHANGED
@@ -41,13 +41,12 @@ module LogStash
|
|
41
41
|
raise LogStash::Json::ParserError.new(e.message)
|
42
42
|
end
|
43
43
|
|
44
|
-
def jruby_dump(o)
|
44
|
+
def jruby_dump(o, options={})
|
45
45
|
# TODO [guyboertje] remove these comments in 5.0
|
46
46
|
# test for enumerable here to work around an omission in JrJackson::Json.dump to
|
47
47
|
# also look for Java::JavaUtil::ArrayList, see TODO submit issue
|
48
48
|
# o.is_a?(Enumerable) ? JrJackson::Raw.generate(o) : JrJackson::Json.dump(o)
|
49
|
-
|
50
|
-
JrJackson::Base.generate(o, {})
|
49
|
+
JrJackson::Base.generate(o, options)
|
51
50
|
|
52
51
|
rescue => e
|
53
52
|
raise LogStash::Json::GeneratorError.new(e.message)
|
data/lib/logstash/namespace.rb
CHANGED
@@ -13,7 +13,7 @@ module LogStash class OutputDelegator
|
|
13
13
|
|
14
14
|
# The *args this takes are the same format that a Outputs::Base takes. A list of hashes with parameters in them
|
15
15
|
# Internally these just get merged together into a single hash
|
16
|
-
def initialize(logger, klass, default_worker_count, *plugin_args)
|
16
|
+
def initialize(logger, klass, default_worker_count, metric, *plugin_args)
|
17
17
|
@logger = logger
|
18
18
|
@threadsafe = klass.threadsafe?
|
19
19
|
@config = plugin_args.reduce({}, :merge)
|
@@ -21,6 +21,14 @@ module LogStash class OutputDelegator
|
|
21
21
|
@workers = java.util.concurrent.CopyOnWriteArrayList.new
|
22
22
|
@default_worker_count = default_worker_count
|
23
23
|
@registered = false
|
24
|
+
|
25
|
+
# Create an instance of the input so we can fetch the identifier
|
26
|
+
output = @klass.new(@config)
|
27
|
+
|
28
|
+
# Scope the metrics to the plugin
|
29
|
+
namespaced_metric = metric.namespace(output.plugin_unique_name.to_sym)
|
30
|
+
@metric_events = namespaced_metric.namespace(:events)
|
31
|
+
|
24
32
|
@events_received = Concurrent::AtomicFixnum.new(0)
|
25
33
|
end
|
26
34
|
|
@@ -74,7 +82,7 @@ module LogStash class OutputDelegator
|
|
74
82
|
@workers << @klass.new(@config)
|
75
83
|
@workers.first.register # Needed in case register calls `workers_not_supported`
|
76
84
|
|
77
|
-
@logger.debug("Will start workers for output", :worker_count => target_worker_count, :class => @klass
|
85
|
+
@logger.debug("Will start workers for output", :worker_count => target_worker_count, :class => @klass)
|
78
86
|
|
79
87
|
# Threadsafe versions don't need additional workers
|
80
88
|
setup_additional_workers!(target_worker_count) unless @threadsafe
|
@@ -88,6 +96,7 @@ module LogStash class OutputDelegator
|
|
88
96
|
|
89
97
|
(target_worker_count - 1).times do
|
90
98
|
inst = @klass.new(@config)
|
99
|
+
inst.metric = @metric
|
91
100
|
@workers << inst
|
92
101
|
end
|
93
102
|
|
@@ -118,23 +127,27 @@ module LogStash class OutputDelegator
|
|
118
127
|
|
119
128
|
def threadsafe_multi_receive(events)
|
120
129
|
@events_received.increment(events.length)
|
130
|
+
@metric_events.increment(:in, events.length)
|
121
131
|
|
122
132
|
@threadsafe_worker.multi_receive(events)
|
133
|
+
@metric_events.increment(:out, events.length)
|
123
134
|
end
|
124
135
|
|
125
136
|
def worker_multi_receive(events)
|
126
137
|
@events_received.increment(events.length)
|
138
|
+
@metric_events.increment(:in, events.length)
|
127
139
|
|
128
140
|
worker = @worker_queue.pop
|
129
141
|
begin
|
130
142
|
worker.multi_receive(events)
|
143
|
+
@metric_events.increment(:out, events.length)
|
131
144
|
ensure
|
132
145
|
@worker_queue.push(worker)
|
133
146
|
end
|
134
147
|
end
|
135
148
|
|
136
149
|
def do_close
|
137
|
-
@logger.debug("closing output delegator", :klass => @klass
|
150
|
+
@logger.debug("closing output delegator", :klass => @klass)
|
138
151
|
|
139
152
|
if @threadsafe
|
140
153
|
@workers.each(&:do_close)
|
@@ -27,22 +27,6 @@ class LogStash::Outputs::Base < LogStash::Plugin
|
|
27
27
|
|
28
28
|
attr_reader :worker_plugins, :available_workers, :workers, :worker_plugins, :workers_not_supported
|
29
29
|
|
30
|
-
# Set or return concurrency type
|
31
|
-
def self.concurrency(type=nil)
|
32
|
-
if type
|
33
|
-
@concurrency = type
|
34
|
-
|
35
|
-
if type == :shared
|
36
|
-
declare_threadsafe!
|
37
|
-
elsif type == :single
|
38
|
-
declare_workers_not_supported!("This plugin only supports one worker!")
|
39
|
-
end
|
40
|
-
|
41
|
-
else
|
42
|
-
@concurrency || :legacy # default is :legacyo
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
30
|
def self.declare_threadsafe!
|
47
31
|
declare_workers_not_supported!
|
48
32
|
@threadsafe = true
|
@@ -81,8 +65,6 @@ class LogStash::Outputs::Base < LogStash::Plugin
|
|
81
65
|
# If we're running with a single thread we must enforce single-threaded concurrency by default
|
82
66
|
# Maybe in a future version we'll assume output plugins are threadsafe
|
83
67
|
@single_worker_mutex = Mutex.new
|
84
|
-
|
85
|
-
@receives_encoded = self.methods.include?(:multi_receive_encoded)
|
86
68
|
end
|
87
69
|
|
88
70
|
public
|
@@ -95,23 +77,10 @@ class LogStash::Outputs::Base < LogStash::Plugin
|
|
95
77
|
raise "#{self.class}#receive must be overidden"
|
96
78
|
end # def receive
|
97
79
|
|
98
|
-
public
|
99
|
-
def concurrency
|
100
|
-
self.class.concurrency
|
101
|
-
end
|
102
|
-
|
103
80
|
public
|
104
81
|
# To be overriden in implementations
|
105
82
|
def multi_receive(events)
|
106
|
-
|
107
|
-
self.multi_receive_encoded(codec.multi_encode(events))
|
108
|
-
else
|
109
|
-
events.each {|event| receive(event) }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def codec
|
114
|
-
params["codec"]
|
83
|
+
events.each {|event| receive(event) }
|
115
84
|
end
|
116
85
|
|
117
86
|
private
|
data/lib/logstash/pipeline.rb
CHANGED
@@ -14,10 +14,28 @@ require "logstash/util/defaults_printer"
|
|
14
14
|
require "logstash/shutdown_watcher"
|
15
15
|
require "logstash/util/wrapped_synchronous_queue"
|
16
16
|
require "logstash/pipeline_reporter"
|
17
|
+
require "logstash/instrument/metric"
|
18
|
+
require "logstash/instrument/namespaced_metric"
|
19
|
+
require "logstash/instrument/null_metric"
|
20
|
+
require "logstash/instrument/collector"
|
17
21
|
require "logstash/output_delegator"
|
22
|
+
require "logstash/filter_delegator"
|
18
23
|
|
19
24
|
module LogStash; class Pipeline
|
20
|
-
|
25
|
+
attr_reader :inputs,
|
26
|
+
:filters,
|
27
|
+
:outputs,
|
28
|
+
:worker_threads,
|
29
|
+
:events_consumed,
|
30
|
+
:events_filtered,
|
31
|
+
:reporter,
|
32
|
+
:pipeline_id,
|
33
|
+
:metric,
|
34
|
+
:logger,
|
35
|
+
:started_at,
|
36
|
+
:thread,
|
37
|
+
:config_str,
|
38
|
+
:original_settings
|
21
39
|
|
22
40
|
DEFAULT_OUTPUT_WORKERS = 1
|
23
41
|
|
@@ -52,6 +70,16 @@ module LogStash; class Pipeline
|
|
52
70
|
|
53
71
|
@worker_threads = []
|
54
72
|
|
73
|
+
# Metric object should be passed upstream, multiple pipeline share the same metric
|
74
|
+
# and collector only the namespace will changes.
|
75
|
+
# If no metric is given, we use a `NullMetric` for all internal calls.
|
76
|
+
# We also do this to make the changes backward compatible with previous testing of the
|
77
|
+
# pipeline.
|
78
|
+
#
|
79
|
+
# This need to be configured before we evaluate the code to make
|
80
|
+
# sure the metric instance is correctly send to the plugin.
|
81
|
+
@metric = settings.fetch(:metric, Instrument::NullMetric.new)
|
82
|
+
|
55
83
|
grammar = LogStashConfigParser.new
|
56
84
|
@config = grammar.parse(config_str)
|
57
85
|
if @config.nil?
|
@@ -61,11 +89,15 @@ module LogStash; class Pipeline
|
|
61
89
|
# The code will initialize all the plugins and define the
|
62
90
|
# filter and output methods.
|
63
91
|
code = @config.compile
|
92
|
+
@code = code
|
93
|
+
|
64
94
|
# The config code is hard to represent as a log message...
|
65
95
|
# So just print it.
|
66
|
-
|
67
|
-
|
96
|
+
|
97
|
+
if @settings[:debug_config] && logger.debug?
|
98
|
+
logger.debug("Compiled pipeline code", :code => code)
|
68
99
|
end
|
100
|
+
|
69
101
|
begin
|
70
102
|
eval(code)
|
71
103
|
rescue => e
|
@@ -101,7 +133,7 @@ module LogStash; class Pipeline
|
|
101
133
|
safe_filters, unsafe_filters = @filters.partition(&:threadsafe?)
|
102
134
|
|
103
135
|
if unsafe_filters.any?
|
104
|
-
plugins = unsafe_filters.collect { |f| f.
|
136
|
+
plugins = unsafe_filters.collect { |f| f.config_name }
|
105
137
|
case thread_count
|
106
138
|
when nil
|
107
139
|
# user did not specify a worker thread count
|
@@ -130,6 +162,9 @@ module LogStash; class Pipeline
|
|
130
162
|
end
|
131
163
|
|
132
164
|
def run
|
165
|
+
@started_at = Time.now
|
166
|
+
|
167
|
+
LogStash::Util.set_thread_name("[#{pipeline_id}]-pipeline-manager")
|
133
168
|
@logger.terminal(LogStash::Util::DefaultsPrinter.print(@settings))
|
134
169
|
@thread = Thread.current
|
135
170
|
|
@@ -179,7 +214,7 @@ module LogStash; class Pipeline
|
|
179
214
|
begin
|
180
215
|
start_inputs
|
181
216
|
@outputs.each {|o| o.register }
|
182
|
-
@filters.each {|f| f.register}
|
217
|
+
@filters.each {|f| f.register }
|
183
218
|
|
184
219
|
pipeline_workers = safe_pipeline_worker_count
|
185
220
|
batch_size = @settings[:pipeline_batch_size]
|
@@ -209,16 +244,21 @@ module LogStash; class Pipeline
|
|
209
244
|
end
|
210
245
|
|
211
246
|
# Main body of what a worker thread does
|
212
|
-
# Repeatedly takes batches off the
|
247
|
+
# Repeatedly takes batches off the queue, filters, then outputs them
|
213
248
|
def worker_loop(batch_size, batch_delay)
|
214
249
|
running = true
|
215
250
|
|
251
|
+
namespace_events = metric.namespace([:stats, :events])
|
252
|
+
namespace_pipeline = metric.namespace([:stats, :pipelines, pipeline_id.to_s.to_sym, :events])
|
253
|
+
|
216
254
|
while running
|
217
255
|
# To understand the purpose behind this synchronize please read the body of take_batch
|
218
256
|
input_batch, signal = @input_queue_pop_mutex.synchronize { take_batch(batch_size, batch_delay) }
|
219
257
|
running = false if signal == LogStash::SHUTDOWN
|
220
258
|
|
221
259
|
@events_consumed.increment(input_batch.size)
|
260
|
+
namespace_events.increment(:in, input_batch.size)
|
261
|
+
namespace_pipeline.increment(:in, input_batch.size)
|
222
262
|
|
223
263
|
filtered_batch = filter_batch(input_batch)
|
224
264
|
|
@@ -229,8 +269,14 @@ module LogStash; class Pipeline
|
|
229
269
|
|
230
270
|
@events_filtered.increment(filtered_batch.size)
|
231
271
|
|
272
|
+
namespace_events.increment(:filtered, filtered_batch.size)
|
273
|
+
namespace_pipeline.increment(:filtered, filtered_batch.size)
|
274
|
+
|
232
275
|
output_batch(filtered_batch)
|
233
276
|
|
277
|
+
namespace_events.increment(:out, filtered_batch.size)
|
278
|
+
namespace_pipeline.increment(:out, filtered_batch.size)
|
279
|
+
|
234
280
|
inflight_batches_synchronize { set_current_thread_inflight_batch(nil) }
|
235
281
|
end
|
236
282
|
end
|
@@ -392,7 +438,7 @@ module LogStash; class Pipeline
|
|
392
438
|
def shutdown_workers
|
393
439
|
# Each worker thread will receive this exactly once!
|
394
440
|
@worker_threads.each do |t|
|
395
|
-
@logger.debug("Pushing shutdown", :thread => t
|
441
|
+
@logger.debug("Pushing shutdown", :thread => t)
|
396
442
|
@input_queue.push(LogStash::SHUTDOWN)
|
397
443
|
end
|
398
444
|
|
@@ -409,10 +455,14 @@ module LogStash; class Pipeline
|
|
409
455
|
args << {} if args.empty?
|
410
456
|
args.first.merge!(LogStash::Config::Mixin::ALLOW_ENV_FLAG => @allow_env)
|
411
457
|
|
458
|
+
pipeline_scoped_metric = metric.namespace([:stats, :pipelines, pipeline_id.to_s.to_sym, :plugins])
|
459
|
+
|
412
460
|
klass = LogStash::Plugin.lookup(plugin_type, name)
|
413
461
|
|
414
462
|
if plugin_type == "output"
|
415
|
-
LogStash::OutputDelegator.new(@logger, klass, DEFAULT_OUTPUT_WORKERS, *args)
|
463
|
+
LogStash::OutputDelegator.new(@logger, klass, DEFAULT_OUTPUT_WORKERS, pipeline_scoped_metric.namespace(:outputs), *args)
|
464
|
+
elsif plugin_type == "filter"
|
465
|
+
LogStash::FilterDelegator.new(@logger, klass, pipeline_scoped_metric.namespace(:filters), *args)
|
416
466
|
else
|
417
467
|
klass.new(*args)
|
418
468
|
end
|
@@ -460,6 +510,15 @@ module LogStash; class Pipeline
|
|
460
510
|
end
|
461
511
|
end
|
462
512
|
|
513
|
+
|
514
|
+
# Calculate the uptime in milliseconds
|
515
|
+
#
|
516
|
+
# @return [Fixnum] Uptime in milliseconds, 0 if the pipeline is not started
|
517
|
+
def uptime
|
518
|
+
return 0 if started_at.nil?
|
519
|
+
((Time.now.to_f - started_at.to_f) * 1000.0).to_i
|
520
|
+
end
|
521
|
+
|
463
522
|
# perform filters flush into the output queue
|
464
523
|
# @param options [Hash]
|
465
524
|
# @option options [Boolean] :final => true to signal a final shutdown flush
|
data/lib/logstash/plugin.rb
CHANGED
@@ -5,6 +5,7 @@ require "logstash/config/mixin"
|
|
5
5
|
require "logstash/instrument/null_metric"
|
6
6
|
require "cabin"
|
7
7
|
require "concurrent"
|
8
|
+
require "securerandom"
|
8
9
|
|
9
10
|
class LogStash::Plugin
|
10
11
|
attr_accessor :params
|
@@ -12,35 +13,69 @@ class LogStash::Plugin
|
|
12
13
|
|
13
14
|
NL = "\n"
|
14
15
|
|
15
|
-
|
16
|
+
include LogStash::Config::Mixin
|
17
|
+
|
18
|
+
# Disable or enable metric logging for this specific plugin instance
|
19
|
+
# by default we record all the metrics we can, but you can disable metrics collection
|
20
|
+
# for a specific plugin.
|
21
|
+
config :enable_metric, :validate => :boolean, :default => true
|
22
|
+
|
23
|
+
# Add a unique `ID` to the plugin instance, this `ID` is used for tracking
|
24
|
+
# information for a specific configuration of the plugin.
|
25
|
+
#
|
26
|
+
# ```
|
27
|
+
# output {
|
28
|
+
# stdout {
|
29
|
+
# id => "ABC"
|
30
|
+
# }
|
31
|
+
# }
|
32
|
+
# ```
|
33
|
+
#
|
34
|
+
# If you don't explicitely set this variable Logstash will generate a unique name.
|
35
|
+
config :id, :validate => :string
|
36
|
+
|
16
37
|
def hash
|
17
38
|
params.hash ^
|
18
39
|
self.class.name.hash
|
19
40
|
end
|
20
41
|
|
21
|
-
|
42
|
+
|
22
43
|
def eql?(other)
|
23
44
|
self.class.name == other.class.name && @params == other.params
|
24
45
|
end
|
25
46
|
|
26
|
-
public
|
27
47
|
def initialize(params=nil)
|
28
48
|
@params = LogStash::Util.deep_clone(params)
|
29
49
|
@logger = Cabin::Channel.get(LogStash)
|
30
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return a uniq ID for this plugin configuration, by default
|
53
|
+
# we will generate a UUID
|
54
|
+
#
|
55
|
+
# If the user defines a `id => 'ABC'` in the configuration we will return
|
56
|
+
#
|
57
|
+
# @return [String] A plugin ID
|
58
|
+
def id
|
59
|
+
(@params["id"].nil? || @params["id"].empty?) ? SecureRandom.uuid : @params["id"]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Return a unique_name, This is composed by the name of
|
63
|
+
# the plugin and the generated ID (of the configured one)
|
64
|
+
#
|
65
|
+
# @return [String] a unique name
|
66
|
+
def plugin_unique_name
|
67
|
+
"#{config_name}_#{id}"
|
31
68
|
end
|
32
69
|
|
33
70
|
# close is called during shutdown, after the plugin worker
|
34
71
|
# main task terminates
|
35
|
-
public
|
36
72
|
def do_close
|
37
|
-
@logger.debug("closing", :plugin => self
|
73
|
+
@logger.debug("closing", :plugin => self)
|
38
74
|
close
|
39
75
|
end
|
40
76
|
|
41
77
|
# Subclasses should implement this close method if you need to perform any
|
42
78
|
# special tasks during shutdown (like flushing, etc.)
|
43
|
-
public
|
44
79
|
def close
|
45
80
|
# ..
|
46
81
|
end
|
@@ -49,15 +84,6 @@ class LogStash::Plugin
|
|
49
84
|
return "#{self.class.name}: #{@params}"
|
50
85
|
end
|
51
86
|
|
52
|
-
# This is a shim to make sure that plugin
|
53
|
-
# that record metric still work with 2.4
|
54
|
-
#
|
55
|
-
# https://github.com/elastic/logstash/issues/5539
|
56
|
-
def metric
|
57
|
-
@metric_plugin
|
58
|
-
end
|
59
|
-
|
60
|
-
public
|
61
87
|
def inspect
|
62
88
|
if !@params.nil?
|
63
89
|
description = @params
|
@@ -69,13 +95,26 @@ class LogStash::Plugin
|
|
69
95
|
end
|
70
96
|
end
|
71
97
|
|
72
|
-
public
|
73
98
|
def debug_info
|
74
99
|
[self.class.to_s, original_params]
|
75
100
|
end
|
76
101
|
|
102
|
+
def metric=(new_metric)
|
103
|
+
@metric = new_metric
|
104
|
+
end
|
105
|
+
|
106
|
+
def metric
|
107
|
+
@metric_plugin ||= enable_metric ? @metric : LogStash::Instrument::NullMetric.new
|
108
|
+
end
|
109
|
+
|
110
|
+
# return the configured name of this plugin
|
111
|
+
# @return [String] The name of the plugin defined by `config_name`
|
112
|
+
def config_name
|
113
|
+
self.class.config_name
|
114
|
+
end
|
115
|
+
|
116
|
+
|
77
117
|
# Look up a plugin by type and name.
|
78
|
-
public
|
79
118
|
def self.lookup(type, name)
|
80
119
|
path = "logstash/#{type}s/#{name}"
|
81
120
|
|
@@ -96,7 +135,6 @@ class LogStash::Plugin
|
|
96
135
|
end
|
97
136
|
|
98
137
|
private
|
99
|
-
|
100
138
|
# lookup a plugin by type and name in the existing LogStash module namespace
|
101
139
|
# ex.: namespace_lookup("filter", "grok") looks for LogStash::Filters::Grok
|
102
140
|
# @param type [String] plugin type, "input", "ouput", "filter"
|