Skip to content

feat: add grafana create, update anddelete alert rules #3860

Closed
WashingtonKK wants to merge 9 commits intosuperplanehq:mainfrom
WashingtonKK:feat/grafana-alert-rules-crud-part-1
Closed

feat: add grafana create, update anddelete alert rules #3860
WashingtonKK wants to merge 9 commits intosuperplanehq:mainfrom
WashingtonKK:feat/grafana-alert-rules-crud-part-1

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

Demo Video


Note

Medium Risk
Adds new Grafana provisioning API interactions (alert rules + notification policy route upserts/removals) and changes webhook secret management/filtering, which could affect alert delivery and provisioning behavior if Grafana API responses differ from expectations.

Overview
Extends the Grafana integration with new alert-rule components: grafana.createAlertRule, grafana.getAlertRule, and grafana.updateAlertRule, including shared config/schema/validation and example outputs.

Updates the Grafana client and webhook handler to provision notification policy routes (in addition to contact points), generate/persist webhook bearer secrets in webhook storage (legacy sharedSecret still supported), and optionally filter alert webhooks by alertname predicates consistently across provisioning and runtime.

Enhances resource pickers and UI: adds listable folder/alert-rule integration resources, switches Query Data Source timeFrom/timeTo to datetime fields with a default lookback, improves execution detail rendering (timestamp formatting + query result summary), and refreshes Grafana docs/instructions accordingly.

Written by Cursor Bugbot for commit cf6ef60. This will update automatically on new commits. 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)

if resourceType != resourceTypeDataSource {
return []core.IntegrationResource{}, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ListResources errors on unknown types when client fails

Low Severity

NewClient is now called before the resourceType switch, so if the integration isn't fully configured (e.g., missing API token), ListResources returns an error even for unknown resource types. Previously, the unknown-type check happened first and returned an empty list without attempting client creation. This changes the error contract for the default case from ([], nil) to (nil, error).

Additional Locations (1)
Fix in Cursor Fix in Web

eventId: execution.rootEvent.id,
},
];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicated event section builder across mapper files

Low Severity

buildGrafanaEventSections in alert_rule_shared.ts duplicates the logic of baseEventSections in query_data_source.ts. Both find the root trigger node, look up its renderer, extract the title, and return a single-element EventSection[] with the same fields. The minor differences (guard clauses, optional fallbacks) could be unified into one shared utility to avoid divergence during future maintenance.

Additional Locations (1)
Fix in Cursor Fix in Web

… handler

- Simplified instructions for connecting Grafana in `grafana.go`.
- Enhanced `OnAlertFiring` trigger to support alert name filtering with predicates.
- Updated webhook handler to manage shared secrets more effectively.
- Added tests for alert name filtering and webhook handling.
- Removed unused custom field renderer and related components.
- Improved metadata handling in the Grafana webhook setup.
- Refactored timestamp formatting utility to use timezone-aware functions.

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
…larity

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
… timestamp formatting

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
…ata handling

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
…al setup requirements

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
@WashingtonKK WashingtonKK force-pushed the feat/grafana-alert-rules-crud-part-1 branch from 83e397a to cf6ef60 Compare March 31, 2026 19:14
@WashingtonKK
Copy link
Copy Markdown
Collaborator Author

Recreated on the renamed branch as #3873 (feat/grafana-alert-rules). Closing this PR so the active review thread stays on the new branch name.

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.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

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

{Label: "OK", Value: "OK"},
{Label: "Keep Last State", Value: "KeepLast"},
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shared dropdown options invalid for execErrState field

Medium Severity

The alertRuleStateOptions() function is shared for both the noDataState and execErrState select fields, but Grafana's API accepts different valid values for each. The Grafana provisioning API accepts NoData, Alerting, OK, KeepLast for noDataState, but Error, Alerting, OK, KeepLast for execErrState. The shared options include NoData (invalid for execErrState) and omit Error (a valid execErrState value). Selecting "No Data" for execution error state causes an API rejection.

Additional Locations (1)
Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant