Introduce tool-based classes to represent alert payloads
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 anAlertManagement::Alert
. - Create a new
AlertManagement::Alert
from an incoming notification. Use thenew_from_payload
class method onAlertMangement::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 onAlertManagement::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
- [-] Changelog entry - This is only a refactor with no user-facing changes.
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
-
Separation of EE specific content - there are a few fingerprint-related EE pieces that I haven't included in this round of changes, as they aren't yet taken advantage of. Will update in a future MR.
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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