Skip to content

Commit 4cd41fc

Browse files
committed
Stringify grouping key values in push client
About a day after fixing this for the job name I realised that I'd made the same mistake a whole ten lines of code further down the method. Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
1 parent d08e7b3 commit 4cd41fc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/prometheus/client/push.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def build_path(job, grouping_key)
9999
end
100100

101101
grouping_key.each do |label, value|
102+
value = value.to_s
103+
102104
if value.include?('/')
103105
encoded_value = Base64.urlsafe_encode64(value)
104106
path += "/#{label}@base64/#{encoded_value}"

spec/prometheus/client/push_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@
101101
expect(push.path).to eql('/metrics/job/foo')
102102
end
103103

104+
it 'converts non-string grouping labels to strings' do
105+
push = Prometheus::Client::Push.new(
106+
job: 'test-job',
107+
grouping_key: { foo: :bar, baz: :qux},
108+
)
109+
110+
expect(push.path).to eql('/metrics/job/test-job/foo/bar/baz/qux')
111+
end
112+
104113
it 'encodes the job name in url-safe base64 if it contains `/`' do
105114
push = Prometheus::Client::Push.new(
106115
job: 'foo/test-job',

0 commit comments

Comments
 (0)