diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2018-01-04 04:45:57 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2018-01-04 04:45:57 +0300 |
commit | 80d4c0675f5715d724be20d47cafa372524e3ed1 (patch) | |
tree | a7eb85470d83f374d2fa013f297fcfeeb0ab135f /app | |
parent | 249c9a8cf63b5b36b86499720804a5180e640537 (diff) |
Add test checking if prometheus integration is enabled after prometheus is installed
Diffstat (limited to 'app')
-rw-r--r-- | app/models/clusters/applications/prometheus.rb | 9 | ||||
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 20 | ||||
-rw-r--r-- | app/views/projects/services/prometheus/_help.html.haml | 10 |
3 files changed, 32 insertions, 7 deletions
diff --git a/app/models/clusters/applications/prometheus.rb b/app/models/clusters/applications/prometheus.rb index 94cac9277a5..ac9ea707f62 100644 --- a/app/models/clusters/applications/prometheus.rb +++ b/app/models/clusters/applications/prometheus.rb @@ -10,6 +10,15 @@ module Clusters default_value_for :version, VERSION + state_machine :status do + after_transition any => [:installed] do |application| + application.cluster.projects.each do |project| + # raise "exe" + project.prometheus_service&.update(active: true) + end + end + end + def chart 'stable/prometheus' end diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb index abd2be2e7fe..2fb94c1facb 100644 --- a/app/models/project_services/prometheus_service.rb +++ b/app/models/project_services/prometheus_service.rb @@ -1,3 +1,7 @@ +module Gitlab + PrometheusError = Class.new(StandardError) +end + class PrometheusService < MonitoringService include ReactiveService @@ -8,7 +12,6 @@ class PrometheusService < MonitoringService # Access to prometheus is directly through the API prop_accessor :api_url boolean_accessor :manual_configuration - boolean_accessor :prometheus_installed with_options presence: true, if: :manual_configuration? do validates :api_url, url: true @@ -18,10 +21,9 @@ class PrometheusService < MonitoringService after_save :clear_reactive_cache! - def initialize_properties if properties.nil? - self.properties = { prometheus_installed: false } + self.properties = { } end end @@ -54,7 +56,6 @@ class PrometheusService < MonitoringService } ] }, - { type: 'text', name: 'api_url', @@ -126,6 +127,10 @@ class PrometheusService < MonitoringService end end + def prometheus_installed? + cluster_with_prometheus.present? + end + private def cluster_with_prometheus(environment_id = nil) @@ -135,7 +140,7 @@ class PrometheusService < MonitoringService project.clusters.enabled.select { |c| c.environment_scope == '*' || c.environment_scope == '' } end - clusters.detect { |cluster| cluster.application_prometheus.installed? } + clusters.detect { |cluster| cluster.application_prometheus&.installed? } end def rename_data_to_metrics(metrics) @@ -144,7 +149,8 @@ class PrometheusService < MonitoringService end def synchronize_service_state! - self.active = prometheus_installed? || manual_configuration? || cluster_with_prometheus.present? - self.prometheus_installed = !manual_configuration? && cluster_with_prometheus.present? + self.active = prometheus_installed? || self.manual_configuration? + + true end end diff --git a/app/views/projects/services/prometheus/_help.html.haml b/app/views/projects/services/prometheus/_help.html.haml new file mode 100644 index 00000000000..96a194b212e --- /dev/null +++ b/app/views/projects/services/prometheus/_help.html.haml @@ -0,0 +1,10 @@ +.row.prepend-top-default.append-bottom-default + %p + - unless @service.manual_configuration? + - if @service.prometheus_installed? + = link_to 'Manage installed Prometheus', project_clusters_path(@project), class: 'btn btn-cancel' + - else + = link_to 'Install Prometheus', project_clusters_path(@project), class: 'btn btn-cancel' + - else + To automatically install prometheus disable manual configuration + |