Skip to content

Add custom mapping related columns to http_integrations

What does this MR do?

Contributes to #262707 (closed)

Adds payload_example and payload_attribute_mapping columns to alert_management_http_integration table.

The columns are intended for storing the custom mapping related information per HTTP integration for alerts.

The payload_example is going to contain an example of an alert payload which is going to be sent to the alert's endpoint of a particular HTTP Integration. It should be similar (or close) to the payload we store in the alert_management_alerts.payload. It is a custom field populated by a user with maintainer (and above) permissions. The HTTP Integrations feature allows having one HTTP Integrations for licenses below GitLab Premium and several for licenses above GitLab Premium.

It can contain a lengthy JSON, but we are going to limit it to 1 MByte.

The payload_attribute_mapping column is going to contain a mapping between an alert attributes we want to display on an alert's page and their paths in the alert's payload.

Can have the following structure:

payload_example:

{
  "alert": {
    "name": "Example",
    "desc": "An alert example",
  },
  "created_at": "2019-12-14T14:15:16Z"
}

payload_attribute_mapping:

{
  "title": { "type": "string", "path": ["alert", "name"] },
  "description": { "type": "string", "path": ["alert", "desc"] },
  "start_time": { "type": "datetime", "path": ["created_at"] }
}

We are not going to search by payload_example, nor by payload_attributes_mapping, thus there is no need to have indexes for these columns.

Migration output

→ be rake db:migrate
== 20201214113729 AddCustomMappingColumnsToHttpIntegrations: migrating ========
-- add_column(:alert_management_http_integrations, :payload_example, :jsonb, {:null=>false, :default=>{}})
   -> 0.0050s
-- add_column(:alert_management_http_integrations, :payload_attribute_mapping, :jsonb, {:null=>false, :default=>{}})
   -> 0.0006s
== 20201214113729 AddCustomMappingColumnsToHttpIntegrations: migrated (0.0058s)
→ be rake db:rollback
== 20201214113729 AddCustomMappingColumnsToHttpIntegrations: reverting ========
-- remove_column(:alert_management_http_integrations, :payload_attribute_mapping, :jsonb, {:null=>false, :default=>{}})
   -> 0.0023s
-- remove_column(:alert_management_http_integrations, :payload_example, :jsonb, {:null=>false, :default=>{}})
   -> 0.0003s
== 20201214113729 AddCustomMappingColumnsToHttpIntegrations: reverted (0.0063s)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Vitali Tatarintev

Merge request reports