diff --git a/lib/prometheus/client/push.rb b/lib/prometheus/client/push.rb index 18b63575..628704f2 100644 --- a/lib/prometheus/client/push.rb +++ b/lib/prometheus/client/push.rb @@ -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)) diff --git a/spec/prometheus/client/push_spec.rb b/spec/prometheus/client/push_spec.rb index cea5bcab..d29b0ad2 100644 --- a/spec/prometheus/client/push_spec.rb +++ b/spec/prometheus/client/push_spec.rb @@ -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')