Skip to content

Commit

Permalink
Merge pull request #297 from prometheus/sinjo-stringify-push-grouping…
Browse files Browse the repository at this point in the history
…-key

Stringify grouping key values in push client
  • Loading branch information
Sinjo authored Oct 22, 2023
2 parents d08e7b3 + 30adf63 commit bd9c91f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/prometheus/client/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 9 additions & 0 deletions spec/prometheus/client/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit bd9c91f

Please sign in to comment.