Commit 41469e6c authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch '9558-alert-notification-not-working-for-managed-prometheus-installations' into 'master'

Resolve "Alert notification not working for managed Prometheus installations"

Closes #9558

See merge request gitlab-org/gitlab-ee!9402
parents 072e9f54 6c98301e
......@@ -3,9 +3,10 @@
module Clusters
module Applications
class PrometheusConfigService
def initialize(project, cluster)
def initialize(project, cluster, app)
@project = project
@cluster = cluster
@app = app
end
def execute(config)
......@@ -18,7 +19,7 @@ module Clusters
private
attr_reader :project, :cluster
attr_reader :project, :cluster, :app
def reset_alert_manager(config)
config = set_alert_manager_enabled(config, false)
......@@ -80,13 +81,22 @@ module Clusters
'webhook_configs' => [
{
'url' => notify_url,
'send_resolved' => true
'send_resolved' => true,
'http_config' => {
'bearer_token' => alert_manager_token
}
}
]
}
]
end
def alert_manager_token
app.generate_alert_manager_token!
app.alert_manager_token
end
def alert_manager_route_params
{
'receiver' => 'gitlab',
......@@ -97,11 +107,8 @@ module Clusters
end
def notify_url
::Gitlab::Routing.url_helpers.notify_namespace_project_prometheus_alerts_url(
namespace_id: project.namespace.path,
project_id: project.path,
format: :json
)
::Gitlab::Routing.url_helpers
.notify_project_prometheus_alerts_url(project, format: :json)
end
def has_alerts?
......
......@@ -34,7 +34,7 @@ module Clusters
def update_config(config)
PrometheusConfigService
.new(project, cluster)
.new(project, cluster, app)
.execute(config)
end
end
......
---
title: Fix alert notifications for managed Prometheus
merge_request: 9402
author:
type: fixed
......@@ -3,11 +3,17 @@
require 'spec_helper'
describe Clusters::Applications::PrometheusConfigService do
include Gitlab::Routing.url_helpers
set(:project) { create(:project) }
set(:production) { create(:environment, project: project) }
set(:cluster) { create(:cluster, :provided_by_user, projects: [project]) }
subject { described_class.new(project, cluster).execute(input) }
let(:application) do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
end
subject { described_class.new(project, cluster, application).execute(input) }
describe '#execute' do
let(:input) do
......@@ -37,7 +43,7 @@ describe Clusters::Applications::PrometheusConfigService do
let(:webhook_config) { receiver.dig('webhook_configs', 0) }
let(:notify_url) do
"http://localhost/#{project.namespace.name}/#{project.name}/prometheus/alerts/notify.json"
notify_project_prometheus_alerts_url(project, format: :json)
end
it 'sets receiver' do
......@@ -47,7 +53,10 @@ describe Clusters::Applications::PrometheusConfigService do
it 'sets webhook_config' do
expect(webhook_config).to eq(
'url' => notify_url,
'send_resolved' => true
'send_resolved' => true,
'http_config' => {
'bearer_token' => application.alert_manager_token
}
)
end
end
......
......@@ -42,7 +42,7 @@ describe Clusters::Applications::PrometheusUpdateService do
expect(Clusters::Applications::PrometheusConfigService)
.to receive(:new)
.with(project, cluster)
.with(project, cluster, application)
.and_return(prometheus_config_service)
expect(prometheus_config_service)
......
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