Skip to content

Commit d08e7b3

Browse files
authored
Merge pull request #296 from prometheus/sinjo-stringify-job-name
Stringify non-string job names in push client
2 parents e144d62 + 2f5422c commit d08e7b3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
# Unreleased changes
44

5-
_None outstanding_
5+
## Bug fixes
6+
7+
- [#296](https://github.com/prometheus/client_ruby/pull/296) Stringify non-string job
8+
names in push client:
9+
Previously, an error would be raised if you passed a symbol as the job name, which
10+
is inconsistent with how we handle label values in the rest of the client. This
11+
change converts the job name to a string before trying to use it.
612

713
# 4.2.1 / 2023-08-04
814

lib/prometheus/client/push.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def parse(url)
8787
end
8888

8989
def build_path(job, grouping_key)
90+
job = job.to_s
91+
9092
# Job can't be empty, but it can contain `/`, so we need to base64
9193
# encode it in that case
9294
if job.include?('/')

spec/prometheus/client/push_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@
9393
expect(push.path).to eql('/metrics/job/test-job/foo/bar/baz/qux')
9494
end
9595

96+
it 'converts non-string job names to strings' do
97+
push = Prometheus::Client::Push.new(
98+
job: :foo,
99+
)
100+
101+
expect(push.path).to eql('/metrics/job/foo')
102+
end
103+
96104
it 'encodes the job name in url-safe base64 if it contains `/`' do
97105
push = Prometheus::Client::Push.new(
98106
job: 'foo/test-job',

0 commit comments

Comments
 (0)