From a80ac49be42acb4f7b6349cbc246f4a9fe7178f4 Mon Sep 17 00:00:00 2001 From: Chris Sinjakli Date: Tue, 16 Jul 2019 19:38:31 +0100 Subject: [PATCH] really gross WIP --- lib/prometheus/client/metric.rb | 1 + spec/examples/metric_example.rb | 12 ++++++++++++ spec/prometheus/client/counter_spec.rb | 1 + 3 files changed, 14 insertions(+) diff --git a/lib/prometheus/client/metric.rb b/lib/prometheus/client/metric.rb index 1bb43347..83b35204 100644 --- a/lib/prometheus/client/metric.rb +++ b/lib/prometheus/client/metric.rb @@ -85,6 +85,7 @@ def validate_docstring(docstring) def label_set_for(labels) # We've already validated, and there's nothing to merge. Save some cycles return preset_labels if @all_labels_preset && labels.empty? + labels = labels.map { |k,v| [k, v.to_s] }.to_h @validator.validate_labelset!(preset_labels.merge(labels)) end end diff --git a/spec/examples/metric_example.rb b/spec/examples/metric_example.rb index ced2c317..4dca8c64 100644 --- a/spec/examples/metric_example.rb +++ b/spec/examples/metric_example.rb @@ -63,5 +63,17 @@ expect(subject.get(labels: { test: 'label' })).to be_a(type) end end + + context "with non-string label values" do + subject { described_class.new(:foo, docstring: 'Labels', labels: [:test]) } + + it "converts labels to strings for consistent storage" do + incrementor.call(test: :label) + expect(subject.get(labels: { test: 'label' })).to eq(1.0) + end + + context "and all labels preset" do + end + end end end diff --git a/spec/prometheus/client/counter_spec.rb b/spec/prometheus/client/counter_spec.rb index 806c55b6..c3fee3d1 100644 --- a/spec/prometheus/client/counter_spec.rb +++ b/spec/prometheus/client/counter_spec.rb @@ -20,6 +20,7 @@ it_behaves_like Prometheus::Client::Metric do let(:type) { Float } + let(:incrementor) { ->(labels) { subject.increment(labels: labels); pp subject} } end describe '#increment' do