feat(helm): add metrics endpoint and optional ServiceMonitor support#1802
feat(helm): add metrics endpoint and optional ServiceMonitor support#1802mesutoezdil wants to merge 2 commits intokagent-dev:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Helm-chart support for exposing the controller’s existing metrics endpoint and optionally creating a Prometheus Operator ServiceMonitor, so observability can be enabled from chart values instead of manual env/service customization.
Changes:
- Adds
controller.metricsvalues for enabling metrics, choosing the port, configuring secure mode, and togglingServiceMonitorcreation. - Wires metrics settings into the controller ConfigMap, Deployment, and Service so the endpoint is exposed when enabled.
- Adds Helm unit tests covering Service, Deployment, and ServiceMonitor rendering for the new metrics options.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
helm/kagent/values.yaml |
Adds chart values for controller metrics and ServiceMonitor settings. |
helm/kagent/tests/controller-servicemonitor_test.yaml |
Adds render tests for the new ServiceMonitor template. |
helm/kagent/tests/controller-service_test.yaml |
Verifies the controller Service adds a metrics port when enabled. |
helm/kagent/tests/controller-deployment_test.yaml |
Verifies the controller Deployment/ConfigMap pick up metrics ports and env vars. |
helm/kagent/templates/controller-servicemonitor.yaml |
Introduces the optional Prometheus Operator ServiceMonitor. |
helm/kagent/templates/controller-service.yaml |
Exposes the metrics port on the controller Service. |
helm/kagent/templates/controller-deployment.yaml |
Exposes the metrics port on the controller container. |
helm/kagent/templates/controller-configmap.yaml |
Sets metrics-related env vars consumed by the controller. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,20 @@ | |||
| {{- if and .Values.controller.metrics.enabled .Values.controller.metrics.serviceMonitor.enabled }} | |||
| - port: metrics | ||
| interval: {{ .Values.controller.metrics.serviceMonitor.interval }} | ||
| scrapeTimeout: {{ .Values.controller.metrics.serviceMonitor.scrapeTimeout }} |
| metrics: | ||
| enabled: false | ||
| port: 9093 | ||
| secure: false |
| {{- if .Values.controller.metrics.enabled }} | ||
| - port: {{ .Values.controller.metrics.port }} | ||
| targetPort: {{ .Values.controller.metrics.port }} | ||
| protocol: TCP | ||
| name: metrics |
Adds controller.metrics values to enable the Prometheus metrics endpoint and optionally deploy a ServiceMonitor for Prometheus Operator. When controller.metrics.enabled is true the chart sets METRICS_BIND_ADDRESS and METRICS_SECURE env vars, exposes the metrics container port, and adds a named port to the controller Service. Setting controller.metrics.serviceMonitor.enabled to true additionally creates a ServiceMonitor resource. Closes kagent-dev#1369 Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
- Gate ServiceMonitor on Capabilities.APIVersions to avoid install failures on clusters without Prometheus Operator CRDs - Add scheme/tlsConfig to ServiceMonitor endpoint when secure=true - Document secure default and NodePort exposure in values.yaml Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
47384db to
2008de2
Compare
|
Hey — I've put up an alternative shape for #1369 in #1803. The main substantive difference is RBAC: the controller binary defaults The kubebuilder/operator-sdk default — and what the Both shapes should solve #1369; happy to converge in either direction if maintainers have a preference. |
Revives #1435 which was closed by stalebot. The controller already supports METRICS_BIND_ADDRESS and METRICS_SECURE via flags, this just wires them up properly in the chart.
When controller.metrics.enabled is true the chart sets the env vars, exposes the metrics port on the Deployment and Service, and optionally creates a ServiceMonitor for Prometheus Operator.
Usage:
Closes #1369