Skip to content

Conversation

serhiy-yevtushenko
Copy link
Contributor

@serhiy-yevtushenko serhiy-yevtushenko commented Sep 2, 2025

Description

Fixes the issue #234 - added a method delete_notification_policy_tree, which performs call to the existing Grafana End-Point

Checklist

  • The patch has appropriate test coverage
  • [ X] The patch follows the style guidelines of this project
  • [ X] The patch has appropriate comments, particularly in hard-to-understand areas
  • The documentation was updated corresponding to the patch
  • [ X] I have performed a self-review of this patch

Copy link

coderabbitai bot commented Sep 2, 2025

Warning

Rate limit exceeded

@serhiy-yevtushenko has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d6fa598 and 145d0df.

📒 Files selected for processing (1)
  • test/elements/test_alertingprovisioning.py (1 hunks)

Summary by CodeRabbit

  • New Features
    • Added support to remove the alert notification policy tree via the API.
    • Available in both synchronous and asynchronous clients for consistent usage.
    • Enables easier cleanup and reset of alerting notification policies without affecting existing retrieval and update capabilities.

Walkthrough

Adds synchronous and asynchronous delete_notification_policy_tree methods to AlertingProvisioning that issue a DELETE to /v1/provisioning/policies and return the client response. Existing get/set notification policy tree methods are unchanged.

Changes

Cohort / File(s) Summary
Alerting provisioning — sync
grafana_client/elements/alertingprovisioning.py
Added delete_notification_policy_tree(self) which calls HTTP DELETE on /v1/provisioning/policies and returns the client response.
Alerting provisioning — async
grafana_client/elements/_async/alertingprovisioning.py
Added async def delete_notification_policy_tree(self) which performs an async DELETE to /v1/provisioning/policies and returns the client response.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Caller
    participant AP as AlertingProvisioning (sync/async)
    participant G as Grafana API

    Caller->>AP: delete_notification_policy_tree()
    AP->>G: DELETE /v1/provisioning/policies
    G-->>AP: 2xx / 4xx / 5xx Response
    AP-->>Caller: return response
    note right of AP: new method added (sync & async)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my nose and give a tap,
A tiny hop, a tidy zap—
The policy tree falls soft and neat,
I nibble crumbs and drum my feet.
🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.27%. Comparing base (c6b24d4) to head (145d0df).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #236      +/-   ##
==========================================
+ Coverage   92.26%   92.27%   +0.01%     
==========================================
  Files          27       27              
  Lines        1822     1825       +3     
==========================================
+ Hits         1681     1684       +3     
  Misses        141      141              
Flag Coverage Δ
unittests 92.27% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
grafana_client/elements/alertingprovisioning.py (1)

193-199: Bug: delete_mute_timing uses GET instead of DELETE.

This will not delete the resource and is likely a copy/paste error.

-        return self.client.GET(delete_mute_timing_path)
+        return self.client.DELETE(delete_mute_timing_path)
🧹 Nitpick comments (4)
grafana_client/elements/alertingprovisioning.py (4)

148-155: Nit: align docstring wording with surrounding methods.

Prefer “Deletes notification policy tree” for consistency with other “Deletes …” docstrings.

-        Removes notification policy tree
+        Deletes notification policy tree

51-57: Docstring param mismatch in get_rule_group.

The docstring mentions disable_provenance, but the method doesn’t accept it.

         """
         :param folder_uid:
         :param group_uid:
-        :param disable_provenance:
         :return:
         """

239-240: Nit: variable name says “create” in a delete method.

Rename for clarity.

-        create_template_path = "/v1/provisioning/templates/%s" % template_name
-        return self.client.DELETE(create_template_path)
+        delete_template_path = "/v1/provisioning/templates/%s" % template_name
+        return self.client.DELETE(delete_template_path)

148-155: Tests and docs follow-up

Please add a unit test that asserts client.DELETE is called with “/v1/provisioning/policies” and update docs/readme to mention the new API. I can draft both if helpful.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c6b24d4 and a182834.

📒 Files selected for processing (1)
  • grafana_client/elements/alertingprovisioning.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (ubuntu-22.04, pypy-3.9)
🔇 Additional comments (1)
grafana_client/elements/alertingprovisioning.py (1)

148-155: Good addition: DELETE endpoint wired to existing policies path.

Method name, path, and return pattern are consistent with adjacent GET/PUT methods for the same resource. Nice, lean change.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
grafana_client/elements/_async/alertingprovisioning.py (1)

193-199: Bug: delete_mute_timing uses GET instead of DELETE

Unrelated to this PR but nearby; this likely prevents deletions.

Apply:

-        return await self.client.GET(delete_mute_timing_path)
+        return await self.client.DELETE(delete_mute_timing_path)
🧹 Nitpick comments (1)
grafana_client/elements/_async/alertingprovisioning.py (1)

148-155: Async delete_notification_policy_tree: endpoint/method look correct; please add tests/docs

Matches existing get/set pattern and uses the right path. Suggest adding a unit test asserting a DELETE to "/v1/provisioning/policies" is issued, and updating docs/changelog accordingly.

Example test sketch (pytest + mock):

import pytest
import asyncio

@pytest.mark.asyncio
async def test_delete_notification_policy_tree_calls_correct_endpoint(mocker):
    client = mocker.Mock()
    client.DELETE = mocker.AsyncMock(return_value={"status": 204})
    ap = AlertingProvisioning(client)
    resp = await ap.delete_notification_policy_tree()
    client.DELETE.assert_awaited_once_with("/v1/provisioning/policies")
    assert resp == {"status": 204}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a182834 and d6fa598.

📒 Files selected for processing (1)
  • grafana_client/elements/_async/alertingprovisioning.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
grafana_client/elements/_async/alertingprovisioning.py (1)
grafana_client/elements/alertingprovisioning.py (1)
  • delete_notification_policy_tree (148-154)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (ubuntu-22.04, pypy-3.9)
  • GitHub Check: test (ubuntu-22.04, pypy-3.10)

Copy link
Contributor

@amotl amotl left a comment

Choose a reason for hiding this comment

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

Thanks a stack for your contribution.

@amotl amotl merged commit 755ef50 into grafana-toolbox:main Sep 2, 2025
7 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.

2 participants