Commit 1f54acd9 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'ck3g-pass-alert-fields-data-to-frontend' into 'master'

Pass the custom mapping fields to frontend

See merge request gitlab-org/gitlab!51982
parents bbbc36c0 120fa9d9
......@@ -6,18 +6,9 @@ module Types
graphql_name 'AlertManagementPayloadAlertFieldName'
description 'Values for alert field names used in the custom mapping'
# The complete list of fields can be found in:
# https://docs.gitlab.com/ee/operations/incident_management/alert_integrations.html#customize-the-alert-payload-outside-of-gitlab
value 'TITLE', 'The title of the incident.', value: 'title'
value 'DESCRIPTION', 'A high-level summary of the problem.', value: 'description'
value 'START_TIME', 'The time of the incident.', value: 'start_time'
value 'END_TIME', 'The resolved time of the incident.', value: 'end_time'
value 'SERVICE', 'The affected service.', value: 'service'
value 'MONITORING_TOOL', 'The name of the associated monitoring tool.', value: 'monitoring_tool'
value 'HOSTS', 'One or more hosts, as to where this incident occurred.', value: 'hosts'
value 'SEVERITY', 'The severity of the alert.', value: 'severity'
value 'FINGERPRINT', 'The unique identifier of the alert. This can be used to group occurrences of the same alert.', value: 'fingerprint'
value 'GITLAB_ENVIRONMENT_NAME', 'The name of the associated GitLab environment.', value: 'gitlab_environment_name'
::Gitlab::AlertManagement.alert_fields.each do |field|
value field[:name].upcase, field[:description], value: field[:name]
end
end
end
end
......@@ -37,7 +37,7 @@ module EE
override :alerts_settings_data
def alerts_settings_data(disabled: false)
super.merge(alert_management_multiple_integrations_data)
super.merge(alert_management_multiple_integrations_data, alert_fields)
end
override :operations_settings_data
......@@ -66,5 +66,13 @@ module EE
'multi_integrations' => @project.feature_available?(:multiple_alert_http_integrations).to_s
}
end
def alert_fields
return {} unless ::Gitlab::AlertManagement.custom_mapping_available?(@project)
{
'alert_fields' => ::Gitlab::AlertManagement.alert_fields.map { |f| f.slice(:name, :label, :types) }.to_json
}
end
end
end
......@@ -6,5 +6,74 @@ module Gitlab
::Feature.enabled?(:multiple_http_integrations_custom_mapping, project) &&
project.feature_available?(:multiple_alert_http_integrations)
end
# Returns the complete list of alert fields for the custom mapping to be consumed by the frontend and the GraphQL API.
#
# @see https://docs.gitlab.com/ee/operations/incident_management/alert_integrations.html#customize-the-alert-payload-outside-of-gitlab
# @return [Array<Hash>]
def self.alert_fields
[
{
name: 'title',
label: 'Title',
description: 'The title of the incident.',
types: %w[string]
},
{
name: 'description',
label: 'Description',
description: 'A high-level summary of the problem.',
types: %w[string]
},
{
name: 'start_time',
label: 'Start time',
description: 'The time of the incident.',
types: %w[datetime]
},
{
name: 'end_time',
label: 'End time',
description: 'The resolved time of the incident.',
types: %w[datetime]
},
{
name: 'service',
label: 'Service',
description: 'The affected service.',
types: %w[string]
},
{
name: 'monitoring_tool',
label: 'Monitoring tool',
description: 'The name of the associated monitoring tool.',
types: %w[string]
},
{
name: 'hosts',
label: 'Hosts',
description: 'One or more hosts, as to where this incident occurred.',
types: %w[string array]
},
{
name: 'severity',
label: 'Severity',
description: 'The severity of the alert.',
types: %w[string]
},
{
name: 'fingerprint',
label: 'Fingerprint',
description: 'The unique identifier of the alert. This can be used to group occurrences of the same alert.',
types: %w[string array]
},
{
name: 'gitlab_environment_name',
label: 'Environment',
description: 'The name of the associated GitLab environment.',
types: %w[string]
}
]
end
end
end
......@@ -73,7 +73,7 @@ RSpec.describe OperationsHelper, :routing do
end
describe '#alerts_settings_data' do
subject { helper.alerts_settings_data }
subject(:alerts_settings_data) { helper.alerts_settings_data }
describe 'Multiple Integrations Support' do
before do
......@@ -84,12 +84,37 @@ RSpec.describe OperationsHelper, :routing do
let(:multi_integrations) { true }
it { is_expected.to include('multi_integrations' => 'true') }
context 'with multiple_http_integrations_custom_mapping feature flag enabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: true)
end
it 'has the correct list of fields', :aggregate_failures do
fields = Gitlab::Json.parse(alerts_settings_data['alert_fields'])
expect(fields.count).to eq(10)
expect(fields.first.keys).to eq(%w[name label types])
expect(fields.map { |f| f['name'] }).to match_array(
%w[title description start_time end_time service monitoring_tool hosts severity fingerprint gitlab_environment_name]
)
end
end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it { is_expected.not_to have_key('alert_fields') }
end
end
context 'when not available' do
let(:multi_integrations) { false }
it { is_expected.to include('multi_integrations' => 'false') }
it { is_expected.not_to have_key('alert_fields') }
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