Skip to content

Commit 86e6868

Browse files
committed
feat(helm): add PodMonitors for the workloads that serve metrics
Six workloads serve a Prometheus endpoint on a pod port and nothing collects any of them. ate-api-server, atelet, the atenet router, the atenet egress and the k8s credential provider start the metrics server in serverboot; ate-controller serves controller-runtime's own on :8080, its default, since its ctrl.Options sets no Metrics field. The router and the egress each add a second port for their agentgateway container. Three of those pods carry prometheus.io/* annotations, which a Prometheus reads only when it is configured for pod-annotation discovery. A Prometheus Operator installation discovers PodMonitors instead and ignores the annotations, so on such an installation every one of these endpoints is served and none is collected. Add one PodMonitor per workload, off by default because the object needs the monitoring.coreos.com/v1 CRDs. The port name and the pod label are pinned per workload: no two metrics sources agree on the port name, and the credential provider's label is the substrate.fullname helper's output rather than the bare component name. A wrong name or label yields a monitor that matches nothing and reports no error. podcertificate-controller gets no monitor. It emits no metrics, which docs/metrics/substrate.yaml records under blind_spots. Run the new chart unit tests in helm-verify, which had no way to run them. Signed-off-by: Quentin Bisson <quentin@giantswarm.io>
1 parent c2e2e13 commit 86e6868

4 files changed

Lines changed: 307 additions & 0 deletions

File tree

‎.github/workflows/helm-verify.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ jobs:
3333
run: helm lint charts/substrate charts/substrate-crds
3434
- name: Verify committed manifests match the chart output
3535
run: make verify-helm-template
36+
- name: Install helm-unittest
37+
run: helm plugin install https://github.com/helm-unittest/helm-unittest --version v1.0.2
38+
- name: Run the chart unit tests
39+
run: helm unittest charts/substrate
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{{/*
2+
Copyright 2026 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/}}
16+
{{/*
17+
One PodMonitor per workload that serves metrics. Six do, from three sources,
18+
and no two agree on the port name:
19+
20+
ate-api-server, atelet, the atenet router, the atenet egress and the
21+
Kubernetes credential provider start the metrics server themselves
22+
(serverboot's StartMetricsServer). The first two name that port `prometheus`,
23+
the other three name it `metrics`.
24+
25+
ate-controller serves controller-runtime's own metrics server. Its
26+
ctrl.Options sets no Metrics field, and only BindAddress "0" disables that
27+
server, so it binds the default :8080 — the port its pod already declares as
28+
`metrics`. This endpoint carries the controller_runtime_* and workqueue_*
29+
families that docs/metrics/substrate.yaml lists under
30+
bridged_metric_families.
31+
32+
The router and the egress each run an agentgateway container of their own,
33+
serving its stats on a second port: `gw-metrics` on the router, `stats` on
34+
the egress. Those are the gateway's own metrics rather than the ate
35+
registry's, and they are as uncollected as the rest, so each of those two
36+
monitors carries both endpoints.
37+
38+
Only the first three carry prometheus.io/* annotations, and an annotation is
39+
read only by a Prometheus configured for pod-annotation discovery. A Prometheus
40+
Operator installation discovers PodMonitors instead and ignores annotations, so
41+
without these objects every one of these endpoints is served and none is
42+
collected.
43+
44+
A PodMonitor addresses a NAMED container port, so the name is per workload: one
45+
shared name would match some pods and silently miss the others. The pod label
46+
is per workload too — each carries a bare `app: <component>` except the
47+
credential provider, whose label is the substrate.fullname helper's output and
48+
so depends on the release name.
49+
50+
podcertificate-controller gets no monitor: it emits no metrics, which
51+
docs/metrics/substrate.yaml states under blind_spots.
52+
53+
One object per workload rather than one selecting several: an interval and a
54+
relabeling are a component's own, and the atelet is a DaemonSet whose series
55+
are per node.
56+
*/}}
57+
{{- if .Values.metrics.podMonitor.enabled }}
58+
{{- $components := list
59+
(dict "app" "ate-api-server" "ports" (list "prometheus"))
60+
(dict "app" "ate-controller" "ports" (list "metrics"))
61+
(dict "app" "atelet" "ports" (list "prometheus"))
62+
(dict "app" "atenet-egress" "ports" (list "metrics" "stats"))
63+
(dict "app" "atenet-router" "ports" (list "metrics" "gw-metrics"))
64+
(dict "app" "k8s-credential-provider" "ports" (list "metrics") "fullnameLabel" true)
65+
}}
66+
{{- range $components }}
67+
{{- $label := .app }}
68+
{{- if .fullnameLabel }}
69+
{{- $label = include "substrate.fullname" (list .app $) }}
70+
{{- end }}
71+
---
72+
apiVersion: monitoring.coreos.com/v1
73+
kind: PodMonitor
74+
metadata:
75+
name: {{ include "substrate.fullname" (list .app $) }}
76+
namespace: {{ $.Release.Namespace }}
77+
labels:
78+
app: {{ $label }}
79+
{{- with $.Values.metrics.podMonitor.labels }}
80+
{{- toYaml . | nindent 4 }}
81+
{{- end }}
82+
spec:
83+
selector:
84+
matchLabels:
85+
app: {{ $label }}
86+
namespaceSelector:
87+
matchNames:
88+
- {{ $.Release.Namespace }}
89+
podMetricsEndpoints:
90+
{{- range .ports }}
91+
- port: {{ . }}
92+
path: /metrics
93+
{{- with $.Values.metrics.podMonitor.interval }}
94+
interval: {{ . }}
95+
{{- end }}
96+
{{- end }}
97+
{{- end }}
98+
{{- end }}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# The PodMonitors of the six workloads that serve metrics. Two things here are
16+
# easy to get wrong and silent when wrong, so each is pinned per workload:
17+
#
18+
# the port NAME, because a PodMonitor addresses a named container port and no
19+
# two sources agree — ate-api-server and atelet name theirs `prometheus`, the
20+
# others `metrics`, and the agentgateway sidecars of the router and the
21+
# egress add `gw-metrics` and `stats`;
22+
#
23+
# the pod LABEL, because every workload carries a bare `app: <component>`
24+
# except the credential provider, whose label is the substrate.fullname
25+
# helper's output and so depends on the release name.
26+
#
27+
# A wrong name or label yields a monitor that matches nothing, and no error.
28+
suite: metrics PodMonitors
29+
templates:
30+
- podmonitor.yaml
31+
tests:
32+
- it: renders nothing by default
33+
asserts:
34+
- hasDocuments:
35+
count: 0
36+
37+
- it: renders one PodMonitor per workload that serves metrics
38+
set:
39+
metrics.podMonitor.enabled: true
40+
asserts:
41+
- hasDocuments:
42+
count: 6
43+
44+
- it: addresses the port name ate-api-server's pod declares
45+
set:
46+
metrics.podMonitor.enabled: true
47+
documentIndex: 0
48+
asserts:
49+
- isKind:
50+
of: PodMonitor
51+
- equal:
52+
path: spec.selector.matchLabels.app
53+
value: ate-api-server
54+
- equal:
55+
path: spec.podMetricsEndpoints[0].port
56+
value: prometheus
57+
- equal:
58+
path: spec.podMetricsEndpoints[0].path
59+
value: /metrics
60+
61+
- it: addresses ate-controller's controller-runtime metrics port
62+
set:
63+
metrics.podMonitor.enabled: true
64+
documentIndex: 1
65+
asserts:
66+
- equal:
67+
path: spec.selector.matchLabels.app
68+
value: ate-controller
69+
- equal:
70+
path: spec.podMetricsEndpoints[0].port
71+
value: metrics
72+
73+
- it: addresses the port name the atelet's pod declares
74+
set:
75+
metrics.podMonitor.enabled: true
76+
documentIndex: 2
77+
asserts:
78+
- equal:
79+
path: spec.selector.matchLabels.app
80+
value: atelet
81+
- equal:
82+
path: spec.podMetricsEndpoints[0].port
83+
value: prometheus
84+
85+
- it: scrapes both the egress ext-proc and its agentgateway sidecar
86+
set:
87+
metrics.podMonitor.enabled: true
88+
documentIndex: 3
89+
asserts:
90+
- equal:
91+
path: spec.selector.matchLabels.app
92+
value: atenet-egress
93+
- equal:
94+
path: spec.podMetricsEndpoints[0].port
95+
value: metrics
96+
- equal:
97+
path: spec.podMetricsEndpoints[1].port
98+
value: stats
99+
100+
- it: scrapes both the router and its agentgateway sidecar
101+
set:
102+
metrics.podMonitor.enabled: true
103+
documentIndex: 4
104+
asserts:
105+
- equal:
106+
path: spec.selector.matchLabels.app
107+
value: atenet-router
108+
- equal:
109+
path: spec.podMetricsEndpoints[0].port
110+
value: metrics
111+
- equal:
112+
path: spec.podMetricsEndpoints[1].port
113+
value: gw-metrics
114+
115+
# The credential provider's pod label is the substrate.fullname helper's
116+
# output, not the bare component name: bare under the canonical release name
117+
# `substrate`, release-prefixed under any other. Both are pinned, because a
118+
# label that does not track the helper yields a monitor matching nothing.
119+
- it: selects the credential provider by the bare name under the canonical release
120+
set:
121+
metrics.podMonitor.enabled: true
122+
release:
123+
name: substrate
124+
documentIndex: 5
125+
asserts:
126+
- equal:
127+
path: spec.selector.matchLabels.app
128+
value: k8s-credential-provider
129+
- equal:
130+
path: spec.podMetricsEndpoints[0].port
131+
value: metrics
132+
133+
- it: selects the credential provider by the prefixed name under any other release
134+
set:
135+
metrics.podMonitor.enabled: true
136+
release:
137+
name: ate
138+
documentIndex: 5
139+
asserts:
140+
- equal:
141+
path: metadata.name
142+
value: ate-k8s-credential-provider
143+
- equal:
144+
path: spec.selector.matchLabels.app
145+
value: ate-k8s-credential-provider
146+
147+
- it: scopes every monitor to the release namespace
148+
set:
149+
metrics.podMonitor.enabled: true
150+
release:
151+
namespace: ate-system
152+
asserts:
153+
- equal:
154+
path: metadata.namespace
155+
value: ate-system
156+
- equal:
157+
path: spec.namespaceSelector.matchNames[0]
158+
value: ate-system
159+
160+
- it: leaves the interval out when it is unset, so Prometheus' own default holds
161+
set:
162+
metrics.podMonitor.enabled: true
163+
asserts:
164+
- notExists:
165+
path: spec.podMetricsEndpoints[0].interval
166+
167+
- it: carries the interval on every endpoint, and the discovery labels
168+
set:
169+
metrics.podMonitor.enabled: true
170+
metrics.podMonitor.interval: 60s
171+
metrics.podMonitor.labels:
172+
release: prometheus
173+
documentIndex: 4
174+
asserts:
175+
- equal:
176+
path: spec.podMetricsEndpoints[0].interval
177+
value: 60s
178+
- equal:
179+
path: spec.podMetricsEndpoints[1].interval
180+
value: 60s
181+
- equal:
182+
path: metadata.labels.release
183+
value: prometheus

‎charts/substrate/values.yaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ credentialProvider:
7878
# Mounted via envFrom with optional=true. Created by the chart from these values.
7979
ateApiServerEnvVarsConfigMap: ate-api-server-envvars
8080

81+
# Prometheus metrics. Six workloads serve /metrics on a pod port: ate-api-server,
82+
# atelet, the atenet router, the atenet egress and the credential provider start
83+
# the metrics server themselves, and ate-controller serves controller-runtime's
84+
# own on :8080, its default. The router and the egress each add a second port for
85+
# their agentgateway container's stats.
86+
#
87+
# Only the first three carry prometheus.io/* annotations, which a Prometheus reads
88+
# only when it does pod-annotation discovery. A Prometheus Operator installation
89+
# discovers PodMonitors instead, so turn these on there or every endpoint is
90+
# served and none is collected.
91+
metrics:
92+
podMonitor:
93+
# Requires the monitoring.coreos.com/v1 CRDs. Off by default: the object
94+
# does not apply on a cluster without the Prometheus Operator.
95+
enabled: false
96+
# Scrape interval. Empty leaves Prometheus' own default.
97+
interval: ""
98+
# Labels on every PodMonitor. Set whatever the Prometheus' or the agent's
99+
# podMonitorSelector matches on, and any tenant label a multi-tenant
100+
# backend routes by.
101+
labels: {}
102+
81103
# OTLP export, following the OpenTelemetry SDK environment variable spec.
82104
# endpoint applies to every signal; a signal's own endpoint overrides it.
83105
# A signal exports only when it is enabled and resolves to an endpoint.

0 commit comments

Comments
 (0)