Skip to content

feat(grafana): add read-only alerting actions - #240

Merged
l1shen merged 1 commit into
oomol-lab:mainfrom
wengych:feat/grafana-alerting-actions
Jul 31, 2026
Merged

feat(grafana): add read-only alerting actions#240
l1shen merged 1 commit into
oomol-lab:mainfrom
wengych:feat/grafana-alerting-actions

Conversation

@wengych

@wengych wengych commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Adds four read-only alerting actions to the Grafana provider:

Action Endpoint
list_alert_rules GET /api/v1/provisioning/alert-rules
get_alert_rule GET /api/v1/provisioning/alert-rules/:uid
list_alert_instances GET /api/alertmanager/grafana/api/v2/alerts (supports active/silenced/inhibited filters)
list_contact_points GET /api/v1/provisioning/contact-points

These endpoints belong to Grafana's stable legacy REST API and are not affected by App Platform API version discovery (#221). This exact code has been running against Grafana 12.4.3 in a private deployment for two weeks.

🤖 Generated with Claude Code

Add list_alert_rules, get_alert_rule, list_alert_instances, and
list_contact_points. All four use Grafana's stable legacy REST API
(/api/v1/provisioning/*, /api/alertmanager/*), which is not versioned
per release, so they are unaffected by App Platform API version
discovery.
Copilot AI review requested due to automatic review settings July 30, 2026 14:24
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added Grafana alerting actions to list and retrieve alert rules.
    • Added support for listing alert instances with optional status filters.
    • Added support for listing notification contact points.
    • Responses are validated and returned in consistent formats.

Walkthrough

Added four Grafana provider actions for listing and retrieving alert rules, listing alert instances with optional filters, and listing contact points. New schemas validate alerting payloads. Runtime handlers call the corresponding Grafana REST endpoints and return normalized results with empty fallbacks when responses are missing.

Sequence Diagram(s)

sequenceDiagram
  participant ProviderAction
  participant grafanaActionHandlers
  participant GrafanaAPI
  ProviderAction->>grafanaActionHandlers: Dispatch alerting action
  grafanaActionHandlers->>GrafanaAPI: Request alert rules, instances, or contact points
  GrafanaAPI-->>grafanaActionHandlers: Return alerting payload
  grafanaActionHandlers-->>ProviderAction: Return normalized result
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the required format and accurately summarizes the Grafana alerting actions change.
Description check ✅ Passed The description clearly describes the new Grafana read-only alerting actions and their endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/providers/grafana/runtime.ts (1)

371-380: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the redundant compactObject wrapper.

grafanaRequestJson already drops undefined query values, so pass the query object directly and avoid the helper that only hides undefined fields.

Proposed simplification
-  const query = compactObject({
+  const query = {
     active: optionalBoolean(input.active),
     silenced: optionalBoolean(input.silenced),
     inhibited: optionalBoolean(input.inhibited),
-  });
+  };

As per coding guidelines, “Avoid trivial pass-through helpers and conditional object spreads that only hide undefined JSON fields.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/providers/grafana/runtime.ts` around lines 371 - 380, In
executeListAlertInstances, remove the compactObject wrapper and pass the object
containing active, silenced, and inhibited directly as the query argument to
grafanaRequestJson; rely on grafanaRequestJson to omit undefined values and
preserve the existing optionalBoolean mappings.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/providers/grafana/runtime.ts`:
- Around line 371-380: In executeListAlertInstances, remove the compactObject
wrapper and pass the object containing active, silenced, and inhibited directly
as the query argument to grafanaRequestJson; rely on grafanaRequestJson to omit
undefined values and preserve the existing optionalBoolean mappings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 661922ae-a902-4c61-b9d8-63b46809043a

📥 Commits

Reviewing files that changed from the base of the PR and between e86860c and e575460.

📒 Files selected for processing (2)
  • src/providers/grafana/actions.ts
  • src/providers/grafana/runtime.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds four new read-only alerting actions to the Grafana provider, implemented against Grafana’s legacy REST endpoints (i.e. not App Platform API-versioned), by extending the action catalog and wiring corresponding runtime handlers.

Changes:

  • Add new Grafana action names and JSON schemas for: list_alert_rules, get_alert_rule, list_alert_instances, list_contact_points.
  • Implement runtime request handlers for the four new alerting endpoints and register them in grafanaActionHandlers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/providers/grafana/runtime.ts Registers and implements the four new alerting action executors using existing grafanaRequestJson plumbing.
src/providers/grafana/actions.ts Extends the Grafana action-name union and defines input/output schemas for the four new alerting actions.
Comments suppressed due to low confidence (4)

src/providers/grafana/actions.ts:375

  • Other Grafana list-style actions in this provider return a raw field alongside the processed list. For consistency and easier debugging, consider adding raw to this action’s output schema too.
    outputSchema: s.object("Grafana alert instances.", {
      alertInstances: s.array("Alert instances returned by Grafana.", alertInstanceSchema),
    }),

src/providers/grafana/actions.ts:384

  • Other Grafana list-style actions in this provider include a raw field in the output. Adding raw here would keep the Grafana action outputs consistent and preserve the unmodified payload for troubleshooting.
    outputSchema: s.object("Grafana notification contact points.", {
      contactPoints: s.array("Contact points returned by Grafana.", contactPointSchema),
    }),

src/providers/grafana/runtime.ts:382

  • Consider returning the raw payload (or at least the filtered object-array form) alongside alertInstances, matching the pattern used by other list actions in this provider (e.g. list_data_sources) for easier troubleshooting.
    "/api/alertmanager/grafana/api/v2/alerts",
    { method: "GET", query },
    { ...context, phase: "execute" },
  );
  return { alertInstances: objectArrayOrEmpty(payload) };

src/providers/grafana/runtime.ts:391

  • For consistency with other Grafana list actions that expose raw (e.g. list_data_sources), consider returning a raw field here too so callers can inspect the underlying Grafana payload when needed.
    "/api/v1/provisioning/contact-points",
    { method: "GET" },
    { ...context, phase: "execute" },
  );
  return { contactPoints: objectArrayOrEmpty(payload) };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +343 to +345
outputSchema: s.object("Grafana-managed alert rules.", {
alertRules: s.array("Alert rules returned by Grafana.", alertRuleSchema),
}),
Comment on lines +354 to +359
const payload = await grafanaRequestJson(
"/api/v1/provisioning/alert-rules",
{ method: "GET" },
{ ...context, phase: "execute" },
);
return { alertRules: objectArrayOrEmpty(payload) };
@l1shen
l1shen merged commit 5ae9018 into oomol-lab:main Jul 31, 2026
4 checks passed
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.

3 participants