Commit 545f89c0 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add payloadAlertFields to HttpIntegration response

Now a `alertManagementHttpIntegrations` GraphQL query returns
`payloadAlertFields` calculated from the persisted `payload_example`.
parent 8155ccf4
......@@ -634,6 +634,11 @@ type AlertManagementHttpIntegration implements AlertManagementIntegration {
"""
name: String
"""
Extract alert fields from payload example for custom mapping.
"""
payloadAlertFields: [AlertManagementPayloadAlertField!]
"""
The custom mapping of GitLab alert attributes to fields from the payload_example.
"""
......
......@@ -1578,6 +1578,28 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "payloadAlertFields",
"description": "Extract alert fields from payload example for custom mapping.",
"args": [
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "AlertManagementPayloadAlertField",
"ofType": null
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "payloadAttributeMappings",
"description": "The custom mapping of GitLab alert attributes to fields from the payload_example.",
......@@ -274,6 +274,7 @@ An endpoint and credentials used to accept alerts for a project.
| `apiUrl` | String | URL at which Prometheus metrics can be queried to populate the metrics dashboard. |
| `id` | ID! | ID of the integration. |
| `name` | String | Name of the integration. |
| `payloadAlertFields` | AlertManagementPayloadAlertField! => Array | Extract alert fields from payload example for custom mapping. |
| `payloadAttributeMappings` | AlertManagementPayloadAlertMappingField! => Array | The custom mapping of GitLab alert attributes to fields from the payload_example. |
| `payloadExample` | JsonString | The example of an alert payload. |
| `token` | String | Token used to authenticate alert notification requests. |
......
......@@ -15,6 +15,11 @@ module EE
null: true,
description: 'The custom mapping of GitLab alert attributes to fields from the payload_example.',
resolver: ::Resolvers::AlertManagement::PayloadAlertMappingFieldResolver
field :payload_alert_fields, [::Types::AlertManagement::PayloadAlertFieldType],
null: true,
description: 'Extract alert fields from payload example for custom mapping.',
resolver: ::Resolvers::AlertManagement::PersistedPayloadAlertFieldResolver
end
end
end
......
......@@ -8,8 +8,6 @@ module Resolvers
alias_method :integration, :object
def resolve
return [] unless integration.is_a?(::AlertManagement::HttpIntegration)
integration.payload_attribute_mapping.map do |field_name, mapping|
::AlertManagement::AlertPayloadField.new(
project: integration.project,
......
# frozen_string_literal: true
module Resolvers
module AlertManagement
class PersistedPayloadAlertFieldResolver < BaseResolver
type ::Types::AlertManagement::PayloadAlertFieldType, null: true
alias_method :integration, :object
def resolve
Gitlab::AlertManagement::AlertPayloadFieldExtractor
.new(integration.project)
.extract(integration.payload_example)
end
end
end
end
......@@ -18,6 +18,7 @@ RSpec.describe GitlabSchema.types['AlertManagementHttpIntegration'] do
api_url
payload_example
payload_attribute_mappings
payload_alert_fields
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
......@@ -107,6 +107,18 @@ RSpec.describe 'getting Alert Management HTTP Integrations' do
'path' => %w(alert desc),
'type' => 'STRING'
}
],
'payloadAlertFields' => [
{
'label' => 'Name',
'path' => %w(alert name),
'type' => 'STRING'
},
{
'label' => 'Desc',
'path' => %w(alert desc),
'type' => 'STRING'
}
]
},
{
......@@ -118,7 +130,8 @@ RSpec.describe 'getting Alert Management HTTP Integrations' do
'url' => inactive_http_integration.url,
'apiUrl' => nil,
'payloadExample' => "{}",
'payloadAttributeMappings' => []
'payloadAttributeMappings' => [],
'payloadAlertFields' => []
}
)
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