Skip to content

Commit 17b7494

Browse files
committed
Metrics Docs Maintenance
Updates the docs around metrics gathering to include necessary NetworkPolicy, and fixes some errors in the ServiceMonitor yaml for securityContext and catalogd labels. Signed-off-by: Daniel Franz <dfranz@redhat.com>
1 parent 0c9f0b5 commit 17b7494

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

docs/draft/howto/consuming-metrics.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following procedure is provided as an example for testing purposes. Do not d
66

77
In OLM v1, you can use the provided metrics with tools such as the [Prometheus Operator][prometheus-operator]. By default, Operator Controller and catalogd export metrics to the `/metrics` endpoint of each service.
88

9-
You must grant the necessary permissions to access the metrics by using [role-based access control (RBAC) polices][rbac-k8s-docs].
9+
You must grant the necessary permissions to access the metrics by using [role-based access control (RBAC) polices][rbac-k8s-docs]. You will also need to create a `NetworkPolicy` to allow egress traffic from your scraper pod, as the OLM namespace by default allows only `catalogd` and `operator-controller` to send and receive traffic.
1010
Because the metrics are exposed over HTTPS by default, you need valid certificates to use the metrics with services such as Prometheus.
1111
The following sections cover enabling metrics, validating access, and provide a reference of a `ServiceMonitor`
1212
to illustrate how you might integrate the metrics with the [Prometheus Operator][prometheus-operator] or other third-part solutions.
@@ -23,6 +23,25 @@ kubectl create clusterrolebinding operator-controller-metrics-binding \
2323
--serviceaccount=olmv1-system:operator-controller-controller-manager
2424
```
2525

26+
2. Next, create a `NetworkPolicy` to allow the scraper pods to send their scrape requests:
27+
28+
```shell
29+
kubectl apply -f - << EOF
30+
apiVersion: networking.k8s.io/v1
31+
kind: NetworkPolicy
32+
metadata:
33+
name: scraper-policy
34+
namespace: olmv1-system
35+
spec:
36+
podSelector:
37+
matchLabels:
38+
metrics: scraper
39+
policyTypes:
40+
- Egress
41+
egress:
42+
- {} # Allows all egress traffic for metrics requests
43+
EOF
44+
```
2645
### Validating Access Manually
2746

2847
1. Generate a token for the service account and extract the required certificates:
@@ -41,6 +60,8 @@ kind: Pod
4160
metadata:
4261
name: curl-metrics
4362
namespace: olmv1-system
63+
labels:
64+
metrics: scraper
4465
spec:
4566
serviceAccountName: operator-controller-controller-manager
4667
containers:
@@ -69,6 +90,9 @@ spec:
6990
secretName: olmv1-cert
7091
securityContext:
7192
runAsNonRoot: true
93+
runAsUser: 65534
94+
seccompProfile:
95+
type: RuntimeDefault
7296
restartPolicy: Never
7397
EOF
7498
```
@@ -131,6 +155,8 @@ kind: Pod
131155
metadata:
132156
name: curl-metrics-catalogd
133157
namespace: olmv1-system
158+
labels:
159+
metrics: scraper
134160
spec:
135161
serviceAccountName: catalogd-controller-manager
136162
containers:
@@ -159,6 +185,9 @@ spec:
159185
secretName: $OLM_SECRET
160186
securityContext:
161187
runAsNonRoot: true
188+
runAsUser: 65534
189+
seccompProfile:
190+
type: RuntimeDefault
162191
restartPolicy: Never
163192
EOF
164193
```
@@ -253,7 +282,7 @@ metadata:
253282
spec:
254283
endpoints:
255284
- path: /metrics
256-
port: https
285+
port: metrics
257286
scheme: https
258287
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
259288
tlsConfig:
@@ -272,7 +301,7 @@ spec:
272301
key: tls.key
273302
selector:
274303
matchLabels:
275-
control-plane: catalogd-controller-manager
304+
app.kubernetes.io/name: catalogd
276305
EOF
277306
```
278307

0 commit comments

Comments
 (0)