Commit 8cc3dc10 authored by Sean Arnold's avatar Sean Arnold

Access prometheus via cluster_prometheus_adapter

- Update specs
- Delete unnecessary code
parent d7e6a633
......@@ -136,7 +136,6 @@ module Clusters
conditions = { projects: { alerts_service: [:data] } }
includes(conditions).joins(conditions).where(projects: { id: project_ids })
end
scope :with_deployment_in_environment, -> (environment) { joins(:deployments).merge(Deployment.for_environment(environment)) }
def self.ancestor_clusters_for_clusterable(clusterable, hierarchy_order: :asc)
return [] if clusterable.is_a?(Instance)
......
......@@ -53,14 +53,13 @@ module Prometheus
end
def schedule_prometheus_update
clusters = project.all_clusters
clusters = clusters.with_application_prometheus
clusters = clusters.with_deployment_in_environment(environment)
return unless prometheus_application
clusters.each do |cluster|
application = cluster.application_prometheus
::Clusters::Applications::ScheduleUpdateService.new(application, project).execute
end
::Clusters::Applications::ScheduleUpdateService.new(prometheus_application, project).execute
end
def prometheus_application
environment.cluster_prometheus_adapter
end
def metrics_by_identifier
......
......@@ -207,24 +207,6 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end
end
describe '.with_project_alert_service_data' do
subject { described_class.with_deployment_in_environment(environment) }
let(:project) { create(:project, :repository) }
let!(:cluster) { create(:cluster, projects: [project]) }
let!(:environment) { create(:environment) }
context 'deployment in environment' do
let!(:deployment) { create(:deployment, cluster: cluster, environment: environment, sha: cluster.project.commit.id) }
it { is_expected.to include(cluster) }
end
context 'no deployment in environment' do
it { is_expected.not_to include(cluster) }
end
end
describe '.for_project_namespace' do
subject { described_class.for_project_namespace(namespace_id) }
......
......@@ -51,23 +51,14 @@ describe Prometheus::CreateDefaultAlertsService do
end
context 'cluster with prometheus exists' do
let!(:cluster) { create(:cluster, :with_installed_prometheus, projects: [project]) }
let!(:cluster) { create(:cluster, :with_installed_prometheus, :provided_by_user, projects: [project]) }
it 'does not schedule an update to prometheus' do
expect(::Clusters::Applications::ScheduleUpdateService).not_to receive(:new)
execute
end
context 'deployment to relevant environment' do
let!(:deployment) { create(:deployment, cluster: cluster, environment: environment, sha: project.commit.id) }
it 'schedules an update to prometheus' do
expect_next_instance_of(::Clusters::Applications::ScheduleUpdateService) do |instance|
expect(instance).to receive(:execute)
end
execute
it 'schedules an update to prometheus' do
expect_next_instance_of(::Clusters::Applications::ScheduleUpdateService) do |instance|
expect(instance).to receive(:execute)
end
execute
end
end
......
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