Skip to content

Commit f1a0adb

Browse files
committed
OBSDOCS-978: Document how user-workload monitoring admins can write general purpose alerting rules that can span several namespaces
1 parent baf9fac commit f1a0adb

6 files changed

+170
-19
lines changed

modules/monitoring-about-creating-alerting-rules-for-user-defined-projects.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
:_mod-docs-content-type: CONCEPT
66
[id="about-creating-alerting-rules-for-user-defined-projects_{context}"]
7-
= About creating alerting rules for user-defined projects
7+
= Creating alerting rules for user-defined projects
8+
9+
In {product-title}, you can create alerting rules for user-defined projects. Those alerting rules will trigger alerts based on the values of the chosen metrics.
810

911
If you create alerting rules for a user-defined project, consider the following key behaviors and important limitations when you define the new rules:
1012

@@ -14,6 +16,8 @@ You cannot include metrics from another user-defined project.
1416
For example, an alerting rule for the `ns1` user-defined project can use metrics exposed by the `ns1` project in addition to core platform metrics, such as CPU and memory metrics.
1517
However, the rule cannot include metrics from a different `ns2` user-defined project.
1618
19+
* By default, when you create an alerting rule, the `namespace` label is enforced on it even if a rule with the same name exists in another project. To create alerting rules that are not bound to their project of origin, see "Creating cross-project alerting rules for user-defined projects".
20+
1721
* To reduce latency and to minimize the load on core platform monitoring components, you can add the `openshift.io/prometheus-rule-evaluation-scope: leaf-prometheus` label to a rule.
1822
This label forces only the Prometheus instance deployed in the `openshift-user-workload-monitoring` project to evaluate the alerting rule and prevents the Thanos Ruler instance from doing so.
1923
+
@@ -22,3 +26,6 @@ This label forces only the Prometheus instance deployed in the `openshift-user-w
2226
If an alerting rule has this label, your alerting rule can use only those metrics exposed by your user-defined project.
2327
Alerting rules you create based on default platform metrics might not trigger alerts.
2428
====
29+
30+
31+

modules/monitoring-creating-alerting-rules-for-user-defined-projects.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ You can create alerting rules for user-defined projects. Those alerting rules wi
1010

1111
[NOTE]
1212
====
13-
* When you create an alerting rule, a project label is enforced on it even if a rule with the same name exists in another project.
14-
15-
* To help users understand the impact and cause of the alert, ensure that your alerting rule contains an alert message and severity value.
13+
To help users understand the impact and cause of the alert, ensure that your alerting rule contains an alert message and severity value.
1614
====
1715

1816
.Prerequisites
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * observability/monitoring/managing-alerts.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="creating-cross-project-alerting-rules-for-user-defined-projects_{context}"]
7+
= Creating cross-project alerting rules for user-defined projects
8+
9+
You can create alerting rules for user-defined projects that are not bound to their project of origin by configuring a project in the `user-workload-monitoring-config` config map. This allows you to create generic alerting rules that get applied to multiple user-defined projects instead of having individual `PrometheusRule` objects in each user project.
10+
11+
.Prerequisites
12+
13+
ifndef::openshift-dedicated,openshift-rosa[]
14+
* If you are a cluster administrator, you have access to the cluster as a user with the `cluster-admin` cluster role.
15+
* If you are a non-administrator user, you have access to the cluster as a user with the following user roles:
16+
** The `user-workload-monitoring-config-edit` role in the `openshift-user-workload-monitoring` project to edit the `user-workload-monitoring-config` config map.
17+
** The `monitoring-rules-edit` cluster role for the project where you want to create an alerting rule.
18+
* A cluster administrator has enabled monitoring for user-defined projects.
19+
endif::openshift-dedicated,openshift-rosa[]
20+
ifdef::openshift-dedicated,openshift-rosa[]
21+
* You have access to the cluster as a user with the `dedicated-admin` role.
22+
+
23+
[NOTE]
24+
====
25+
If you are a non-administrator user, you can still create cross-project alerting rules if you have the `monitoring-rules-edit` cluster role for the project where you want to create an alerting rule. However, that project needs to be configured in the `user-workload-monitoring-config` config map under the `namespacesWithoutLabelEnforcement` property, which can be done only by cluster administrators.
26+
====
27+
* The `user-workload-monitoring-config` `ConfigMap` object exists. This object is created by default when the cluster is created.
28+
endif::openshift-dedicated,openshift-rosa[]
29+
* You have installed the OpenShift CLI (`oc`).
30+
31+
.Procedure
32+
33+
. Edit the `user-workload-monitoring-config` config map in the `openshift-user-workload-monitoring` project:
34+
+
35+
[source,terminal]
36+
----
37+
$ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config
38+
----
39+
40+
. Configure projects in which you want to create alerting rules that are not bound to a specific project:
41+
+
42+
[source,yaml]
43+
----
44+
apiVersion: v1
45+
kind: ConfigMap
46+
metadata:
47+
name: user-workload-monitoring-config
48+
namespace: openshift-user-workload-monitoring
49+
data:
50+
config.yaml: |
51+
namespacesWithoutLabelEnforcement: [ <namespace> ] # <1>
52+
# ...
53+
----
54+
<1> Specify one or more projects in which you want to create cross-project alerting rules. Prometheus and Thanos Ruler for user-defined monitoring do not enforce the `namespace` label in `PrometheusRule` objects created in these projects.
55+
56+
. Create a YAML file for alerting rules. In this example, it is called `example-cross-project-alerting-rule.yaml`.
57+
58+
. Add an alerting rule configuration to the YAML file.
59+
The following example creates a new cross-project alerting rule called `example-security`. The alerting rule fires when a user project does not enforce the restricted pod security policy:
60+
+
61+
.Example cross-project alerting rule
62+
[source,yaml]
63+
----
64+
apiVersion: monitoring.coreos.com/v1
65+
kind: PrometheusRule
66+
metadata:
67+
name: example-security
68+
namespace: ns1 #<1>
69+
spec:
70+
groups:
71+
- name: pod-security-policy
72+
rules:
73+
- alert: "ProjectNotEnforcingRestrictedPolicy" # <2>
74+
for: 5m # <3>
75+
expr: kube_namespace_labels{namespace!~"(openshift|kube).*|default",label_pod_security_kubernetes_io_enforce!="restricted"} # <4>
76+
annotations:
77+
message: "Restricted policy not enforced. Project {{ $labels.namespace }} does not enforce the restricted pod security policy." #<5>
78+
labels:
79+
severity: warning # <6>
80+
----
81+
<1> Ensure that you specify the project that you defined in the `namespacesWithoutLabelEnforcement` field.
82+
<2> The name of the alerting rule you want to create.
83+
<3> The duration for which the condition should be true before an alert is fired.
84+
<4> The PromQL query expression that defines the new rule.
85+
<5> The message associated with the alert.
86+
<6> The severity that alerting rule assigns to the alert.
87+
+
88+
[IMPORTANT]
89+
====
90+
Ensure that you create a specific cross-project alerting rule in only one of the projects that you specified in the `namespacesWithoutLabelEnforcement` field.
91+
If you create the same cross-project alerting rule in multiple projects, it results in repeated alerts.
92+
====
93+
94+
. Apply the configuration file to the cluster:
95+
+
96+
[source,terminal]
97+
----
98+
$ oc apply -f example-cross-project-alerting-rule.yaml
99+
----
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * observability/monitoring/managing-alerts.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="disabling-cross-project-alerting-rules-for-user-defined-projects_{context}"]
7+
= Disabling cross-project alerting rules for user-defined projects
8+
9+
Creating cross-project alerting rules for user-defined projects is enabled by default. Cluster administrators can disable the capability in the `cluster-monitoring-config` config map for the following reasons:
10+
11+
* To prevent user-defined monitoring from overloading the cluster monitoring stack.
12+
* To prevent buggy alerting rules from being applied to the cluster without having to identify the rule that causes the issue.
13+
14+
.Prerequisites
15+
16+
ifndef::openshift-dedicated,openshift-rosa[]
17+
* You have access to the cluster as a user with the `cluster-admin` cluster role.
18+
endif::openshift-dedicated,openshift-rosa[]
19+
ifdef::openshift-dedicated,openshift-rosa[]
20+
* You have access to the cluster as a user with the `dedicated-admin` role.
21+
endif::openshift-dedicated,openshift-rosa[]
22+
* You have installed the OpenShift CLI (`oc`).
23+
24+
.Procedure
25+
26+
. Edit the `cluster-monitoring-config` config map in the `openshift-monitoring` project:
27+
+
28+
[source,terminal]
29+
----
30+
$ oc -n openshift-monitoring edit configmap cluster-monitoring-config
31+
----
32+
33+
. In the `cluster-monitoring-config` config map, disable the option to create cross-project alerting rules by setting the `rulesWithoutLabelEnforcementAllowed` value under `data/config.yaml/userWorkload` to `false`:
34+
+
35+
[source,yaml]
36+
----
37+
kind: ConfigMap
38+
apiVersion: v1
39+
metadata:
40+
name: cluster-monitoring-config
41+
namespace: openshift-monitoring
42+
data:
43+
config.yaml: |
44+
userWorkload:
45+
rulesWithoutLabelEnforcementAllowed: false
46+
# ...
47+
----
48+
49+
. Save the file to apply the changes.
50+
51+
52+

modules/monitoring-managing-alerting-rules-for-user-defined-projects.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
{product-title} monitoring ships with a set of default alerting rules. As a cluster administrator, you can view the default alerting rules.
1111

12-
In {product-title} {product-version}, you can create, view, edit, and remove alerting rules in user-defined projects.
12+
In {product-title}, you can view, edit, and remove alerting rules in user-defined projects.
1313

1414
ifdef::openshift-rosa,openshift-dedicated[]
1515
[IMPORTANT]

observability/monitoring/managing-alerts.adoc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,28 @@ include::modules/monitoring-modifying-core-platform-alerting-rules.adoc[leveloff
5656
* See the link:https://prometheus.io/docs/practices/alerting/[Prometheus alerting documentation] for further guidelines on optimizing alerts.
5757
endif::openshift-dedicated,openshift-rosa[]
5858
59-
// Managing alerting rules for user-defined projects
60-
include::modules/monitoring-managing-alerting-rules-for-user-defined-projects.adoc[leveloffset=+1]
59+
// Creating alerting rules for user-defined projects
60+
include::modules/monitoring-about-creating-alerting-rules-for-user-defined-projects.adoc[leveloffset=+1]
6161
include::modules/monitoring-optimizing-alerting-for-user-defined-projects.adoc[leveloffset=+2]
62-
63-
[role="_additional-resources"]
64-
.Additional resources
65-
* See the link:https://prometheus.io/docs/practices/alerting/[Prometheus alerting documentation] for further guidelines on optimizing alerts
66-
ifndef::openshift-rosa,openshift-dedicated[]
67-
* See xref:../../observability/monitoring/monitoring-overview.adoc#monitoring-overview[Monitoring overview] for details about {product-title} {product-version} monitoring architecture
68-
endif::[]
69-
70-
// creating alerting rules for user defined projects
71-
include::modules/monitoring-about-creating-alerting-rules-for-user-defined-projects.adoc[leveloffset=+2]
7262
include::modules/monitoring-creating-alerting-rules-for-user-defined-projects.adoc[leveloffset=+2]
63+
include::modules/monitoring-creating-cross-project-alerting-rules-for-user-defined-projects.adoc[leveloffset=+2]
7364
7465
[role="_additional-resources"]
7566
.Additional resources
76-
* See xref:../../observability/monitoring/monitoring-overview.adoc#monitoring-overview[Monitoring overview] for details about {product-title} {product-version} monitoring architecture.
67+
* link:https://prometheus.io/docs/practices/alerting/[Prometheus alerting documentation]
68+
* xref:../../observability/monitoring/monitoring-overview.adoc#monitoring-overview[Monitoring overview]
7769
70+
// Managing alerting rules for user-defined projects
71+
include::modules/monitoring-managing-alerting-rules-for-user-defined-projects.adoc[leveloffset=+1]
7872
include::modules/monitoring-accessing-alerting-rules-for-your-project.adoc[leveloffset=+2]
7973
include::modules/monitoring-listing-alerting-rules-for-all-projects-in-a-single-view.adoc[leveloffset=+2]
8074
include::modules/monitoring-removing-alerting-rules-for-user-defined-projects.adoc[leveloffset=+2]
75+
include::modules/monitoring-disabling-cross-project-alerting-rules-for-user-defined-projects.adoc[leveloffset=+2]
8176
8277
[role="_additional-resources"]
8378
.Additional resources
8479
85-
* See the link:https://prometheus.io/docs/alerting/alertmanager/[Alertmanager documentation]
80+
* link:https://prometheus.io/docs/alerting/alertmanager/[Alertmanager documentation]
8681
8782
// Sending notifications to external systems
8883
include::modules/monitoring-sending-notifications-to-external-systems.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)