mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Fix issue setting 'enable_metric => false' on a plugin
This commit fixes a ClassCastException which happens when a plugin has the `enable_metric` setting set to false - a NullMetricExt is assumed, but that is only created when 'metric.collect' is set to 'false' in the Logstash configuration, not when an individual plugin disables its metrics. Fixes #10538
This commit is contained in:
parent
772dccb880
commit
f0006a051e
2 changed files with 15 additions and 1 deletions
|
@ -322,4 +322,18 @@ describe LogStash::Filters::NOOP do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
describe "when metrics are disabled" do
|
||||
describe "An error should not be raised, and the event should be processed" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
noop { enable_metric => false }
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample_one("type" => "noop", "tags" => {"blackhole" => "go"}) do
|
||||
expect(subject.get("[tags][blackhole]")).to eq("go")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ public final class NullNamespacedMetricExt extends AbstractNamespacedMetricExt {
|
|||
@JRubyMethod(optional = 2)
|
||||
public NullNamespacedMetricExt initialize(final ThreadContext context,
|
||||
final IRubyObject[] args) {
|
||||
this.metric = args.length > 0 && !args[0].isNil() ? (NullMetricExt) args[0] : new NullMetricExt(context.runtime, metaClass);
|
||||
this.metric = args.length > 0 && !args[0].isNil() && (args[0] instanceof NullMetricExt) ? (NullMetricExt) args[0] : new NullMetricExt(context.runtime, metaClass);
|
||||
final IRubyObject namespaceName = args.length == 2 ? args[1] : NULL;
|
||||
if (namespaceName instanceof RubyArray) {
|
||||
this.namespaceName = (RubyArray) namespaceName;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue