summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-02 22:40:03 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-02 22:40:03 +0100
commit0c802f4fba67e4fe54f9c4442d280fc7465e6b3f (patch)
tree590f6984cd9cf0b163daf176edc8f4d7dbc4af2b
parentb38b5ceb8e039283e90dd323327e59c8f608c103 (diff)
downloadgitlab-ce-0c802f4fba67e4fe54f9c4442d280fc7465e6b3f.tar.gz
Manual Configuration instead of Activation. Prometheus Service just got a bit weirder
-rw-r--r--app/controllers/concerns/service_params.rb1
-rw-r--r--app/models/project_services/prometheus_service.rb36
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