Skip to content

Commit

Permalink
really gross WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinjakli committed Jul 16, 2019
1 parent 607a43a commit a80ac49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/prometheus/client/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/examples/metric_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/prometheus/client/counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a80ac49

Please sign in to comment.