Skip to content

Commit 1a27741

Browse files
authored
Metrics Docs Maintenance (#2024)
Updates the docs around metrics gathering to include necessary NetworkPolicy, fixes some errors in the ServiceMonitor yaml for securityContext and catalogd labels, and makes the example curl commands easier to execute. Signed-off-by: Daniel Franz <[email protected]>
1 parent 0c9f0b5 commit 1a27741

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

docs/draft/howto/consuming-metrics.md

Lines changed: 44 additions & 23 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,28 +90,27 @@ spec:
6990
secretName: olmv1-cert
7091
securityContext:
7192
runAsNonRoot: true
93+
runAsUser: 1000
94+
seccompProfile:
95+
type: RuntimeDefault
7296
restartPolicy: Never
7397
EOF
7498
```
7599

76-
3. Access the pod:
100+
3. Run the following command using the `TOKEN` value obtained above to check the metrics:
77101

78102
```shell
79-
kubectl exec -it curl-metrics -n olmv1-system -- sh
80-
```
81-
82-
4. Run the following command using the `TOKEN` value obtained above to check the metrics:
83-
84-
```shell
85-
curl -v -k -H "Authorization: Bearer <TOKEN>" \
103+
kubectl exec -it curl-metrics -n olmv1-system -- \
104+
curl -v -k -H "Authorization: Bearer ${TOKEN}" \
86105
https://operator-controller-service.olmv1-system.svc.cluster.local:8443/metrics
87106
```
88107

89-
5. Run the following command to validate the certificates and token:
108+
4. Run the following command to validate the certificates and token:
90109

91110
```shell
111+
kubectl exec -it curl-metrics -n olmv1-system -- \
92112
curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \
93-
-H "Authorization: Bearer <TOKEN>" \
113+
-H "Authorization: Bearer ${TOKEN}" \
94114
https://operator-controller-service.olmv1-system.svc.cluster.local:8443/metrics
95115
```
96116

@@ -131,6 +151,8 @@ kind: Pod
131151
metadata:
132152
name: curl-metrics-catalogd
133153
namespace: olmv1-system
154+
labels:
155+
metrics: scraper
134156
spec:
135157
serviceAccountName: catalogd-controller-manager
136158
containers:
@@ -159,27 +181,26 @@ spec:
159181
secretName: $OLM_SECRET
160182
securityContext:
161183
runAsNonRoot: true
184+
runAsUser: 1000
185+
seccompProfile:
186+
type: RuntimeDefault
162187
restartPolicy: Never
163188
EOF
164189
```
165190

166-
4. Access the pod:
167-
168-
```shell
169-
kubectl exec -it curl-metrics-catalogd -n olmv1-system -- sh
170-
```
171-
172-
5. Run the following command using the `TOKEN` value obtained above to check the metrics:
191+
4. Run the following command using the `TOKEN` value obtained above to check the metrics:
173192

174193
```shell
175-
curl -v -k -H "Authorization: Bearer <TOKEN>" \
194+
kubectl exec -it curl-metrics -n olmv1-system -- \
195+
curl -v -k -H "Authorization: Bearer ${TOKEN}" \
176196
https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics
177197
```
178198

179-
6. Run the following command to validate the certificates and token:
199+
5. Run the following command to validate the certificates and token:
180200
```shell
201+
kubectl exec -it curl-metrics -n olmv1-system -- \
181202
curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \
182-
-H "Authorization: Bearer <TOKEN>" \
203+
-H "Authorization: Bearer ${TOKEN}" \
183204
https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics
184205
```
185206

@@ -253,7 +274,7 @@ metadata:
253274
spec:
254275
endpoints:
255276
- path: /metrics
256-
port: https
277+
port: metrics
257278
scheme: https
258279
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
259280
tlsConfig:
@@ -272,7 +293,7 @@ spec:
272293
key: tls.key
273294
selector:
274295
matchLabels:
275-
control-plane: catalogd-controller-manager
296+
app.kubernetes.io/name: catalogd
276297
EOF
277298
```
278299

0 commit comments

Comments
 (0)