Skip to content
Permalink
Browse files

add validation for invalid use of record accessor syntax in configura…

…tion step

Signed-off-by: Masahiro Sano <sabottenda@gmail.com>
  • Loading branch information...
kazegusuri committed Mar 2, 2019
1 parent e7ea910 commit 959d20011b92374393462ad1d26aadac4e2f2374
@@ -27,9 +27,10 @@ def configure(conf)
placeholders = expander.prepare_placeholders({'hostname' => hostname, 'worker_id' => fluentd_worker_id})
@base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf)
@base_labels.each do |key, value|
if value.is_a?(String)
@base_labels[key] = expander.expand(value, placeholders)
unless value.is_a?(String)
raise Fluent::ConfigError, "record accessor syntax is not available in prometheus_monitor"
end
@base_labels[key] = expander.expand(value, placeholders)
end

if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput)
@@ -42,6 +42,9 @@ def configure(conf)
placeholders = expander.prepare_placeholders({'hostname' => hostname, 'worker_id' => fluentd_worker_id})
@base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf)
@base_labels.each do |key, value|
unless value.is_a?(String)
raise Fluent::ConfigError, "record accessor syntax is not available in prometheus_output_monitor"
end
@base_labels[key] = expander.expand(value, placeholders)
end

@@ -31,6 +31,9 @@ def configure(conf)
placeholders = expander.prepare_placeholders({'hostname' => hostname, 'worker_id' => fluentd_worker_id})
@base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf)
@base_labels.each do |key, value|
unless value.is_a?(String)
raise Fluent::ConfigError, "record accessor syntax is not available in prometheus_tail_monitor"
end
@base_labels[key] = expander.expand(value, placeholders)
end

@@ -8,8 +8,17 @@
<labels>
host ${hostname}
foo bar
no_effect1 $.foo.bar
no_effect2 $[0][1]
</labels>
]

INVALID_MONITOR_CONFIG = %[
@type prometheus_monitor
<labels>
host ${hostname}
foo bar
invalid_use1 $.foo.bar
invalid_use2 $[0][1]
</labels>
]

@@ -18,8 +27,17 @@
let(:driver) { Fluent::Test::Driver::Input.new(Fluent::Plugin::PrometheusMonitorInput).configure(config) }

describe '#configure' do
it 'does not raise error' do
expect{driver}.not_to raise_error
describe 'valid' do
it 'does not raise error' do
expect{driver}.not_to raise_error
end
end

describe 'invalid' do
let(:config) { INVALID_MONITOR_CONFIG }
it 'expect raise error' do
expect{driver}.to raise_error
end
end
end
end

0 comments on commit 959d200

Please sign in to comment.
You can’t perform that action at this time.