Commit c873783c authored by Sean Arnold's avatar Sean Arnold

Schedule update for prometheus after alert creation

parent 0813a73d
......@@ -33,6 +33,7 @@ module Prometheus
return ServiceResponse.error(message: 'Invalid environment') unless environment
create_alerts
schedule_prometheus_update
ServiceResponse.success
end
......@@ -51,6 +52,13 @@ module Prometheus
end
end
def schedule_prometheus_update
project.all_clusters.with_application_prometheus.each do |cluster|
application = cluster.application_prometheus
::Clusters::Applications::ScheduleUpdateService.new(application, project).execute
end
end
def metrics_by_identifier
strong_memoize(:metrics_by_identifier) do
metric_identifiers = DEFAULT_ALERTS.map { |alert| alert[:identifier] }
......
......@@ -86,6 +86,10 @@ FactoryBot.define do
application_helm factory: %i(clusters_applications_helm installed)
end
trait :with_installed_prometheus do
application_prometheus factory: %i(clusters_applications_prometheus installed)
end
trait :with_all_applications do
application_helm factory: %i(clusters_applications_helm installed)
application_ingress factory: %i(clusters_applications_ingress installed)
......
......@@ -45,6 +45,27 @@ describe Prometheus::CreateDefaultAlertsService do
.by(expected_alerts.size)
end
it 'does not schedule an update to prometheus' do
expect(::Clusters::Applications::ScheduleUpdateService).not_to receive(:new)
execute
end
context 'cluster with prometheus exists' do
let!(:cluster) do
cluster = create(:cluster, :with_installed_prometheus)
cluster.projects << project
cluster
end
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
context 'multiple environments' do
let!(:production) { create(:environment, project: project, name: 'production') }
......
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