Commit 2b607f09 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'split-summary-and-alert-details-params' into 'master'

Split summary and alert details params

Closes #31883

See merge request gitlab-org/gitlab!18261
parents 554414f5 bf85c3f7
......@@ -4,6 +4,7 @@ module Projects
module Prometheus
class AlertPresenter < Gitlab::View::Presenter::Delegated
RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown).freeze
GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze
MARKDOWN_LINE_BREAK = " \n".freeze
def full_title
......@@ -58,8 +59,11 @@ module Projects
def metadata_list
metadata = []
metadata << list_item('starts_at', starts_at) if starts_at
metadata << list_item('Start time', starts_at) if starts_at
metadata << list_item('full_query', backtick(full_query)) if full_query
metadata << list_item(service.label.humanize, service.value) if service
metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool
metadata << list_item(hosts.label.humanize, host_links) if hosts
metadata.join(MARKDOWN_LINE_BREAK)
end
......@@ -78,7 +82,7 @@ module Projects
def annotation_list
strong_memoize(:annotation_list) do
annotations
.reject { |annotation| RESERVED_ANNOTATIONS.include?(annotation.label) }
.reject { |annotation| annotation.label.in?(RESERVED_ANNOTATIONS | GENERIC_ALERT_SUMMARY_ANNOTATIONS) }
.map { |annotation| list_item(annotation.label, annotation.value) }
.join(MARKDOWN_LINE_BREAK)
end
......@@ -91,6 +95,16 @@ module Projects
def backtick(value)
"`#{value}`"
end
GENERIC_ALERT_SUMMARY_ANNOTATIONS.each do |annotation_name|
define_method(annotation_name) do
annotations.find { |a| a.label == annotation_name }
end
end
def host_links
Array(hosts.value).join(' ')
end
end
end
end
......@@ -37,6 +37,8 @@ describe Projects::Prometheus::AlertPresenter do
end
describe '#issue_summary_markdown' do
let(:markdown_line_break) { ' ' }
subject { presenter.issue_summary_markdown }
context 'without default payload' do
......@@ -45,7 +47,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at}
**Start time:** #{presenter.starts_at}
MARKDOWN
)
......@@ -62,11 +64,12 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at}
**Start time:** #{presenter.starts_at}
#### Alert Details
**foo:** value1 \n**bar:** value2
**foo:** value1#{markdown_line_break}
**bar:** value2
MARKDOWN
)
end
......@@ -82,11 +85,64 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at} \n**full_query:** `query`
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**full_query:** `query`
MARKDOWN
)
end
end
context 'with the Generic Alert parameters' do
let(:generic_alert_params) do
{
'title' => 'The Generic Alert Title',
'description' => 'The Generic Alert Description',
'monitoring_tool' => 'monitoring_tool_name',
'service' => 'service_name',
'hosts' => ['http://localhost:3000', 'http://localhost:3001']
}
end
before do
payload['annotations'] = generic_alert_params
end
it do
is_expected.to eq(
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Service:** service_name#{markdown_line_break}
**Monitoring tool:** monitoring_tool_name#{markdown_line_break}
**Hosts:** http://localhost:3000 http://localhost:3001
#### Alert Details
**title:** The Generic Alert Title#{markdown_line_break}
**description:** The Generic Alert Description
MARKDOWN
)
end
context 'when hosts is a string' do
before do
payload['annotations'] = { 'hosts' => 'http://localhost:3000' }
end
it do
is_expected.to eq(
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Hosts:** http://localhost:3000
MARKDOWN
)
end
end
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