Commit 7cfd6dac authored by Michael Kozono's avatar Michael Kozono

Merge branch 'refactor_prometheus_adapter' into 'master'

Refactor Prometheus Adapter to take in cluster

See merge request gitlab-org/gitlab!22191
parents db75883a bb353382
......@@ -23,7 +23,7 @@ module Projects
private
def prometheus_adapter
@prometheus_adapter ||= ::Prometheus::AdapterService.new(project).prometheus_adapter
@prometheus_adapter ||= ::Prometheus::AdapterService.new(project, project.deployment_platform&.cluster).prometheus_adapter
end
def require_prometheus_metrics!
......
......@@ -223,7 +223,7 @@ class Environment < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass
def prometheus_adapter
@prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform).prometheus_adapter
@prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform&.cluster).prometheus_adapter
end
# rubocop: enable CodeReuse/ServiceClass
......
......@@ -2,18 +2,13 @@
module Prometheus
class AdapterService
def initialize(project, deployment_platform = nil)
@project = project
attr_reader :project, :cluster
@deployment_platform = if deployment_platform
deployment_platform
else
project.deployment_platform
end
def initialize(project, cluster)
@project = project
@cluster = cluster
end
attr_reader :deployment_platform, :project
def prometheus_adapter
@prometheus_adapter ||= if service_prometheus_adapter.can_query?
service_prometheus_adapter
......@@ -27,7 +22,7 @@ module Prometheus
end
def cluster_prometheus_adapter
application = deployment_platform&.cluster&.application_prometheus
application = cluster&.application_prometheus
application if application&.available?
end
......
......@@ -81,7 +81,7 @@ module EE
end
def cluster_prometheus_adapter
@cluster_prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform).cluster_prometheus_adapter
@cluster_prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform&.cluster).cluster_prometheus_adapter
end
def protected?
......
......@@ -3,13 +3,12 @@
require 'spec_helper'
describe Prometheus::AdapterService do
let(:project) { create(:project) }
let_it_be(:project) { create(:project) }
let_it_be(:cluster, reload: true) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) }
subject { described_class.new(project) }
subject { described_class.new(project, cluster) }
describe '#prometheus_adapter' do
let(:cluster) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) }
context 'prometheus service can execute queries' do
let(:prometheus_service) { double(:prometheus_service, can_query?: true) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment