2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
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
|
2019-07-07 11:18:12 +05:30
|
|
|
return unless cluster.application_prometheus&.available?
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
cluster.application_prometheus
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|