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
:issues_events,
:issues_url,
:jira_issue_transition_id,
:manual_configuration,
:merge_requests_events,
:mock_service_url,
:namespace,
......
......@@ -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
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