Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-02 23:42:24 +0300
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-02 23:42:24 +0300
commitb38b5ceb8e039283e90dd323327e59c8f608c103 (patch)
treecc7525f7681e7bdc15add9577fd5bc74705fa0c6 /lib/gitlab/prometheus_client.rb
parentdb2433c36da6410c803163139e41228f9ae3f26b (diff)
Move client creation to Prometheus Application, manufacture proper rest client
Diffstat (limited to 'lib/gitlab/prometheus_client.rb')
-rw-r--r--lib/gitlab/prometheus_client.rb14
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/gitlab/prometheus_client.rb b/lib/gitlab/prometheus_client.rb
index 8ec4515fb12..d1875dd1042 100644
--- a/lib/gitlab/prometheus_client.rb
+++ b/lib/gitlab/prometheus_client.rb
@@ -3,12 +3,10 @@ module Gitlab
# Helper methods to interact with Prometheus network services & resources
class PrometheusClient
- attr_reader :api_url, :rest_client, :headers
+ attr_reader :rest_client, :headers
- def initialize(api_url:, rest_client: nil, headers: nil)
- @api_url = api_url
+ def initialize(rest_client)
@rest_client = rest_client || RestClient::Resource.new(api_url)
- @headers = headers || {}
end
def ping
@@ -49,7 +47,7 @@ module Gitlab
end
def get(path, args)
- response = rest_client[path].get(headers.merge(params: args))
+ response = rest_client[path].get(params: args)
handle_response(response)
rescue SocketError
raise PrometheusError, "Can't connect to #{url}"
@@ -60,7 +58,7 @@ module Gitlab
end
def handle_response(response)
- json_data = json_response(response)
+ json_data = JSON.parse(response.body)
if response.code == 200 && json_data['status'] == 'success'
json_data['data'] || {}
elsif response.code == 400
@@ -70,10 +68,6 @@ module Gitlab
end
end
- def json_response(response)
- JSON.parse(response.body)
- end
-
def get_result(expected_type)
data = yield
data['result'] if data['resultType'] == expected_type