From 0c802f4fba67e4fe54f9c4442d280fc7465e6b3f Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 2 Jan 2018 22:40:03 +0100 Subject: Manual Configuration instead of Activation. Prometheus Service just got a bit weirder --- app/controllers/concerns/service_params.rb | 1 + app/models/project_services/prometheus_service.rb | 36 ++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/service_params.rb b/app/controllers/concerns/service_params.rb index 3d61458c064..c1acb50b76c 100644 --- a/app/controllers/concerns/service_params.rb +++ b/app/controllers/concerns/service_params.rb @@ -32,6 +32,7 @@ module ServiceParams :issues_events, :issues_url, :jira_issue_transition_id, + :manual_configuration, :merge_requests_events, :mock_service_url, :namespace, diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb index 5e5aa92fd1a..9644c27cae8 100644 --- a/app/models/project_services/prometheus_service.rb +++ b/app/models/project_services/prometheus_service.rb @@ -7,19 +7,27 @@ class PrometheusService < MonitoringService # Access to prometheus is directly through the API prop_accessor :api_url + boolean_accessor :manual_configuration - with_options presence: true, if: :activated? do + with_options presence: true, if: :manual_configuration? do validates :api_url, url: true end + before_save :synchronize_service_state! + after_save :clear_reactive_cache! + def initialize_properties if properties.nil? self.properties = {} end end + def show_active_box? + false + end + def title 'Prometheus' end @@ -34,6 +42,18 @@ class PrometheusService < MonitoringService def fields [ + { type: 'fieldset', + legend: 'Manual Configuration', + fields: [ + { + type: 'checkbox', + name: 'manual_configuration', + title: s_('PrometheusService|Active'), + required: true + } + ] + }, + { type: 'text', name: 'api_url', @@ -79,16 +99,11 @@ class PrometheusService < MonitoringService with_reactive_cache(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, nil, &:itself) end - def manual_mode? - false - end - # Cache metrics for specific environment def calculate_reactive_cache(query_class_name, environment_id, *args) return unless active? && project && !project.pending_delete? client = client(environment_id) - data = Kernel.const_get(query_class_name).new(client).query(environment_id, *args) { success: true, @@ -100,12 +115,13 @@ class PrometheusService < MonitoringService end def client(environment_id) - if manual_mode? + if manual_configuration? Gitlab::PrometheusClient.new(RestClient::Resource.new(api_url)) else cluster = find_cluster_with_prometheus(environment_id) + raise Gitlab::PrometheusError, "couldn't find cluster with Prometheus installed" unless cluster - Gitlab::PrometheusClient.new(cluster.application_prometheus.proxy_client) if cluster + Gitlab::PrometheusClient.new(cluster.application_prometheus.proxy_client) end end @@ -125,4 +141,8 @@ class PrometheusService < MonitoringService metrics[:metrics] = metrics.delete :data metrics end + + def synchronize_service_state! + self.active = manual_configuration + end end -- cgit v1.2.1