summaryrefslogtreecommitdiff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-03-01 18:14:54 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2018-03-01 18:33:49 +0100
commit8ad9cd5581dafeb7a24da7ed119a30761a0a72fe (patch)
tree8a9796c20ca958738ba74ec008383dc5fc787a18 /app/models/concerns
parent2c090539f2dbdbc11c18598c7952a5de497047ea (diff)
downloadgitlab-ce-8ad9cd5581dafeb7a24da7ed119a30761a0a72fe.tar.gz
Implement PrometheusDeploymentLocator + fix metrics controller
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/prometheus_adapter_locator.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/concerns/prometheus_adapter_locator.rb b/app/models/concerns/prometheus_adapter_locator.rb
new file mode 100644
index 00000000000..f301eab5c57
--- /dev/null
+++ b/app/models/concerns/prometheus_adapter_locator.rb
@@ -0,0 +1,26 @@
+module PrometheusAdapterLocator
+ def deployment_platform
+ project.deployment_platform
+ end
+
+ def prometheus_adapter
+ @prometheus_adapter ||= if service_prometheus_adapter.can_query?
+ service_prometheus_adapter
+ else
+ cluster_prometheus_adapter
+ end
+ end
+
+ def service_prometheus_adapter
+ project.find_or_initialize_service('prometheus')
+ end
+
+ def cluster_prometheus_adapter
+ return unless deployment_platform.respond_to?(:cluster)
+
+ cluster = deployment_platform.cluster
+ return unless cluster.application_prometheus&.installed?
+
+ cluster.application_prometheus
+ end
+end \ No newline at end of file