summaryrefslogtreecommitdiff
path: root/app/services/prometheus
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-03-05 19:34:59 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2018-03-05 19:34:59 +0100
commit5ceec83a0154e513480a9bb08e252371bf7886c6 (patch)
tree9a193e295c56feb2c29ac042b59b14b1808715d1 /app/services/prometheus
parent273e4142566a053e0628183fbf86ef7b94cb5a66 (diff)
downloadgitlab-ce-5ceec83a0154e513480a9bb08e252371bf7886c6.tar.gz
Implemente Prometheus:AdapterService
Diffstat (limited to 'app/services/prometheus')
-rw-r--r--app/services/prometheus/adapter_service.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/services/prometheus/adapter_service.rb b/app/services/prometheus/adapter_service.rb
new file mode 100644
index 00000000000..4504d2ccfe6
--- /dev/null
+++ b/app/services/prometheus/adapter_service.rb
@@ -0,0 +1,36 @@
+module Prometheus
+ class AdapterService
+ def initialize(project, deployment_platform = nil)
+ @project = project
+
+ @deployment_platform = if deployment_platform
+ deployment_platform
+ else
+ project.deployment_platform
+ end
+ end
+
+ attr_reader :deployment_platform, :project
+
+ 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
+end