Skip to content

Commit ca53b57

Browse files
committed
Stringify non-string job names in push client
We do this to all other label values in the client and we should make this one consistent. Right now it's particularly surprising that passing a symbol as the job name results in an error like: ``` undefined method `include?' for :foo:Symbol (NoMethodError) ``` Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
1 parent e144d62 commit ca53b57

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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)