diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e015f16..30c0906e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Previously, an error would be raised if you passed a symbol as the job name, which is inconsistent with how we handle label values in the rest of the client. This change converts the job name to a string before trying to use it. +- [#297](https://github.com/prometheus/client_ruby/pull/297) Stringify grouping key + values in push client: + Same thing as #296, but for grouping key values. # 4.2.1 / 2023-08-04 diff --git a/lib/prometheus/client/push.rb b/lib/prometheus/client/push.rb index 44147ae1..ca556ed1 100644 --- a/lib/prometheus/client/push.rb +++ b/lib/prometheus/client/push.rb @@ -99,6 +99,8 @@ def build_path(job, grouping_key) end grouping_key.each do |label, value| + value = value.to_s + if value.include?('/') encoded_value = Base64.urlsafe_encode64(value) path += "/#{label}@base64/#{encoded_value}" diff --git a/spec/prometheus/client/push_spec.rb b/spec/prometheus/client/push_spec.rb index 43890366..2f0b70a5 100644 --- a/spec/prometheus/client/push_spec.rb +++ b/spec/prometheus/client/push_spec.rb @@ -101,6 +101,15 @@ expect(push.path).to eql('/metrics/job/foo') end + it 'converts non-string grouping labels to strings' do + push = Prometheus::Client::Push.new( + job: 'test-job', + grouping_key: { foo: :bar, baz: :qux}, + ) + + expect(push.path).to eql('/metrics/job/test-job/foo/bar/baz/qux') + end + it 'encodes the job name in url-safe base64 if it contains `/`' do push = Prometheus::Client::Push.new( job: 'foo/test-job',