Commit 3a99cda1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'design-list-of-alert-summary' into 'master'

Change Prometheus Alert issue details list from bulleted to description list

See merge request gitlab-org/gitlab!18116
parents 3e23689a 62a715e4
...@@ -4,6 +4,7 @@ module Projects ...@@ -4,6 +4,7 @@ module Projects
module Prometheus module Prometheus
class AlertPresenter < Gitlab::View::Presenter::Delegated class AlertPresenter < Gitlab::View::Presenter::Delegated
RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown).freeze RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown).freeze
MARKDOWN_LINE_BREAK = " \n".freeze
def full_title def full_title
[environment_name, alert_title].compact.join(': ') [environment_name, alert_title].compact.join(': ')
...@@ -35,10 +36,10 @@ module Projects ...@@ -35,10 +36,10 @@ module Projects
def issue_summary_markdown def issue_summary_markdown
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
## Summary #### Summary
#{metadata_list} #{metadata_list}
#{annotation_list} #{alert_details}
MARKDOWN MARKDOWN
end end
...@@ -57,23 +58,34 @@ module Projects ...@@ -57,23 +58,34 @@ module Projects
def metadata_list def metadata_list
metadata = [] metadata = []
metadata << bullet('starts_at', starts_at) if starts_at metadata << list_item('starts_at', starts_at) if starts_at
metadata << bullet('full_query', backtick(full_query)) if full_query metadata << list_item('full_query', backtick(full_query)) if full_query
metadata.join(MARKDOWN_LINE_BREAK)
end
def alert_details
if annotation_list.present?
<<~MARKDOWN.chomp
metadata.join("\n") #### Alert Details
#{annotation_list}
MARKDOWN
end
end end
def annotation_list def annotation_list
strong_memoize(:annotation_list) do strong_memoize(:annotation_list) do
annotations annotations
.reject { |annotation| RESERVED_ANNOTATIONS.include?(annotation.label) } .reject { |annotation| RESERVED_ANNOTATIONS.include?(annotation.label) }
.map { |annotation| bullet(annotation.label, annotation.value) } .map { |annotation| list_item(annotation.label, annotation.value) }
.join("\n") .join(MARKDOWN_LINE_BREAK)
end end
end end
def bullet(key, value) def list_item(key, value)
"* #{key}: #{value}" "**#{key}:** #{value}".strip
end end
def backtick(value) def backtick(value)
......
---
title: Change Prometheus Alert details list from bulleted to description list
merge_request: 18116
author: Vitali Tatarintev
type: changed
...@@ -41,9 +41,14 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -41,9 +41,14 @@ describe Projects::Prometheus::AlertPresenter do
context 'without default payload' do context 'without default payload' do
it do it do
is_expected.to include('## Summary') is_expected.to eq(
is_expected.to include('* starts_at:') <<~MARKDOWN.chomp
is_expected.not_to include('* full_query:') #### Summary
**starts_at:** #{presenter.starts_at}
MARKDOWN
)
end end
end end
...@@ -53,8 +58,17 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -53,8 +58,17 @@ describe Projects::Prometheus::AlertPresenter do
end end
it do it do
is_expected.to include('* foo: value1') is_expected.to eq(
is_expected.to include('* bar: value2') <<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at}
#### Alert Details
**foo:** value1 \n**bar:** value2
MARKDOWN
)
end end
end end
...@@ -63,7 +77,16 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -63,7 +77,16 @@ describe Projects::Prometheus::AlertPresenter do
payload['generatorURL'] = 'http://host?g0.expr=query' payload['generatorURL'] = 'http://host?g0.expr=query'
end end
it { is_expected.to include('* full_query: `query`') } it do
is_expected.to eq(
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at} \n**full_query:** `query`
MARKDOWN
)
end
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