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.
This commit is contained in:
Yorick Peterse 2015-12-14 17:37:20 +01:00
parent 5142c61707
commit d67e2045a0
2 changed files with 13 additions and 1 deletions

View file

@ -16,7 +16,11 @@ class MetricsWorker
new_hash = hash.symbolize_keys
new_hash[:tags].each do |key, value|
new_hash[:tags][key] = escape_value(value)
if value.blank?
new_hash[:tags].delete(key)
else
new_hash[:tags][key] = escape_value(value)
end
end
new_hash

View file

@ -30,6 +30,14 @@ describe MetricsWorker do
expect(metrics).to eq([{ values: {}, tags: { 'foo' => 'bar\\=' } }])
end
it 'drops empty tags' do
metrics = worker.prepare_metrics([
{ 'values' => {}, 'tags' => { 'cats' => '', 'dogs' => nil }}
])
expect(metrics).to eq([{ values: {}, tags: {} }])
end
end
describe '#escape_value' do