Skip to content

Commit

Permalink
Stringify non-string job names in push client
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sinjo committed Oct 7, 2023
1 parent e144d62 commit ca53b57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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 ca53b57

Please sign in to comment.