Commit d0593ee6 authored by Vitali Tatarintev's avatar Vitali Tatarintev Committed by Shinya Maeda

Change alert severity sort order

Change `AlertManagement::Alert` severity sort order:

* Ascending sort order sorts severity from less critical to critical.
* Descending sort order sorts severity from critical to less critical.
parent 81be8aed
...@@ -16,10 +16,10 @@ module Types ...@@ -16,10 +16,10 @@ module Types
value 'UPDATED_TIME_DESC', 'Created time by descending order', value: :updated_at_desc value 'UPDATED_TIME_DESC', 'Created time by descending order', value: :updated_at_desc
value 'EVENT_COUNT_ASC', 'Events count by ascending order', value: :event_count_asc value 'EVENT_COUNT_ASC', 'Events count by ascending order', value: :event_count_asc
value 'EVENT_COUNT_DESC', 'Events count by descending order', value: :event_count_desc value 'EVENT_COUNT_DESC', 'Events count by descending order', value: :event_count_desc
value 'SEVERITY_ASC', 'Severity by ascending order', value: :severity_asc value 'SEVERITY_ASC', 'Severity from less critical to more critical', value: :severity_asc
value 'SEVERITY_DESC', 'Severity by descending order', value: :severity_desc value 'SEVERITY_DESC', 'Severity from more critical to less critical', value: :severity_desc
value 'STATUS_ASC', 'Status by ascending order', value: :status_asc value 'STATUS_ASC', 'Status by order: Ignored > Resolved > Acknowledged > Triggered', value: :status_asc
value 'STATUS_DESC', 'Status by descending order', value: :status_desc value 'STATUS_DESC', 'Status by order: Triggered > Acknowledged > Resolved > Ignored', value: :status_desc
end end
end end
end end
...@@ -118,8 +118,16 @@ module AlertManagement ...@@ -118,8 +118,16 @@ module AlertManagement
scope :order_start_time, -> (sort_order) { order(started_at: sort_order) } scope :order_start_time, -> (sort_order) { order(started_at: sort_order) }
scope :order_end_time, -> (sort_order) { order(ended_at: sort_order) } scope :order_end_time, -> (sort_order) { order(ended_at: sort_order) }
scope :order_event_count, -> (sort_order) { order(events: sort_order) } scope :order_event_count, -> (sort_order) { order(events: sort_order) }
scope :order_severity, -> (sort_order) { order(severity: sort_order) }
scope :order_status, -> (sort_order) { order(status: sort_order) } # Ascending sort order sorts severity from less critical to more critical.
# Descending sort order sorts severity from more critical to less critical.
# https://gitlab.com/gitlab-org/gitlab/-/issues/221242#what-is-the-expected-correct-behavior
scope :order_severity, -> (sort_order) { order(severity: sort_order == :asc ? :desc : :asc) }
# Ascending sort order sorts statuses: Ignored > Resolved > Acknowledged > Triggered
# Descending sort order sorts statuses: Triggered > Acknowledged > Resolved > Ignored
# https://gitlab.com/gitlab-org/gitlab/-/issues/221242#what-is-the-expected-correct-behavior
scope :order_status, -> (sort_order) { order(status: sort_order == :asc ? :desc : :asc) }
scope :counts_by_status, -> { group(:status).count } scope :counts_by_status, -> { group(:status).count }
......
---
title: Change the sort order for alert severity and status.
merge_request: 35774
author:
type: fixed
...@@ -395,12 +395,12 @@ enum AlertManagementAlertSort { ...@@ -395,12 +395,12 @@ enum AlertManagementAlertSort {
EVENT_COUNT_DESC EVENT_COUNT_DESC
""" """
Severity by ascending order Severity from less critical to more critical
""" """
SEVERITY_ASC SEVERITY_ASC
""" """
Severity by descending order Severity from more critical to less critical
""" """
SEVERITY_DESC SEVERITY_DESC
...@@ -415,12 +415,12 @@ enum AlertManagementAlertSort { ...@@ -415,12 +415,12 @@ enum AlertManagementAlertSort {
STARTED_AT_DESC STARTED_AT_DESC
""" """
Status by ascending order Status by order: Ignored > Resolved > Acknowledged > Triggered
""" """
STATUS_ASC STATUS_ASC
""" """
Status by descending order Status by order: Triggered > Acknowledged > Resolved > Ignored
""" """
STATUS_DESC STATUS_DESC
......
...@@ -1103,25 +1103,25 @@ ...@@ -1103,25 +1103,25 @@
}, },
{ {
"name": "SEVERITY_ASC", "name": "SEVERITY_ASC",
"description": "Severity by ascending order", "description": "Severity from less critical to more critical",
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "SEVERITY_DESC", "name": "SEVERITY_DESC",
"description": "Severity by descending order", "description": "Severity from more critical to less critical",
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "STATUS_ASC", "name": "STATUS_ASC",
"description": "Status by ascending order", "description": "Status by order: Ignored > Resolved > Acknowledged > Triggered",
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "STATUS_DESC", "name": "STATUS_DESC",
"description": "Status by descending order", "description": "Status by order: Triggered > Acknowledged > Resolved > Ignored",
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
} }
...@@ -75,10 +75,30 @@ FactoryBot.define do ...@@ -75,10 +75,30 @@ FactoryBot.define do
without_ended_at without_ended_at
end end
trait :low_severity do trait :critical do
severity { 'critical' }
end
trait :high do
severity { 'high' }
end
trait :medium do
severity { 'medium' }
end
trait :low do
severity { 'low' } severity { 'low' }
end end
trait :info do
severity { 'info' }
end
trait :unknown do
severity { 'unknown' }
end
trait :prometheus do trait :prometheus do
monitoring_tool { Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] } monitoring_tool { Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] }
end end
...@@ -91,7 +111,7 @@ FactoryBot.define do ...@@ -91,7 +111,7 @@ FactoryBot.define do
with_monitoring_tool with_monitoring_tool
with_host with_host
with_description with_description
low_severity low
end end
end end
end end
...@@ -11,7 +11,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do ...@@ -11,7 +11,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
let(:params) { {} } let(:params) { {} }
describe '#execute' do describe '#execute' do
subject { described_class.new(current_user, project, params).execute } subject(:execute) { described_class.new(current_user, project, params).execute }
context 'user is not a developer or above' do context 'user is not a developer or above' do
it { is_expected.to be_empty } it { is_expected.to be_empty }
...@@ -144,81 +144,55 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do ...@@ -144,81 +144,55 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
end end
context 'when sorting by severity' do context 'when sorting by severity' do
let_it_be(:alert_critical) { create(:alert_management_alert, project: project, severity: :critical) } let_it_be(:alert_critical) { create(:alert_management_alert, :critical, project: project) }
let_it_be(:alert_high) { create(:alert_management_alert, project: project, severity: :high) } let_it_be(:alert_high) { create(:alert_management_alert, :high, project: project) }
let_it_be(:alert_medium) { create(:alert_management_alert, project: project, severity: :medium) } let_it_be(:alert_medium) { create(:alert_management_alert, :medium, project: project) }
let_it_be(:alert_low) { create(:alert_management_alert, project: project, severity: :low) } let_it_be(:alert_low) { create(:alert_management_alert, :low, project: project) }
let_it_be(:alert_info) { create(:alert_management_alert, project: project, severity: :info) } let_it_be(:alert_info) { create(:alert_management_alert, :info, project: project) }
let_it_be(:alert_unknown) { create(:alert_management_alert, project: project, severity: :unknown) } let_it_be(:alert_unknown) { create(:alert_management_alert, :unknown, project: project) }
context 'sorts alerts ascending' do context 'with ascending sort order' do
let(:params) { { sort: 'severity_asc' } } let(:params) { { sort: 'severity_asc' } }
it do it 'sorts alerts by severity from less critical to more critical' do
is_expected.to eq [ expect(execute.pluck(:severity).uniq).to eq(%w(unknown info low medium high critical))
alert_2,
alert_critical,
alert_1,
alert_high,
alert_medium,
alert_low,
alert_info,
alert_unknown
]
end end
end end
context 'sorts alerts descending' do context 'with descending sort order' do
let(:params) { { sort: 'severity_desc' } } let(:params) { { sort: 'severity_desc' } }
it do it 'sorts alerts by severity from more critical to less critical' do
is_expected.to eq [ expect(execute.pluck(:severity).uniq).to eq(%w(critical high medium low info unknown))
alert_unknown,
alert_info,
alert_low,
alert_medium,
alert_1,
alert_high,
alert_critical,
alert_2
]
end end
end end
end end
context 'when sorting by status' do context 'when sorting by status' do
let(:statuses) { AlertManagement::Alert::STATUSES }
let(:triggered) { statuses[:triggered] }
let(:acknowledged) { statuses[:acknowledged] }
let(:resolved) { statuses[:resolved] }
let(:ignored) { statuses[:ignored] }
let_it_be(:alert_triggered) { create(:alert_management_alert, project: project) } let_it_be(:alert_triggered) { create(:alert_management_alert, project: project) }
let_it_be(:alert_acknowledged) { create(:alert_management_alert, :acknowledged, project: project) } let_it_be(:alert_acknowledged) { create(:alert_management_alert, :acknowledged, project: project) }
let_it_be(:alert_resolved) { create(:alert_management_alert, :resolved, project: project) } let_it_be(:alert_resolved) { create(:alert_management_alert, :resolved, project: project) }
let_it_be(:alert_ignored) { create(:alert_management_alert, :ignored, project: project) } let_it_be(:alert_ignored) { create(:alert_management_alert, :ignored, project: project) }
context 'sorts alerts ascending' do context 'with ascending sort order' do
let(:params) { { sort: 'status_asc' } } let(:params) { { sort: 'status_asc' } }
it do it 'sorts by status: Ignored > Resolved > Acknowledged > Triggered' do
is_expected.to eq [ expect(execute.map(&:status).uniq).to eq([ignored, resolved, acknowledged, triggered])
alert_triggered,
alert_acknowledged,
alert_1,
alert_resolved,
alert_2,
alert_ignored
]
end end
end end
context 'sorts alerts descending' do context 'with descending sort order' do
let(:params) { { sort: 'status_desc' } } let(:params) { { sort: 'status_desc' } }
it do it 'sorts by status: Triggered > Acknowledged > Resolved > Ignored' do
is_expected.to eq [ expect(execute.map(&:status).uniq).to eq([triggered, acknowledged, resolved, ignored])
alert_2,
alert_ignored,
alert_1,
alert_resolved,
alert_acknowledged,
alert_triggered
]
end end
end end
end end
......
...@@ -110,14 +110,14 @@ RSpec.describe 'getting Alert Management Alerts' do ...@@ -110,14 +110,14 @@ RSpec.describe 'getting Alert Management Alerts' do
it_behaves_like 'a working graphql query' it_behaves_like 'a working graphql query'
it 'sorts in the correct order' do it 'sorts in the correct order' do
expect(iids).to eq [resolved_alert.iid.to_s, triggered_alert.iid.to_s] expect(iids).to eq [triggered_alert.iid.to_s, resolved_alert.iid.to_s]
end end
context 'ascending order' do context 'ascending order' do
let(:params) { 'sort: SEVERITY_ASC' } let(:params) { 'sort: SEVERITY_ASC' }
it 'sorts in the correct order' do it 'sorts in the correct order' do
expect(iids).to eq [triggered_alert.iid.to_s, resolved_alert.iid.to_s] expect(iids).to eq [resolved_alert.iid.to_s, triggered_alert.iid.to_s]
end 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