File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class HttpClientError < HttpError; end
2323 class HttpServerError < HttpError ; end
2424
2525 DEFAULT_GATEWAY = 'http://localhost:9091' . freeze
26- PATH = '/metrics/job/%s ' . freeze
26+ PATH = '/metrics' . freeze
2727 SUPPORTED_SCHEMES = %w( http https ) . freeze
2828
2929 attr_reader :job , :gateway , :path
@@ -87,7 +87,14 @@ def parse(url)
8787 end
8888
8989 def build_path ( job , grouping_key )
90- path = format ( PATH , ERB ::Util ::url_encode ( job ) )
90+ # Job can't be empty, but it can contain `/`, so we need to base64
91+ # encode it in that case
92+ if job . include? ( '/' )
93+ encoded_job = Base64 . urlsafe_encode64 ( job )
94+ path = "#{ PATH } /job@base64/#{ encoded_job } "
95+ else
96+ path = "#{ PATH } /job/#{ ERB ::Util ::url_encode ( job ) } "
97+ end
9198
9299 grouping_key . each do |label , value |
93100 if value . include? ( '/' )
Original file line number Diff line number Diff line change 9393 expect ( push . path ) . to eql ( '/metrics/job/test-job/foo/bar/baz/qux' )
9494 end
9595
96+ it 'encodes the job name in url-safe base64 if it contains `/`' do
97+ push = Prometheus ::Client ::Push . new (
98+ job : 'foo/test-job' ,
99+ )
100+
101+ expect ( push . path ) . to eql ( '/metrics/job@base64/Zm9vL3Rlc3Qtam9i' )
102+ end
103+
96104 it 'encodes grouping key label values containing `/` in url-safe base64' do
97105 push = Prometheus ::Client ::Push . new (
98106 job : 'test-job' ,
You can’t perform that action at this time.
0 commit comments