Skip to content

Commit

Permalink
Merge pull request #296 from prometheus/sinjo-stringify-job-name
Browse files Browse the repository at this point in the history
Stringify non-string job names in push client
  • Loading branch information
Sinjo authored Oct 7, 2023
2 parents e144d62 + 2f5422c commit d08e7b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit d08e7b3

Please sign in to comment.