lib/prometheus/client/push.rb in prometheus-client-0.6.0 vs lib/prometheus/client/push.rb in prometheus-client-0.7.0.pre.rc.1

- old
+ new

@@ -14,39 +14,45 @@ class Push DEFAULT_GATEWAY = 'http://localhost:9091'.freeze PATH = '/metrics/jobs/%s'.freeze INSTANCE_PATH = '/metrics/jobs/%s/instances/%s'.freeze HEADER = { 'Content-Type' => Formats::Text::CONTENT_TYPE }.freeze + SUPPORTED_SCHEMES = %w(http https).freeze attr_reader :job, :instance, :gateway, :path def initialize(job, instance = nil, gateway = nil) @job = job @instance = instance @gateway = gateway || DEFAULT_GATEWAY @uri = parse(@gateway) @path = build_path(job, instance) @http = Net::HTTP.new(@uri.host, @uri.port) + @http.use_ssl = @uri.scheme == 'https' end def add(registry) request('POST', registry) end def replace(registry) request('PUT', registry) end + def delete + @http.send_request('DELETE', path) + end + private def parse(url) uri = URI.parse(url) - if uri.scheme == 'http' - uri - else + unless SUPPORTED_SCHEMES.include?(uri.scheme) raise ArgumentError, 'only HTTP gateway URLs are supported currently.' end + + uri rescue URI::InvalidURIError => e raise ArgumentError, "#{url} is not a valid URL: #{e}" end def build_path(job, instance)