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
module Prometheus
class AlertPresenter < Gitlab::View::Presenter::Delegated
RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown).freeze
MARKDOWN_LINE_BREAK = " \n".freeze
def full_title
[environment_name, alert_title].compact.join(': ')
......@@ -35,10 +36,10 @@ module Projects
def issue_summary_markdown
<<~MARKDOWN.chomp
## Summary
#### Summary
#{metadata_list}
#{annotation_list}
#{alert_details}
MARKDOWN
end
......@@ -57,23 +58,34 @@ module Projects
def metadata_list
metadata = []
metadata << bullet('starts_at', starts_at) if starts_at
metadata << bullet('full_query', backtick(full_query)) if full_query
metadata << list_item('starts_at', starts_at) if starts_at
metadata << list_item('full_query', backtick(full_query)) if full_query
metadata.join("\n")
metadata.join(MARKDOWN_LINE_BREAK)
end
def alert_details
if annotation_list.present?
<<~MARKDOWN.chomp
#### Alert Details
#{annotation_list}
MARKDOWN
end
end
def annotation_list
strong_memoize(:annotation_list) do
annotations
.reject { |annotation| RESERVED_ANNOTATIONS.include?(annotation.label) }
.map { |annotation| bullet(annotation.label, annotation.value) }
.join("\n")
.map { |annotation| list_item(annotation.label, annotation.value) }
.join(MARKDOWN_LINE_BREAK)
end
end
def bullet(key, value)
"* #{key}: #{value}"
def list_item(key, value)
"**#{key}:** #{value}".strip
end
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
context 'without default payload' do
it do
is_expected.to include('## Summary')
is_expected.to include('* starts_at:')
is_expected.not_to include('* full_query:')
is_expected.to eq(
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at}
MARKDOWN
)
end
end
......@@ -53,8 +58,17 @@ describe Projects::Prometheus::AlertPresenter do
end
it do
is_expected.to include('* foo: value1')
is_expected.to include('* bar: value2')
is_expected.to eq(
<<~MARKDOWN.chomp
#### Summary
**starts_at:** #{presenter.starts_at}
#### Alert Details
**foo:** value1 \n**bar:** value2
MARKDOWN
)
end
end
......@@ -63,7 +77,16 @@ describe Projects::Prometheus::AlertPresenter do
payload['generatorURL'] = 'http://host?g0.expr=query'
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
......
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