Skip to content

improvement(grafana): align tools and block with Grafana API spec#4574

Merged
waleedlatif1 merged 5 commits into
stagingfrom
waleedlatif1/validate-grafana
May 13, 2026
Merged

improvement(grafana): align tools and block with Grafana API spec#4574
waleedlatif1 merged 5 commits into
stagingfrom
waleedlatif1/validate-grafana

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

@waleedlatif1 waleedlatif1 commented May 13, 2026

Summary

  • Fixes wire-format field naming for Grafana provisioned alert rules (missing_series_evals_to_resolve, keepFiringFor, orgID) and reads with fallbacks so output is robust to both casings
  • Expands create/update alert-rule params (uid, isPaused, keepFiringFor, missingSeriesEvalsToResolve, notificationSettings, record, annotations, labels, disableProvenance) and supports X-Disable-Provenance header
  • Corrects defaults: execErrStateError, dashboard overwrite defaults to false, drops hardcoded for: 5m
  • Centralizes alert-rule output mapping in tools/grafana/utils.ts; tightens get_data_source UID heuristic; drops phantom slug/sortMeta from list_dashboards; adds legacy dashboardId param to list_annotations; PATCH-friendly optional text for update_annotation
  • Block: adds matching subBlocks (annotations/labels JSON, isPaused, keepFiringFor, missingSeriesEvalsToResolve, notificationSettings, record, alertRuleUidNew, disableProvenance, overwrite); expands outputs to cover new alert-rule fields

Test plan

  • List/get/create/update/delete alert rule against a live Grafana instance and confirm fields round-trip
  • Create alert rule with disableProvenance and verify rule is editable via UI
  • Update dashboard without overwrite and confirm version-conflict behavior
  • List annotations by dashboardUid and (legacy) dashboardId
  • PATCH-update annotation without text

… spec

Validates and corrects the Grafana integration against the official API
docs: fixes wire-format field naming for provisioned alert rules
(missing_series_evals_to_resolve, keepFiringFor, orgID), adds
X-Disable-Provenance support, expands alert-rule params (isPaused,
notificationSettings, record, annotations, labels), corrects defaults
(execErrState=Error, dashboard overwrite=false), and centralizes alert-rule
output mapping in a shared utils module.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 13, 2026 2:46am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 13, 2026

PR Summary

Medium Risk
Updates Grafana tool request/response shapes (especially alert rule provisioning) and changes defaults like dashboard overwrite, which could alter behavior for existing workflows. Risk is mitigated by mostly additive params and output normalization, but incorrect field mapping could break integrations.

Overview
Aligns the Grafana integration with current API semantics across docs, the Grafana block, and tool implementations.

Alert rules: expands create/update inputs (recording rules support, custom UID, pause/keep-firing/missing-series/notification settings, provenance control via X-Disable-Provenance), fixes wire-format field names and defaults (e.g., execErrState default and no hardcoded for), and centralizes/normalizes alert-rule outputs via new mapAlertRule + shared alertRuleOutputFields.

Dashboards/annotations/data sources/folders/contact points: adds UID-based dashboard filtering + pagination, makes dashboard updates default to not overwriting on version conflict, allows org-wide annotations + additional annotation filters/fields, improves data source ID-vs-UID routing and output fields, adds nested folder support (parentUid + parent metadata), and adds contact point name filtering; the block UI is updated to surface these new params and output fields.

Reviewed by Cursor Bugbot for commit e997595. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR aligns the Grafana tool suite with the provisioning API spec: it fixes wire-format field names (keep_firing_for, orgID), adds new parameters (uid, isPaused, keepFiringFor, notificationSettings, record, disableProvenance), corrects the execErrState default to Error, and fixes the overwrite default to false. A new utils.ts centralises alert rule output mapping across all four alert-rule tools.

  • Alert rule tools (create, update, get, list): output mapping centralised in mapAlertRule/alertRuleOutputFields with dual-casing fallbacks for both keep_firing_for/keepFiringFor and orgID/orgId; JSON parse failures now surface descriptive errors instead of silent fallbacks.
  • Dashboard/annotation/folder/contact-point tools: folderIdsfolderUIDs (Grafana v9+ API), text made optional in update_annotation, dashboardUid made optional for annotation operations, overwrite default corrected, get_data_source UID heuristic tightened.
  • Block: matching subBlocks added for all new params; params config refactored from mutation to explicit result object.

Confidence Score: 5/5

The changes are additive and fix real API compatibility bugs; no regressions were found in the changed paths.

All critical wire-format fixes are correct, error surfacing is consistent, and the centralized mapAlertRule utility correctly handles both API response casings. The two findings are minor quality observations that do not affect correctness of the existing paths.

utils.ts: the notification_settings output key naming inconsistency is worth resolving before it becomes a convention across downstream workflow steps.

Important Files Changed

Filename Overview
apps/sim/tools/grafana/utils.ts New shared utility correctly centralises alert rule output mapping with dual-casing fallbacks; notification_settings output key is inconsistently snake_case vs camelCase for all other fields.
apps/sim/tools/grafana/create_alert_rule.ts Expands params for uid, isPaused, keepFiringFor, notificationSettings, record, disableProvenance; removes hardcoded defaults and fixes JSON parse errors to throw; delegates output to mapAlertRule.
apps/sim/tools/grafana/update_alert_rule.ts Adds same new params as create; surfacing JSON parse errors via early postProcess returns; X-Disable-Provenance header correctly applied to PUT only; folderUid correctly mapped to folderUID.
apps/sim/blocks/blocks/grafana.ts Adds many new subBlocks for alert rule, dashboard, folder, annotation, and contact-point operations; params function refactored from mutating approach to explicit result object; falsy check on missingSeriesEvalsToResolve would drop value 0.
apps/sim/tools/grafana/get_data_source.ts UID heuristic corrected: purely-numeric strings now correctly route to /api/datasources/{id}; output expanded with basicAuthUser, withCredentials, secureJsonFields, version.
apps/sim/tools/grafana/update_dashboard.ts overwrite default corrected from !== false (always-true) to === true (opt-in), which properly surfaces 412 version conflicts.
apps/sim/tools/grafana/types.ts Type definitions updated to match expanded params and nullable outputs; GrafanaAlertRule now uses orgID and includes keepFiringFor, missingSeriesEvalsToResolve, notification_settings, record.

Sequence Diagram

sequenceDiagram
    participant Block as Grafana Block
    participant Tool as Tool (create/update/get/list)
    participant Utils as utils.ts
    participant API as Grafana Provisioning API

    Block->>Tool: params (folderUid, keepFiringFor, notificationSettings, disableProvenance)
    Tool->>API: POST/PUT /api/v1/provisioning/alert-rules
    API-->>Tool: ProvisionedAlertRule JSON (keep_firing_for, orgID, notification_settings)
    Tool->>Utils: mapAlertRule(data)
    Utils-->>Tool: normalized output (keepFiringFor, orgID fallbacks, dual-casing reads)
    Tool-->>Block: success and output

    Note over Tool,API: update_alert_rule GET existing rule first then merge and PUT
Loading

Reviews (4): Last reviewed commit: "fix(grafana): surface invalid JSON for a..." | Re-trigger Greptile

Comment thread apps/sim/tools/grafana/create_alert_rule.ts Outdated
Comment thread apps/sim/tools/grafana/create_alert_rule.ts
Comment thread apps/sim/tools/grafana/update_alert_rule.ts
Comment thread apps/sim/tools/grafana/update_alert_rule.ts
…ields

Grafana's ProvisionedAlertRule schema (verified against upstream Go source
and swagger spec) uses keep_firing_for (snake_case) and
missingSeriesEvalsToResolve (camelCase) — the opposite of what prior audit
rounds assumed. POST/PUT bodies now send the correct field names; mapAlertRule
reads the correct primary names with the old casings kept as fallbacks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Drop hardcoded orgID: 1 fallback; only send orgID when organizationId is
  provided, so token-scoped org context drives rule placement.
- Surface invalid JSON for notificationSettings/record on alert rule
  create/update instead of silently dropping the input.
- Fix execErrState description in update_alert_rule to include Error.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/grafana/create_alert_rule.ts
Copy link
Copy Markdown

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit da17194. Configure here.

…rt rules

Match the behavior of other JSON params (data, notificationSettings, record):
return a descriptive error instead of silently falling back to {} (create)
or keeping the existing value (update).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/grafana/create_alert_rule.ts
Copy link
Copy Markdown

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e997595. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e997595. Configure here.

Move ALERT_RULE_OUTPUT_FIELDS from utils.ts to types.ts and rename to
SCREAMING_SNAKE_CASE so scripts/generate-docs.ts (which only resolves const
references from types.ts matching [A-Z][A-Z_0-9]+) can inline the per-field
rows into the generated alert-rule output tables.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@waleedlatif1 waleedlatif1 merged commit c21bb91 into staging May 13, 2026
8 of 9 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/validate-grafana branch May 13, 2026 02:42
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