Class: LogStash::Plugins::PluginFactory
- Inherits:
-
Object
- Object
- LogStash::Plugins::PluginFactory
- Includes:
- orgorg.logstashorg.logstash.configorg.logstash.config.irorg.logstash.config.ir.compilerorg.logstash.config.ir.compiler.RubyIntegrationorg.logstash.config.ir.compiler.RubyIntegration::PluginFactory
- Defined in:
- lib/logstash/plugins/plugin_factory.rb
Instance Method Summary collapse
- #buildCodec(name, *args) ⇒ Object
- #buildFilter(name, line, column, *args) ⇒ Object
- #buildInput(name, line, column, *args) ⇒ Object
- #buildOutput(name, line, column, *args) ⇒ Object
-
#initialize(lir, metric_factory, exec_factory, filter_class) ⇒ PluginFactory
constructor
A new instance of PluginFactory.
- #plugin(plugin_type, name, line, column, *args) ⇒ Object
Constructor Details
#initialize(lir, metric_factory, exec_factory, filter_class) ⇒ PluginFactory
Returns a new instance of PluginFactory.
35 36 37 38 39 40 41 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 35 def initialize(lir, metric_factory, exec_factory, filter_class) @lir = lir @plugins_by_id = {} @metric_factory = metric_factory @exec_factory = exec_factory @filter_class = filter_class end |
Instance Method Details
#buildCodec(name, *args) ⇒ Object
55 56 57 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 55 def buildCodec(name, *args) plugin("codec", name, 0, 0, *args) end |
#buildFilter(name, line, column, *args) ⇒ Object
47 48 49 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 47 def buildFilter(name, line, column, *args) plugin("filter", name, line, column, *args) end |
#buildInput(name, line, column, *args) ⇒ Object
51 52 53 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 51 def buildInput(name, line, column, *args) plugin("input", name, line, column, *args) end |
#buildOutput(name, line, column, *args) ⇒ Object
43 44 45 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 43 def buildOutput(name, line, column, *args) plugin("output", name, line, column, *args) end |
#plugin(plugin_type, name, line, column, *args) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/logstash/plugins/plugin_factory.rb', line 59 def plugin(plugin_type, name, line, column, *args) # Collapse the array of arguments into a single merged hash args = args.reduce({}, &:merge) if plugin_type == "codec" id = SecureRandom.uuid # codecs don't really use their IDs for metrics, so we can use anything here else # Pull the ID from LIR to keep IDs consistent between the two representations id = @lir.graph.vertices.filter do |v| v. && v..line == line && v..column == column end.findFirst.get.id end args["id"] = id # some code pulls the id out of the args raise ConfigurationError, "Could not determine ID for #{plugin_type}/#{plugin_name}" unless id raise ConfigurationError, "Two plugins have the id '#{id}', please fix this conflict" if @plugins_by_id[id] @plugins_by_id[id] = true # Scope plugins of type 'input' to 'inputs' type_scoped_metric = @metric_factory.create(plugin_type) klass = Plugin.lookup(plugin_type, name) execution_context = @exec_factory.create(id, klass.config_name) if plugin_type == "output" OutputDelegator.new(klass, type_scoped_metric, execution_context, OutputDelegatorStrategyRegistry.instance, args) elsif plugin_type == "filter" @filter_class.new(klass, type_scoped_metric, execution_context, args) else # input or codec plugin plugin_instance = klass.new(args) scoped_metric = type_scoped_metric.namespace(id.to_sym) scoped_metric.gauge(:name, plugin_instance.config_name) plugin_instance.metric = scoped_metric plugin_instance.execution_context = execution_context plugin_instance end end |