Skip to content

Commit

Permalink
Handle empty instance label in push.rb
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
  • Loading branch information
Sinjo committed Mar 27, 2021
1 parent 8f3e71a commit 8137703
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prometheus/client/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse(url)
end

def build_path(job, instance)
if instance
if instance && !instance.empty?
format(INSTANCE_PATH, CGI::escape(job), CGI::escape(instance))
else
format(PATH, CGI::escape(job))
Expand Down
6 changes: 6 additions & 0 deletions spec/prometheus/client/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
expect(push.path).to eql('/metrics/job/test-job')
end

it 'uses the default metrics path if an empty instance value is given' do
push = Prometheus::Client::Push.new(job: 'bar-job', instance: '')

expect(push.path).to eql('/metrics/job/bar-job')
end

it 'uses the full metrics path if an instance value is given' do
push = Prometheus::Client::Push.new(job: 'bar-job', instance: 'foo')

Expand Down

0 comments on commit 8137703

Please sign in to comment.