diff --git a/CHANGELOG.md b/CHANGELOG.md index e9ec9845..2e015f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/prometheus/client/push.rb b/lib/prometheus/client/push.rb index 1490c82d..44147ae1 100644 --- a/lib/prometheus/client/push.rb +++ b/lib/prometheus/client/push.rb @@ -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?('/') diff --git a/spec/prometheus/client/push_spec.rb b/spec/prometheus/client/push_spec.rb index 4af55ad5..43890366 100644 --- a/spec/prometheus/client/push_spec.rb +++ b/spec/prometheus/client/push_spec.rb @@ -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',