Skip to content

Commit bd9c91f

Browse files
authored
Merge pull request #297 from prometheus/sinjo-stringify-push-grouping-key
Stringify grouping key values in push client
2 parents d08e7b3 + 30adf63 commit bd9c91f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
Previously, an error would be raised if you passed a symbol as the job name, which
1010
is inconsistent with how we handle label values in the rest of the client. This
1111
change converts the job name to a string before trying to use it.
12+
- [#297](https://github.com/prometheus/client_ruby/pull/297) Stringify grouping key
13+
values in push client:
14+
Same thing as #296, but for grouping key values.
1215

1316
# 4.2.1 / 2023-08-04
1417

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)