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 non-string job names in push client #296

Merged
merged 2 commits into from
Oct 7, 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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

# Unreleased changes

_None outstanding_
## Bug fixes

- [#296](https://github.com/prometheus/client_ruby/pull/296) Stringify non-string job
names in push client:
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.

# 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 @@ -87,6 +87,8 @@ def parse(url)
end

def build_path(job, grouping_key)
job = job.to_s

# Job can't be empty, but it can contain `/`, so we need to base64
# encode it in that case
if job.include?('/')
Expand Down
8 changes: 8 additions & 0 deletions spec/prometheus/client/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
expect(push.path).to eql('/metrics/job/test-job/foo/bar/baz/qux')
end

it 'converts non-string job names to strings' do
push = Prometheus::Client::Push.new(
job: :foo,
)

expect(push.path).to eql('/metrics/job/foo')
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