Commit 0c802f4f authored by Pawel Chojnacki's avatar Pawel Chojnacki

Manual Configuration instead of Activation. Prometheus Service just got a bit weirder

parent b38b5ceb
...@@ -32,6 +32,7 @@ module ServiceParams ...@@ -32,6 +32,7 @@ module ServiceParams
:issues_events, :issues_events,
:issues_url, :issues_url,
:jira_issue_transition_id, :jira_issue_transition_id,
:manual_configuration,
:merge_requests_events, :merge_requests_events,
:mock_service_url, :mock_service_url,
:namespace, :namespace,
......
...@@ -7,19 +7,27 @@ class PrometheusService < MonitoringService ...@@ -7,19 +7,27 @@ class PrometheusService < MonitoringService
# Access to prometheus is directly through the API # Access to prometheus is directly through the API
prop_accessor :api_url 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 validates :api_url, url: true
end end
before_save :synchronize_service_state!
after_save :clear_reactive_cache! after_save :clear_reactive_cache!
def initialize_properties def initialize_properties
if properties.nil? if properties.nil?
self.properties = {} self.properties = {}
end end
end end
def show_active_box?
false
end
def title def title
'Prometheus' 'Prometheus'
end end
...@@ -34,6 +42,18 @@ class PrometheusService < MonitoringService ...@@ -34,6 +42,18 @@ class PrometheusService < MonitoringService
def fields def fields
[ [
{ type: 'fieldset',
legend: 'Manual Configuration',
fields: [
{
type: 'checkbox',
name: 'manual_configuration',
title: s_('PrometheusService|Active'),
required: true
}
]
},
{ {
type: 'text', type: 'text',
name: 'api_url', name: 'api_url',
...@@ -79,16 +99,11 @@ class PrometheusService < MonitoringService ...@@ -79,16 +99,11 @@ class PrometheusService < MonitoringService
with_reactive_cache(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, nil, &:itself) with_reactive_cache(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, nil, &:itself)
end end
def manual_mode?
false
end
# Cache metrics for specific environment # Cache metrics for specific environment
def calculate_reactive_cache(query_class_name, environment_id, *args) def calculate_reactive_cache(query_class_name, environment_id, *args)
return unless active? && project && !project.pending_delete? return unless active? && project && !project.pending_delete?
client = client(environment_id) client = client(environment_id)
data = Kernel.const_get(query_class_name).new(client).query(environment_id, *args) data = Kernel.const_get(query_class_name).new(client).query(environment_id, *args)
{ {
success: true, success: true,
...@@ -100,12 +115,13 @@ class PrometheusService < MonitoringService ...@@ -100,12 +115,13 @@ class PrometheusService < MonitoringService
end end
def client(environment_id) def client(environment_id)
if manual_mode? if manual_configuration?
Gitlab::PrometheusClient.new(RestClient::Resource.new(api_url)) Gitlab::PrometheusClient.new(RestClient::Resource.new(api_url))
else else
cluster = find_cluster_with_prometheus(environment_id) 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
end end
...@@ -125,4 +141,8 @@ class PrometheusService < MonitoringService ...@@ -125,4 +141,8 @@ class PrometheusService < MonitoringService
metrics[:metrics] = metrics.delete :data metrics[:metrics] = metrics.delete :data
metrics metrics
end end
def synchronize_service_state!
self.active = manual_configuration
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment