feat(helm): add a ServiceMonitor for the controller metrics endpoint - #2401
feat(helm): add a ServiceMonitor for the controller metrics endpoint#2401younsl wants to merge 1 commit into
Conversation
EItanya
left a comment
There was a problem hiding this comment.
Do you think this can be added as an extraObject in you chart instead?
|
Good question, and one I should answer carefully since I am the one who added extraObjects in #2174 and argued there that PrometheusRule belongs in it. I still think that. I would put a ServiceMonitor on the other side of that line, and here is my reasoning. extraObjects works well when the content of the resource is org-specific and independent of the chart: ExternalSecret, NetworkPolicy, Istio Sidecar, PrometheusRule. This ServiceMonitor is a pointer at a Service the chart itself renders, so its endpoint is not user content but derived state. The port name (https vs http-metrics), scheme, tlsConfig and bearerTokenFile all follow controller.metrics.secureServing, the selector has to match kagent.controller.selectorLabels, and it has to stay unrendered under the METRICS_BIND_ADDRESS=0 sentinel. A copy in extraObjects has to hardcode those, and if someone later flips secureServing the scrape fails quietly: the manifest still applies, Prometheus just drops the target. That is the one thing I could not solve outside the chart, so this PR routes the port name through a shared helper that the Service and the ServiceMonitor both use. For context on scope, #1803 landed the Service and the RBAC and left this piece for a follow-up, with the same value path it suggested (controller.metrics.serviceMonitor.enabled). This PR is meant to be that follow-up, additive and changing nothing that #1803 shipped. #1369 asked for both halves, so the ServiceMonitor half is the part still outstanding. @danielorbach @Daniel-Vaz, a sanity check from you would help here: is this the shape you had in mind? Two smaller notes. The kagent-tools chart already has servicemonitor.yaml under tools.metrics.servicemonitor.*, so this would make the controller consistent with it. And there is precedent in the chart for opt-in resources that reference external CRDs, ui-httproute.yaml and openshift-route.yaml, if the Prometheus Operator dependency is the concern. It is disabled by default, so rendered output for existing installs is unchanged and helm unittest covers that. Happy to go smaller if the values surface is the issue: I can trim to what kagent-tools exposes (enabled, interval, scrapeTimeout, labels) and drop relabelings, metricRelabelings, annotations and the namespace override. And if you would still rather this live outside the chart, I am fine closing it and sending just the shared port-name helper plus a documented ServiceMonitor example in the extraObjects block of values.yaml, so at least the port name and scheme have one reference. Whichever you prefer. |
|
@younsl I'd advise against It comes down to who owns the contents. An I'm the one who punted this in #1803, and I was too cautious about dragging Prometheus Operator in. Nothing gets dragged in while the flag defaults to false, and In my personal opinion for this PR:
That last one's the real gap. In #1803 I bound Rendering a One last thing, and probably outside the scope of this pull-request: we're on track for three spellings of this in one umbrella: |
controller.metrics.enabled provisions the metrics Service and the ClusterRoles for authenticated scrapes, but stops short of the resource that makes Prometheus Operator actually scrape it, so every user running kube-prometheus-stack has to hand-write a ServiceMonitor outside the chart. The bundled kagent-tools subchart already ships one. Adds controller.metrics.serviceMonitor, off by default and gated on controller.metrics.enabled. Scrape settings (interval, scrapeTimeout, honorLabels, relabelings, metricRelabelings), extra labels/annotations and a namespace override are exposed; the endpoint defaults to https with the ServiceAccount token and insecureSkipVerify when secureServing is on, matching the self-signed certificate the controller serves, and both are overridable. The Service port name moves into a kagent.controller.metricsPortName helper shared with the ServiceMonitor endpoint so the two cannot drift when secureServing is flipped. Rendered output is unchanged. Signed-off-by: younsl <cysl@kakao.com>
bbfa434 to
e978fe6
Compare
|
Both CI failures are pre-existing on main, not from these chart changes. The same two jobs fail on main HEAD. |
Description
This adds native ServiceMonitor support to the kagent Helm chart so controller metrics are collected by Prometheus Operator out of the box.
This is the follow up that #1803 deferred. That PR landed the metrics Service and the scrape RBAC and closed #1369, but left the ServiceMonitor out of scope. #1802 carried one and was closed as a duplicate of #1803, so the ServiceMonitor half of #1369 was never reviewed on its own and no template for it exists in the chart today. This PR is additive on top of what #1803 merged and changes none of it.
Today controller.metrics.enabled provisions the metrics Service and the ClusterRoles for authenticated scrapes, but not the resource that makes Prometheus actually scrape them. Every user running kube-prometheus-stack has to hand write a ServiceMonitor outside the chart and keep its port name and namespace in sync with the chart by hand. The bundled kagent-tools subchart already ships one, so this closes the gap for the controller.
New values live under controller.metrics.serviceMonitor, disabled by default and gated on controller.metrics.enabled. Interval, scrape timeout, honorLabels, relabelings, metric relabelings, extra labels, annotations and a namespace override are exposed. With secure serving on, the endpoint defaults to https with the ServiceAccount token and insecureSkipVerify, which matches the self signed certificate the controller serves, and both are overridable.
The metrics Service port name moved into a shared helper used by both the Service and the ServiceMonitor endpoint, so the two cannot drift when secure serving is flipped. Rendered output for existing installs is unchanged.
Changelog
Added an optional Prometheus Operator ServiceMonitor for the controller metrics endpoint, configurable under controller.metrics.serviceMonitor.
Testing
Additional Notes
Rendering the ServiceMonitor does not authorize the scrape on its own. With secure serving, the metrics reader ClusterRole still has to be bound to the Prometheus ServiceAccount, which the values comment calls out.
The chart does not gate on the monitoring.coreos.com API being present, matching what kagent-tools does. The explicit opt in flag is the gate, so a missing CRD fails loudly at install time instead of silently dropping the resource during helm template.