Skip to content

Commit dfa5f90

Browse files
committed
Handle empty instance label in push.rb
Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
1 parent 7fc1064 commit dfa5f90

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/prometheus/client/push.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def parse(url)
7171
end
7272

7373
def build_path(job, instance)
74-
if instance
74+
if instance && !instance.empty?
7575
format(INSTANCE_PATH, CGI::escape(job), CGI::escape(instance))
7676
else
7777
format(PATH, CGI::escape(job))

spec/prometheus/client/push_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
expect(push.path).to eql('/metrics/job/test-job')
7777
end
7878

79+
it 'uses the default metrics path if an empty instance value is given' do
80+
push = Prometheus::Client::Push.new(job: 'bar-job', instance: '')
81+
82+
expect(push.path).to eql('/metrics/job/bar-job')
83+
end
84+
7985
it 'uses the full metrics path if an instance value is given' do
8086
push = Prometheus::Client::Push.new(job: 'bar-job', instance: 'foo')
8187

0 commit comments

Comments
 (0)