Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alerting: Implement template preview for Grafana AlertManager #65530

Merged
merged 33 commits into from
Apr 28, 2023

Conversation

soniaAguilarPeiron
Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron commented Mar 29, 2023

What is this feature?

This PR adds the preview feature in templates form. This feature is only available for Grafana AlertManager.

Why do we need this feature?

This will help users understand the result of the template they are creating, by showing errors directly in the preview. This would prevent a lot of templating issues.
This PR also enables user to create alert data payload for the preview, not only editing it in a JSON editor but having an alert data editor, where user doesn't need to understand the exact JSON format for the payload.

Who is this feature for?

All users.

Fixes #61764

Special notes for your reviewer:

templatePreviewFE.mp4

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.
  • There are no known compatibility issues with older supported versions of Grafana, or plugins.
  • It passes the Hosted Grafana feature readiness review for observability, scalability, performance, and security.

@github-advanced-security
Copy link

You have successfully added a new CodeQL configuration .github/workflows/pr-codeql-analysis-javascript.yml:analyze. As part of the setup process, we have scanned this repository and found 27 existing alerts. Please check the repository Security tab to see all alerts.

@soniaAguilarPeiron soniaAguilarPeiron added this to the 9.5.0 milestone Mar 29, 2023
@soniaAguilarPeiron soniaAguilarPeiron added the no-changelog Skip including change in changelog/release notes label Mar 29, 2023
@grafanabot grafanabot removed this from the 9.5.0 milestone Apr 4, 2023
@grafanabot
Copy link
Contributor

This pull request was removed from the 9.5.0 milestone because 9.5.0 is currently being released.

@VikaCep
Copy link
Contributor

VikaCep commented Apr 13, 2023

I noticed the request is called as /templates/preview but in the design doc it's listed as /templates/test. We should get confirmation on the final form.

@soniaAguilarPeiron
Copy link
Member Author

soniaAguilarPeiron commented Apr 14, 2023

I noticed the request is called as /templates/preview but in the design doc it's listed as /templates/test. We should get confirmation on the final form.

yes, the final api is still WIP, so I decided not to update the request yet until we are sure about the final required request.

@VikaCep
Copy link
Contributor

VikaCep commented Apr 14, 2023

I added an alert instance selector to the preview section so that users can select from existing alert instances to build the payload. The alert instances are consumed from api/alertmanager/grafana/api/v2/alerts.

Once one or more alerts are selected, a payload like the one defined in this document is created with the alerts information and shown in the payload editor:

{
   alerts: [
        {
          annotations: ...,
          labels: ...,
          startsAt: ...,
          endsAt: ...,
        },  ...
   ]
}

Example:

2023-04-14 15 22 04

@soniaAguilarPeiron soniaAguilarPeiron force-pushed the alerting/templates-preview branch 6 times, most recently from 04d9fa1 to 8d2fbd4 Compare April 25, 2023 09:07
Copy link
Member

@gillesdemey gillesdemey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Just one more nit but we can change that after it's merged :shipit:

Copy link
Contributor

@konrad147 konrad147 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@soniaAguilarPeiron soniaAguilarPeiron marked this pull request as ready for review April 28, 2023 15:03
@soniaAguilarPeiron soniaAguilarPeiron requested review from a team as code owners April 28, 2023 15:03
@soniaAguilarPeiron soniaAguilarPeiron changed the title Alerting: templates preview Alerting: Implement template preview for Grafana AlertManager Apr 28, 2023
@soniaAguilarPeiron soniaAguilarPeiron merged commit 3854be1 into main Apr 28, 2023
@soniaAguilarPeiron soniaAguilarPeiron deleted the alerting/templates-preview branch April 28, 2023 15:05
ryantxu pushed a commit that referenced this pull request May 3, 2023
* Add Preview template and payload editor to templates form

* Add TemplatePreview test and update css

* Preview errors for each template that is wrong

* Enable preview templating only for Grafana Alert Manager

* Use harcoded default payload instead of requesting it to the backend

* Update error response in the api definition

* Add spinner when loading result for preview

* Update api request followind DD changes

* Use pre instead of TextArea to render the preview

* Fix tests

* Add alert list editor

* Add start and end time for alert generator

* Add preview for data list added in the modal

* Update copies and move submit button in alert generator to the bottom

* Copy updates

* Refactor

* Use tab instead of button to preview

* Move payload editor next to the content

* Copy update

* Refactor

* Adress PR review comments

* Fix wrong json format throwing an exception when adding more data

* Use monaco editor for payload

* Only show text 'Preview for...'  when we have more than one define

* Fix some errors

* Update CollapseSection style

* Add tooltip for the Payload info icon explaining the available list of alert data fields in preview

* Set payload as invalid if it's not an array

* Fix test

* Update text in AlertTemplateDataTable

* Add separators to distinguish lines that belong to the preview

* Fix text

* Use subDays instead of addDays for substracting days
@zerok zerok modified the milestones: 10.0.0, 10.0.0-preview May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Test notification templates from within Grafana
9 participants