Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify grouping key values in push client #297

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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