Skip to content

Commit

Permalink
CLEANUP: Dry up filter wrapper setup
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Apr 8, 2018
1 parent 57e23c0 commit 7cea457
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
13 changes: 5 additions & 8 deletions logstash-core/lib/logstash/filter_delegator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ class FilterDelegator

attr_reader :id

def initialize(klass, metric, execution_context, plugin_args)
@klass = klass
@id = plugin_args["id"]
@filter = klass.new(plugin_args)
def initialize(filter, id)
@klass = filter.class
@id = id
@filter = filter

# Scope the metrics to the plugin
namespaced_metric = metric.namespace(@id.to_sym)
@filter.metric = namespaced_metric
@filter.execution_context = execution_context

namespaced_metric = filter.metric
@metric_events = namespaced_metric.namespace(:events)
@metric_events_in = @metric_events.counter(:in)
@metric_events_out = @metric_events.counter(:out)
Expand Down
13 changes: 5 additions & 8 deletions logstash-core/lib/logstash/java_filter_delegator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ class JavaFilterDelegator

attr_reader :id

def initialize(klass, metric, execution_context, plugin_args)
@klass = klass
@id = plugin_args["id"]
@filter = klass.new(plugin_args)
def initialize(filter, id)
@klass = filter.class
@id = id
@filter = filter

# Scope the metrics to the plugin
namespaced_metric = metric.namespace(@id.to_sym)
@filter.metric = namespaced_metric
@filter.execution_context = execution_context

namespaced_metric = filter.metric
@metric_events = namespaced_metric.namespace(:events)
@metric_events_in = @metric_events.counter(:in)
@metric_events_out = @metric_events.counter(:out)
Expand Down
10 changes: 9 additions & 1 deletion logstash-core/lib/logstash/plugins/plugin_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def create(plugin_type)
class PluginFactory
include org.logstash.config.ir.compiler.RubyIntegration::PluginFactory

def self.filter_delegator(wrapper_class, filter_class, args, filter_metrics, execution_context)
filter_instance = filter_class.new(args)
id = args["id"]
filter_instance.metric = filter_metrics.namespace(id.to_sym)
filter_instance.execution_context = execution_context
wrapper_class.new(filter_instance, id)
end

def initialize(lir, metric_factory, exec_factory, filter_class)
@lir = lir
@plugins_by_id = {}
Expand Down Expand Up @@ -84,7 +92,7 @@ def plugin(plugin_type, name, line, column, *args)
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)
self.class.filter_delegator(@filter_class, klass, args, type_scoped_metric, execution_context)
else # input or codec plugin
plugin_instance = klass.new(args)
scoped_metric = type_scoped_metric.namespace(id.to_sym)
Expand Down
11 changes: 5 additions & 6 deletions logstash-core/spec/logstash/filter_delegator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def register; end
end
end

subject { described_class.new(plugin_klass, metric, execution_context, config) }

it "create a plugin with the passed options" do
expect(plugin_klass).to receive(:new).with(config).and_return(plugin_klass.new(config))
described_class.new(plugin_klass, metric, execution_context, config)
end
subject {
LogStash::Plugins::PluginFactory.filter_delegator(
described_class, plugin_klass, config, metric, execution_context
)
}

context "when the plugin support flush" do
let(:plugin_klass) do
Expand Down
11 changes: 5 additions & 6 deletions logstash-core/spec/logstash/java_filter_delegator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def register; end
end
end

subject { described_class.new(plugin_klass, metric, execution_context, config) }

it "create a plugin with the passed options" do
expect(plugin_klass).to receive(:new).with(config).and_return(plugin_klass.new(config))
described_class.new(plugin_klass, metric, execution_context, config)
end
subject {
LogStash::Plugins::PluginFactory.filter_delegator(
described_class, plugin_klass, config, metric, execution_context
)
}

context "when the plugin support flush" do
let(:plugin_klass) do
Expand Down

0 comments on commit 7cea457

Please sign in to comment.