Skip to content

Commit

Permalink
Merge pull request #1724 from grafana/docs/notification-policy-docs
Browse files Browse the repository at this point in the history
docs: improve alerting documentation
  • Loading branch information
theSuess authored Oct 23, 2024
2 parents fb9264e + e1fa45b commit 0c1656c
Show file tree
Hide file tree
Showing 18 changed files with 476 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: GrafanaNotificationPolicy is the Schema for the GrafanaNotificationPolicy
API
displayName: Grafana Notification policy
kind: GrafanaNotificationPolicy
name: grafananotificationpolicies.grafana.integreatly.org
version: v1beta1
- description: GrafanaAlertRuleGroup is the Schema for the grafanaalertrulegroups
API
displayName: Grafana Alert Rule Group
Expand Down
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ resources:
- grafana_v1beta1_grafanafolder.yaml
- grafana_v1beta1_grafanaalertrulegroup.yaml
- grafana_v1beta1_grafanacontactpoint.yaml
- grafana_v1beta1_grafananotificationpolicy.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
2 changes: 1 addition & 1 deletion docs/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
+++

{{< blocks/cover title="Welcome to the Grafana Operator documentation" image_anchor="top" height="full" >}}
<a class="btn btn-lg btn-primary me-3 mb-4" href="/docs/">
<a class="btn btn-lg btn-primary me-3 mb-4" href="docs/">
Learn More <i class="fas fa-arrow-alt-circle-right ms-2"></i>
</a>
<a class="btn btn-lg btn-secondary me-3 mb-4" href="https://github.com/grafana/grafana-operator/releases">
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/alerting.md

This file was deleted.

76 changes: 76 additions & 0 deletions docs/docs/alerting/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: Alerting
weight: 13
---
{{% pageinfo color="primary" %}}
Alerting resources require Grafana version 9.5 or higher.
{{% /pageinfo %}}

The Grafana Operator currently only supports _Grafana Managed Alerts_.

For data source managed alerts, refer to the documentation and tooling available for the respective data source.
{{% alert title="Note" color="primary" %}}
When using Mimir/Prometheus, you can use the [`mimir.rules.kubernetes`](https://grafana.com/docs/alloy/latest/reference/components/mimir/mimir.rules.kubernetes/) component of [Grafana Alloy](https://grafana.com/docs/alloy/latest/) to deploy rules as Kubernetes resources.
{{% /alert %}}


## Full example

The following resources construct the flow outlined in the [Grafana notification documentation](https://grafana.com/docs/grafana/latest/alerting/fundamentals/notifications/).

They create:
1. Three alert rules across two different groups
2. Two contact points for two different teams
3. A notification policy to route alerts to the correct team

{{< figure src="notification-routing.png" title="Flowchart of alerts routed through this system" width="500" >}}

{{% alert title="Note" color="primary" %}}
If you want to try this for yourself, you can [get started with demo data in Grafana cloud](https://grafana.com/docs/grafana-cloud/get-started/#install-demo-data-sources-and-dashboards).
The examples below utilize the data sources to give you real data to alert on.
{{% /alert %}}

### Alert rule groups

The first resources in this flow are _Alert Rule Groups_.
An alert rule group can contain multiple alert rules.
They group together alerts to run on the same interval and are stored in a Grafana folder, alongside dashboards.

First, create the folder:

{{< readfile file="../examples/notifications-full/folder.yaml" code="true" lang="yaml" >}}

The first alert rule group is responsible for alerting on well known Kubernetes issues:

{{< readfile file="../examples/notifications-full/kubernetes-alert-rules.yaml" code="true" lang="yaml" >}}

The second alert rule group is responsible for alerting on security issues:

{{< readfile file="../examples/notifications-full/security-alert-rules.yaml" code="true" lang="yaml" >}}

After applying the resources, you can see the created rule groups in the _Alert rules_ overview page:

![Alert rules overview page](./overview-page.png)

### Contact Points

Before you can route alerts to the correct receivers, you need to define how these alerts should be delivered.
[Contact points](./contact-points) specify the methods used to notify someone using different providers.

Since the two different teams get notified using different email addresses, two contact points are required.

{{< readfile file="../examples/notifications-full/contact-points.yaml" code="true" lang="yaml" >}}

### Notification Policy

Now that all parts are in place, the only missing component is the notification policy.
The instances notification policy routes alerts to contact points based on labels.
A Grafana instance can only have one notification policy applied at a time as it's a global object.

The following notification policy routes alerts based on the team label and further configures the repetition interval for high severity alerts belonging to the operations team:

{{< readfile file="../examples/notifications-full/notification-policy.yaml" code="true" lang="yaml" >}}

After applying the resource, Grafana shows the following notification policy tree:

![Notification policy tree after applying the resource](./notification-policy-tree.png)
12 changes: 12 additions & 0 deletions docs/docs/alerting/alert-rule-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Alert Rule Groups
---

Alert Rule Groups contain a list of alerts which should evaluate at the same interval.
Every rule group must belong to a folder and contain at least one rule.

The easiest way to get the YAML specification for an alert rule is to use the [modify export feature](https://grafana.com/docs/grafana/latest/alerting/set-up/provision-alerting-resources/export-alerting-resources/), introduced in Grafana 10.

The following snippet shows an example alert rule group with a single alert that fires when the temperature is below zero degrees.

{{< readfile file="../examples/alertrulegroups/resources.yaml" code="true" lang="yaml" >}}
18 changes: 18 additions & 0 deletions docs/docs/alerting/contact-points.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Contact Points
---

Contact points contain the configuration for sending alert notifications. You can assign a contact point either in the alert rule or notification policy options.
For a complete explanation on notification policies, refer to the [upstream Grafana documentation](https://grafana.com/docs/grafana/latest/alerting/fundamentals/notifications/contact-points/).

{{% alert title="Note" color="secondary" %}}
The Grafana operator currently only supports a single receiver per contact point definition.
As a workaround you can create multiple contact points with the same `spec.name` value.
Follow issue [#1529](https://github.com/grafana/grafana-operator/issues/1529) for further updates on this topic.
{{% /alert %}}

The following snippet shows an example contact point which notifies a specific email address.
It also highlights how secrets and config maps can utilized to externalize some of the configuration.
This is especially useful for contact points which contain sensitive information.

{{< readfile file="../examples/contactpoint_override/resources.yaml" code="true" lang="yaml" >}}
15 changes: 15 additions & 0 deletions docs/docs/alerting/notification-policies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Notification Policies
---

Notification policies provide you with a flexible way of designing how to handle notifications and minimize alert noise.
For a complete explanation on notification policies, see the [upstream Grafana documentation](https://grafana.com/docs/grafana/latest/alerting/fundamentals/notifications/notification-policies/).

{{% alert title="Tip" color="secondary" %}}
If you already know which contact point an alert should send to, you can directly set the [`receivers`]({{% relref "/docs/api/#grafanaalertrulegroupspecrulesindexnotificationsettings" %}}) property on the alert rule.
{{% /alert %}}


The following snippet shows an example notification policy routing to the `operations` or `security` team based on the `team` label.

{{< readfile file="../examples/notification-policy/resources.yaml" code="true" lang="yaml" >}}
Binary file added docs/docs/alerting/notification-policy-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/alerting/notification-routing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/alerting/overview-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions examples/notification-policy/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaNotificationPolicy
metadata:
name: grafananotificationpolicy-sample
spec:
instanceSelector:
matchLabels:
dashboards: "grafana"
route:
receiver: grafana-email-default
group_by:
- grafana_folder
- alertname
routes:
- receiver: grafana-email-operations
object_matchers:
- - team
- =
- operations
- receiver: grafana-email-security
object_matchers:
- - team
- =
- security
26 changes: 26 additions & 0 deletions examples/notifications-full/contact-points.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaContactPoint
metadata:
name: operations-team
spec:
name: operations-team
type: "email"
instanceSelector:
matchLabels:
instance: my-grafana-stack
settings:
addresses: 'operations@example.com'
---
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaContactPoint
metadata:
name: security-team
spec:
name: security-team
type: "email"
instanceSelector:
matchLabels:
instance: my-grafana-stack
settings:
addresses: 'security@example.com'
8 changes: 8 additions & 0 deletions examples/notifications-full/folder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaFolder
metadata:
name: alerts-demo
spec:
instanceSelector:
matchLabels:
instance: "my-grafana-stack"
Loading

0 comments on commit 0c1656c

Please sign in to comment.