Skip to content

Commit 2dd8cf5

Browse files
committed
fixes from reviews from @joao
Fixes elastic#6109
1 parent 02f15c8 commit 2dd8cf5

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

logstash-core/lib/logstash/event_dispatcher.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ def remove_listener(listener)
3131
def fire(method_name, *arguments)
3232
@listeners.each do |listener|
3333
if listener.respond_to?(method_name)
34-
if arguments.size > 0
35-
listener.send(method_name, emitter, *arguments)
36-
else
37-
listener.send(method_name, emitter)
38-
end
34+
listener.send(method_name, emitter, *arguments)
3935
end
4036
end
4137
end

logstash-core/lib/logstash/plugins/registry.rb

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class GemRegistry
1515
LOGSTASH_METADATA_KEY = "logstash_plugin"
1616

1717
class << self
18-
def available_libraries
18+
def installed_gems
1919
::Gem::Specification
2020
end
2121

2222
def logstash_plugins
23-
available_libraries
23+
installed_gems
2424
.select { |spec| spec.metadata && spec.metadata[LOGSTASH_METADATA_KEY] }
2525
.collect { |spec| PluginRawContext.new(spec) }
2626
end
@@ -65,11 +65,7 @@ def has_hooks?
6565
end
6666

6767
def execute_hooks!
68-
if has_hooks?
69-
require hooks_file
70-
else
71-
raise ArgumentError, "#execute_hooks! called but no hooks file where found for #{name} of type #{type}"
72-
end
68+
require hooks_file
7369
end
7470
end
7571

@@ -98,8 +94,8 @@ def register(hooks, settings)
9894
attr_reader :hooks
9995

10096
def initialize
101-
@registry = {}
102-
@hooks = HooksRegistry.new
97+
@registry = {}
98+
@hooks = HooksRegistry.new
10399
end
104100

105101
def setup!
@@ -134,38 +130,47 @@ def lookup(type, plugin_name, &block)
134130
plugin = get(type, plugin_name)
135131
# Assume that we have a legacy plugin
136132
if plugin.nil?
137-
begin
138-
path = "logstash/#{type}s/#{plugin_name}"
139-
140-
begin
141-
require path
142-
rescue LoadError
143-
# Plugin might be already defined in the current scope
144-
# This scenario often happen in test when we write an adhoc class
145-
end
146-
147-
klass = namespace_lookup(type, plugin_name)
148-
plugin = lazy_add(type, plugin_name, klass)
149-
rescue => e
150-
logger.warn("Problems loading a plugin with",
151-
:type => type,
152-
:name => plugin_name,
153-
:path => path,
154-
:error_message => e.message,
155-
:error_class => e.class,
156-
:error_backtrace => e.backtrace)
157-
158-
raise LoadError, "Problems loading the requested plugin named #{plugin_name} of type #{type}. Error: #{e.class} #{e.message}"
159-
end
133+
plugin = legacy_lookup(type, plugin_name)
160134
end
161135

162136
if block_given? # if provided pass a block to do validation
163-
raise LoadError unless block.call(plugin.klass, plugin_name)
137+
raise LoadError, "Block validation fails for plugin named #{plugin_name} of type #{type}," unless block.call(plugin.klass, plugin_name)
164138
end
165139

166140
return plugin.klass
167141
end
168142

143+
# The legacy_lookup method uses the 1.5->5.0 file structure to find and match
144+
# a plugin and will do a lookup on the namespace of the required class to find a matching
145+
# plugin with the appropriate type.
146+
def legacy_lookup(type, plugin_name)
147+
begin
148+
path = "logstash/#{type}s/#{plugin_name}"
149+
150+
begin
151+
require path
152+
rescue LoadError
153+
# Plugin might be already defined in the current scope
154+
# This scenario often happen in test when we write an adhoc class
155+
end
156+
157+
klass = namespace_lookup(type, plugin_name)
158+
plugin = lazy_add(type, plugin_name, klass)
159+
rescue => e
160+
logger.error("Problems loading a plugin with",
161+
:type => type,
162+
:name => plugin_name,
163+
:path => path,
164+
:error_message => e.message,
165+
:error_class => e.class,
166+
:error_backtrace => e.backtrace)
167+
168+
raise LoadError, "Problems loading the requested plugin named #{plugin_name} of type #{type}. Error: #{e.class} #{e.message}"
169+
end
170+
171+
plugin
172+
end
173+
169174
def lookup_pipeline_plugin(type, name)
170175
LogStash::PluginRegistry.lookup(type, name) do |plugin_klass, plugin_name|
171176
is_a_plugin?(plugin_klass, plugin_name)
@@ -176,12 +181,12 @@ def lookup_pipeline_plugin(type, name)
176181
end
177182

178183
def lazy_add(type, name, klass)
179-
logger.error("On demand adding plugin to the registry", :name => name, :type => type, :class => klass)
184+
logger.debug("On demand adding plugin to the registry", :name => name, :type => type, :class => klass)
180185
add_plugin(type, name, klass)
181186
end
182187

183188
def add(type, name, klass)
184-
logger.error("Adding plugin to the registry", :name => name, :type => type, :class => klass)
189+
logger.debug("Adding plugin to the registry", :name => name, :type => type, :class => klass)
185190
add_plugin(type, name, klass)
186191
end
187192

@@ -230,7 +235,7 @@ def add_plugin(type, name, klass)
230235
specification_klass = type == :universal ? UniversalPluginSpecification : PluginSpecification
231236
@registry[key_for(type, name)] = specification_klass.new(type, name, klass)
232237
else
233-
logger.info("Ignoring, plugin already added to the registry", :name => name, :type => type, :klass => klass)
238+
logger.debug("Ignoring, plugin already added to the registry", :name => name, :type => type, :klass => klass)
234239
end
235240
end
236241

logstash-core/lib/logstash/runner.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ def execute
199199
logger.warn("--config.debug was specified, but log.level was not set to \'debug\'! No config info will be logged.")
200200
end
201201

202+
# We configure the registry and load any plugin that can register hooks
203+
# with logstash, this need to be done before any operation.
202204
LogStash::PluginRegistry.setup!
203205
@settings.validate_all
204206

@@ -227,8 +229,6 @@ def execute
227229

228230
return start_shell(setting("interactive"), binding) if setting("interactive")
229231

230-
231-
232232
@settings.format_settings.each {|line| logger.debug(line) }
233233

234234
if setting("config.string").nil? && setting("path.config").nil?
@@ -338,8 +338,7 @@ def configure_plugin_paths(paths)
338338
end
339339

340340
def create_agent(*args)
341-
agent = LogStash::Agent.new(*args)
342-
agent
341+
LogStash::Agent.new(*args)
343342
end
344343

345344
# Emit a failure message and abort.

0 commit comments

Comments
 (0)