Commit a515eaaf authored by Stan Hu's avatar Stan Hu

Merge branch '216735-fix-prometheus-alerts-not-being-created' into 'master'

Schedule update for prometheus after alert creation

Closes #216735

See merge request gitlab-org/gitlab!33806
parents 47de0107 8cc3dc10
......@@ -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,16 @@ module Prometheus
end
end
def schedule_prometheus_update
return unless prometheus_application
::Clusters::Applications::ScheduleUpdateService.new(prometheus_application, project).execute
end
def prometheus_application
environment.cluster_prometheus_adapter
end
def metrics_by_identifier
strong_memoize(:metrics_by_identifier) do
metric_identifiers = DEFAULT_ALERTS.map { |alert| alert[:identifier] }
......
---
title: Fix prometheus alerts not being automatically created
merge_request: 33806
author:
type: fixed
......@@ -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)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe Prometheus::CreateDefaultAlertsService do
let_it_be(:project) { create(:project) }
let_it_be(:project) { create(:project, :repository) }
let(:instance) { described_class.new(project: project) }
let(:expected_alerts) { described_class::DEFAULT_ALERTS }
......@@ -45,6 +45,23 @@ 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) { create(:cluster, :with_installed_prometheus, :provided_by_user, projects: [project]) }
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