Commit d67e2045 authored by Yorick Peterse's avatar Yorick Peterse

Drop empty tag values from metrics

InfluxDB throws an error when trying to store a list of tags where one
or more have an empty value.
parent 5142c617
...@@ -16,8 +16,12 @@ class MetricsWorker ...@@ -16,8 +16,12 @@ class MetricsWorker
new_hash = hash.symbolize_keys new_hash = hash.symbolize_keys
new_hash[:tags].each do |key, value| new_hash[:tags].each do |key, value|
if value.blank?
new_hash[:tags].delete(key)
else
new_hash[:tags][key] = escape_value(value) new_hash[:tags][key] = escape_value(value)
end end
end
new_hash new_hash
end end
......
...@@ -30,6 +30,14 @@ describe MetricsWorker do ...@@ -30,6 +30,14 @@ describe MetricsWorker do
expect(metrics).to eq([{ values: {}, tags: { 'foo' => 'bar\\=' } }]) expect(metrics).to eq([{ values: {}, tags: { 'foo' => 'bar\\=' } }])
end end
it 'drops empty tags' do
metrics = worker.prepare_metrics([
{ 'values' => {}, 'tags' => { 'cats' => '', 'dogs' => nil }}
])
expect(metrics).to eq([{ values: {}, tags: {} }])
end
end end
describe '#escape_value' do describe '#escape_value' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment