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',