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:
parent
5142c61707
commit
d67e2045a0
2 changed files with 13 additions and 1 deletions
|
@ -16,8 +16,12 @@ class MetricsWorker
|
|||
new_hash = hash.symbolize_keys
|
||||
|
||||
new_hash[:tags].each do |key, value|
|
||||
if value.blank?
|
||||
new_hash[:tags].delete(key)
|
||||
else
|
||||
new_hash[:tags][key] = escape_value(value)
|
||||
end
|
||||
end
|
||||
|
||||
new_hash
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue