2020-01-08 04:07:53 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Prometheus
|
|
|
|
class Adapter
|
|
|
|
attr_reader :project, :cluster
|
|
|
|
|
|
|
|
def initialize(project, cluster)
|
|
|
|
@project = project
|
|
|
|
@cluster = cluster
|
|
|
|
end
|
|
|
|
|
|
|
|
def prometheus_adapter
|
|
|
|
@prometheus_adapter ||= if service_prometheus_adapter.can_query?
|
|
|
|
service_prometheus_adapter
|
|
|
|
else
|
|
|
|
cluster_prometheus_adapter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_prometheus_adapter
|
2021-05-09 20:10:37 -04:00
|
|
|
integration = cluster&.integration_prometheus
|
|
|
|
integration if integration&.available?
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def service_prometheus_adapter
|
2021-06-23 14:07:10 -04:00
|
|
|
project.find_or_initialize_integration('prometheus')
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|