Skip to content

feat: add grafana create, update and delete alert rules #3873

Merged
forestileao merged 27 commits intosuperplanehq:mainfrom
WashingtonKK:feat/grafana-alert-rules
Apr 13, 2026
Merged

feat: add grafana create, update and delete alert rules #3873
forestileao merged 27 commits intosuperplanehq:mainfrom
WashingtonKK:feat/grafana-alert-rules

Conversation

@WashingtonKK
Copy link
Copy Markdown
Collaborator

@WashingtonKK WashingtonKK commented Mar 31, 2026

Implements: #3850

This expands the Grafana Integration by adding three components:

  • grafana.CreateAlertRule
  • grafana.UpdateAlertRule
  • grafana.DeleteAlertRule
  • grafana.ListAlertRules
  • grafana.GetAlertRule

Demo Video

Screencast.from.2026-04-01.12-37-35.webm

Note

Medium Risk
Adds new Grafana Alerting Provisioning API write paths (create/update/delete) plus new resource listing logic and stricter webhook provisioning behavior, which could impact existing Grafana integrations if permissions or payload merging are incorrect.

Overview
Expands the Grafana integration to manage Grafana-managed alert rules via the Alerting Provisioning HTTP API, adding new workflow components to create, get, list, update (partial merge), and delete alert rules, along with example outputs and UI mappers for rendering metadata/execution details.

Introduces shared alert-rule spec decoding/sanitization/validation and payload building/merging (including contact point attach/clear semantics, provenance checks, deep-clone safety, and condition/query rebuild logic), and extends the Grafana client with alert-rule/folder endpoints plus a mutex to serialize notification policy tree updates.

Tightens Grafana webhook setup to fail fast instead of falling back to manual setup on client/provisioning failures, and updates Query Data Source configuration by renaming dataSourceUid to dataSource, removing the timezone field, and interpreting datetime-local inputs as UTC (with stricter timezone requirements added for annotation datetime-local parsing).

Reviewed by Cursor Bugbot for commit 87ffad3. Bugbot is set up for automated code reviews on this repo. Configure here.

@superplanehq-integration
Copy link
Copy Markdown

👋 Commands for maintainers:

  • /sp start - Start an ephemeral machine (takes ~30s)
  • /sp stop - Stop a running machine (auto-executed on pr close)

@WashingtonKK WashingtonKK changed the title feat: add grafana create, update anddelete alert rules feat: add grafana create, update and delete alert rules Mar 31, 2026
Comment thread pkg/integrations/grafana/alert_rule_common.go
Comment thread pkg/integrations/grafana/query_data_source.go
Comment thread pkg/integrations/grafana/grafana.go
Comment thread pkg/integrations/grafana/webhook_handler.go
Comment thread pkg/integrations/grafana/on_alert_firing.go
Comment thread pkg/integrations/grafana/client.go
Comment thread pkg/integrations/grafana/webhook_handler.go Outdated
Comment thread pkg/integrations/grafana/webhook_handler.go
Comment thread pkg/integrations/grafana/query_data_source.go Outdated
Comment thread pkg/integrations/grafana/query_data_source.go
Comment thread pkg/integrations/grafana/alert_rule_common.go
Comment thread pkg/integrations/grafana/grafana.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/grafana.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go
Comment thread pkg/integrations/grafana/alert_rule_common.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go Outdated
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/list_alert_rules.go
@WashingtonKK
Copy link
Copy Markdown
Collaborator Author

Screencast.from.2026-04-03.10-48-59.webm
Screencast.from.2026-04-03.10-54-32.webm

Comment thread pkg/integrations/grafana/alert_rule_common.go
- Added validation for `For`, `NoDataState`, and `ExecErrState` fields in `CreateAlertRuleSpec` and `UpdateAlertRuleSpec` to ensure they are not empty and conform to expected formats.
- Introduced helper functions `isValidDuration`, `isValidNoDataState`, and `isValidExecErrState` to validate respective fields.
- Added unit tests to cover new validation scenarios, ensuring robust error handling for invalid inputs.

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/example_output_create_alert_rule.json
- Changed alert rule condition from "A" to "C" across multiple JSON files.
- Introduced new query models for alert rules, including a "reduce" model and a "threshold" model, enhancing the alerting capabilities.
- Updated the data structure to support additional references and expressions for improved alert evaluation.

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
- Changed alert rule condition from "A" to "C" in multiple sections of the Grafana documentation.
- Added new query models, including "reduce" and "threshold", to improve alert evaluation capabilities.
- Updated data structures to support additional references and expressions for enhanced alerting functionality.

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread web_src/src/pages/workflowv2/mappers/grafana/alert_rule_shared.ts
Comment thread pkg/integrations/grafana/client.go Outdated
@AleksandarCole AleksandarCole added the pr:stage-3/3 Ready for full, in-depth, review label Apr 10, 2026
Comment thread pkg/integrations/grafana/alert_rule_common.go
Comment thread pkg/integrations/grafana/alert_rule_common.go
Comment thread pkg/integrations/grafana/delete_alert_rule.go
Comment thread pkg/integrations/grafana/get_alert_rule.go
Comment thread pkg/integrations/grafana/list_alert_rules.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/list_alert_rules.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Comment thread pkg/integrations/grafana/alert_rule_common.go
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 87ffad3. Configure here.

Comment thread pkg/integrations/grafana/query_data_source.go
@forestileao forestileao merged commit 2c4a35b into superplanehq:main Apr 13, 2026
6 checks passed
0vertake pushed a commit to 0vertake/superplane that referenced this pull request Apr 13, 2026
…#3873)

Implements: superplanehq#3850

This expands the Grafana Integration by adding three components:
- `grafana.CreateAlertRule`
- `grafana.UpdateAlertRule`
- `grafana.DeleteAlertRule`
- `grafana.ListAlertRules`
- `grafana.GetAlertRule`

### Demo Video

[Screencast from 2026-04-01
12-37-35.webm](https://github.com/user-attachments/assets/831343d3-cf4d-4159-a49f-b82b81f438dc)




<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Adds new Grafana Alerting Provisioning API write paths
(create/update/delete) plus new resource listing logic and stricter
webhook provisioning behavior, which could impact existing Grafana
integrations if permissions or payload merging are incorrect.
> 
> **Overview**
> Expands the Grafana integration to manage **Grafana-managed alert
rules** via the Alerting Provisioning HTTP API, adding new workflow
components to `create`, `get`, `list`, `update` (partial merge), and
`delete` alert rules, along with example outputs and UI mappers for
rendering metadata/execution details.
> 
> Introduces shared alert-rule spec decoding/sanitization/validation and
payload building/merging (including contact point attach/clear
semantics, provenance checks, deep-clone safety, and condition/query
rebuild logic), and extends the Grafana client with alert-rule/folder
endpoints plus a mutex to serialize notification policy tree updates.
> 
> Tightens Grafana webhook setup to **fail fast** instead of falling
back to manual setup on client/provisioning failures, and updates `Query
Data Source` configuration by renaming `dataSourceUid` to `dataSource`,
removing the timezone field, and interpreting datetime-local inputs as
UTC (with stricter timezone requirements added for annotation
datetime-local parsing).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
87ffad3. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:stage-3/3 Ready for full, in-depth, review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants