diff options
author | David Wilkins <dwilkins@gitlab.com> | 2019-08-07 05:42:20 +0300 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-07 05:42:20 +0300 |
commit | 467a411e8892ecd6a3be7cd2f6772665f2c63651 (patch) | |
tree | c7ee78a5f64224569be50ae2534e10ce566fe6df /app/models/project_services | |
parent | b67ed9c96720864b9ddae973b34f7456c9321789 (diff) |
Convert RestClient to Gitlab::HTTP for Prometheus Monitor
- Closes #60024
- Change PrometheusClient.new to accept a base url instead of an
already created RestClient
- Use Gitlab::HTTP in PrometheusClient instead of creating RestClient
in PrometheusService
- Move http_options from PrometheusService to
PrometheusClient (follow_redirects: false)
- ensure that base urls don't have the trailing slash
- Created a `PrometheusClient#url` method that might not be strictly
required
- Change rescued exceptions from RestClient::* to
HTTParty::ResponseError where possible and StandardError for the
rest
Diffstat (limited to 'app/models/project_services')
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb index c68a9d923c8..6eff2ea2e3a 100644 --- a/app/models/project_services/prometheus_service.rb +++ b/app/models/project_services/prometheus_service.rb @@ -63,15 +63,16 @@ class PrometheusService < MonitoringService # Check we can connect to the Prometheus API def test(*args) - Gitlab::PrometheusClient.new(prometheus_client).ping - + prometheus_client.ping { success: true, result: 'Checked API endpoint' } rescue Gitlab::PrometheusClient::Error => err { success: false, result: err } end def prometheus_client - RestClient::Resource.new(api_url, max_redirects: 0) if should_return_client? + return unless should_return_client? + + Gitlab::PrometheusClient.new(api_url) end def prometheus_available? @@ -84,7 +85,7 @@ class PrometheusService < MonitoringService private def should_return_client? - api_url && manual_configuration? && active? && valid? + api_url.present? && manual_configuration? && active? && valid? end def synchronize_service_state |