-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grafana 8.x new Alert Rule #523
Conversation
I submitted a PR to you, @OscarVanL, to fix the failing flake8 👋 |
Thank you! I've merged it. |
It looks like I still need to rebase this to fix the conflicts. |
@OscarVanL could you please rebase and we'll check again? Maybe I could help |
[ADD] Doc String on AlertRuler [UPD] Annotations Management [ADD] Default value
… Add unit tests, example usage, example upload script, and console generate-alertgroup(s) commands
I've rebased the branch. @JamesGibo it looks like you've reviewed some of the previous MRs, mind taking a look at this please? 😄 |
Hello, thank you for this job! We would like to use this class in out project too ) Please, take a look if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution, sorry i have not reviewed it so far, but as it is quite a big PR I want to fully tests its functionality.
Will try have a look at it today.
We can ignore the doc failure as this is just some links that have moved in grafana |
Thanks! We've been using this internally in my company for a couple of months now and it seems to work for us (we wanted a way to template lots of common alert types for many microservices, which this was really useful for), but I also can't say I've tested every feasable use case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had a scan of the code which looks good.
I know you have added an example file, but would you also be able to add a quick example usage of the file to the getting started docs?
@OscarVanL The PR looks good for adding alerts for Grafana v8, would you be able to add some basic documentation of the functionality? Once added I will merge this PR. When tested I tested using it to generate alerts for Grafana v9, unfortunately the alert schema has change significantly. I was also looking at if we could use this code to create the required JSON file for file based Grafana alert provisioning {
"apiVersion": 1,
"groups": [
<Insert rule groups here>
]
} |
@JamesGibo I've added some documentation to the getting started page. That's a shame to hear about the schema change in Grafana v9. I've not had a chance to try out Grafana v9 yet. I've also been quite interested in Grafana provisioning, it would be cool if our dashboards could be generated as code and then provisioned by CI in a way that's well supported by Grafnaa. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, for adding some documentation of the feature.
I will merger the PR now and will make a release once I have finished my work on alerts for Grafana v9.
File based provisioning for dashboards is quite stable and I have been using that for a while, but the alert provisioning has just been released and have already found a few bugs in it and its not very well documented.
What does this do?
This builds on #495 to add a new Grafana 8.x alert rule.
In addition to that MR this does the following:
It also includes some extras to make it more feature complete, but these can be separated out into a different PR if you prefer:
Why is it a good idea?
There was no way to produce alerts in new grafana versions using grafanalib.
Context
Grafana 8 added a new unified alerting system.
Questions
Limitations
Currently, there is no way to import/export grafana alerts as JSON via the Grafana user interface.
I have provided an example upload script that does the following:
Delete all alerts for the AlertGroup in a folder:
DELETE https://<YOUR GRAFANA URL>/api/ruler/grafana/api/v1/rules/<FOLDER>/<ALERT GROUP NAME>
Upload all alerts for the AlertGroup into the folder:
POST https://<YOUR GRAFANA URL>/api/ruler/grafana/api/v1/rules/<FOLDER>
with the generated JSON in the request body.I recommend testing this in separate grafana deployment to your production environment with all your real alerts! I expect it would be good practice to have an alert group specifically for alerts-as-code so that you don't unintentionally delete alerts that colleagues created in the same alert group via the grafana website.