Skip to content

Introduce tool-based classes to represent alert payloads

Sarah Yasonik requested to merge sy-alert-payload-class into master

What does this MR do?

This MR introduces classes to make it easier to represent and interact with various alert payloads. It creates a unified API, letting GitLab code interact with payloads regardless of the fields defined or the source.

As a very simple demo of the format, this MR also moves the runbook-related code out of the presenter.

Practical effects on code:

  • Through the course of this refactor, these new classes will ultimately replace Gitlab::Alerting, Gitlab::AlertManagement::AlertParams, and rearrange content from the several presenter classes we have for alerts.
  • For an idea of where this is going, refer to a trial-run of the idea in !38850 (closed)

This is a step towards a data flow/architecture which would look something like:

  • A Gitlab::AlertManagement::Payload::Base defines an api by which any alert payload content is accessible. Any payload field we expect to interact with (beyond simply displaying it or passing it through to FE), should be defined as part of the base class.
  • Subclasses of Payload::Base define how to access fields from the payload or find corresponding DB records based on the source of the alert (prometheus/generic/etc).

Example use-cases

  • Display an alert in the UI. In this scenario, payload attributes should be accessed through the #parsed_payload field on an AlertManagement::Alert.
  • Create a new AlertManagement::Alert from an incoming notification. Use the new_from_payload class method on AlertMangement::Alert to instantiate an instance of the class with attributes populated from the payload.
  • Send an email based on an alert. For presentational elements (such as formatting strings), use the AlertManagement::AlertPresenter, accessible through the #present method on AlertManagement::Alert

Refactor breakdown (each likely separate MRs)

  • Add payload types
  • Add connections from payloads to AlertManagement::Alert
  • Update alert creation for gitlab-managed prometheus alerts
  • Update alert creation for external prometheus alerts
  • Update alert creation for generic alert
  • Update issue creation from alert UI
  • Update auto-issue creation
  • Update auto-email on alert

Screenshots

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 Peter Leitzen

Merge request reports