-
Notifications
You must be signed in to change notification settings - Fork 426
feat(helm): add metrics endpoint and ServiceMonitor support #1435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
optimus-fulcria
wants to merge
4
commits into
kagent-dev:main
Choose a base branch
from
optimus-fulcria:feat/helm-metrics-servicemonitor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+297
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e124bbf
feat(helm): add support for enabling metrics endpoint and optional Se…
optimus-fulcria e73deb7
fix: gate ServiceMonitor on CRD availability and add auth for secure …
optimus-fulcria 9119305
refactor: move metrics port to dedicated ClusterIP service
optimus-fulcria 2b22165
fix: address Copilot review feedback on ServiceMonitor auth and selec…
optimus-fulcria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| {{- if .Values.controller.metrics.enabled }} | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: {{ include "kagent.fullname" . }}-controller-metrics | ||
| namespace: {{ include "kagent.namespace" . }} | ||
| labels: | ||
| {{- include "kagent.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: metrics | ||
| spec: | ||
| type: ClusterIP | ||
| ports: | ||
| - port: {{ .Values.controller.metrics.port }} | ||
| targetPort: {{ .Values.controller.metrics.port }} | ||
| protocol: TCP | ||
| name: metrics | ||
| selector: | ||
| {{- include "kagent.controller.selectorLabels" . | nindent 4 }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| {{- if and .Values.controller.metrics.enabled .Values.controller.metrics.serviceMonitor.enabled (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") }} | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: ServiceMonitor | ||
| metadata: | ||
| name: {{ include "kagent.fullname" . }}-controller | ||
| namespace: {{ include "kagent.namespace" . }} | ||
| labels: | ||
| {{- include "kagent.controller.labels" . | nindent 4 }} | ||
| {{- with .Values.controller.metrics.serviceMonitor.additionalLabels }} | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| {{- include "kagent.selectorLabels" . | nindent 6 }} | ||
| app.kubernetes.io/component: metrics | ||
| endpoints: | ||
| - port: metrics | ||
| interval: {{ .Values.controller.metrics.serviceMonitor.interval }} | ||
| scrapeTimeout: {{ .Values.controller.metrics.serviceMonitor.scrapeTimeout }} | ||
| {{- if .Values.controller.metrics.secure }} | ||
| scheme: https | ||
| tlsConfig: | ||
| insecureSkipVerify: true | ||
| {{- with .Values.controller.metrics.serviceMonitor.bearerTokenSecret }} | ||
| bearerTokenSecret: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- else }} | ||
| bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- with .Values.controller.metrics.serviceMonitor.metricRelabelings }} | ||
| metricRelabelings: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.controller.metrics.serviceMonitor.relabelings }} | ||
| relabelings: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- end }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| suite: test controller servicemonitor | ||
| templates: | ||
| - controller-servicemonitor.yaml | ||
| tests: | ||
| - it: should not render when metrics are disabled | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: should not render when metrics enabled but serviceMonitor disabled | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.serviceMonitor.enabled: false | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: should not render when CRD is not available | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: should render when both metrics and serviceMonitor are enabled | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 1 | ||
| - isKind: | ||
| of: ServiceMonitor | ||
| - equal: | ||
| path: metadata.name | ||
| value: RELEASE-NAME-controller | ||
|
|
||
| - it: should have correct endpoint configuration | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.port: 9093 | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| controller.metrics.serviceMonitor.interval: 30s | ||
| controller.metrics.serviceMonitor.scrapeTimeout: 10s | ||
| asserts: | ||
| - equal: | ||
| path: spec.endpoints[0].port | ||
| value: metrics | ||
| - equal: | ||
| path: spec.endpoints[0].interval | ||
| value: 30s | ||
| - equal: | ||
| path: spec.endpoints[0].scrapeTimeout | ||
| value: 10s | ||
|
|
||
| - it: should use HTTPS scheme and default bearerTokenFile when metrics are secure | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.secure: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| asserts: | ||
| - equal: | ||
| path: spec.endpoints[0].scheme | ||
| value: https | ||
| - equal: | ||
| path: spec.endpoints[0].bearerTokenFile | ||
| value: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
| - isNull: | ||
| path: spec.endpoints[0].bearerTokenSecret | ||
|
|
||
| - it: should use bearerTokenSecret when configured for secure metrics | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.secure: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| controller.metrics.serviceMonitor.bearerTokenSecret: | ||
| name: my-prometheus-token | ||
| key: token | ||
| asserts: | ||
| - equal: | ||
| path: spec.endpoints[0].scheme | ||
| value: https | ||
| - equal: | ||
| path: spec.endpoints[0].bearerTokenSecret.name | ||
| value: my-prometheus-token | ||
| - equal: | ||
| path: spec.endpoints[0].bearerTokenSecret.key | ||
| value: token | ||
| - isNull: | ||
| path: spec.endpoints[0].bearerTokenFile | ||
|
|
||
| - it: should include additional labels | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| controller.metrics.serviceMonitor.additionalLabels: | ||
| release: prometheus | ||
| asserts: | ||
| - equal: | ||
| path: metadata.labels.release | ||
| value: prometheus | ||
|
|
||
| - it: should have correct selector labels | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| controller.metrics.enabled: true | ||
| controller.metrics.serviceMonitor.enabled: true | ||
| asserts: | ||
| - equal: | ||
| path: spec.selector.matchLabels["app.kubernetes.io/name"] | ||
| value: kagent | ||
| - equal: | ||
| path: spec.selector.matchLabels["app.kubernetes.io/instance"] | ||
| value: RELEASE-NAME | ||
| - equal: | ||
| path: spec.selector.matchLabels["app.kubernetes.io/component"] | ||
| value: metrics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
controller.metrics.secureis true, the controller enables controller-runtime’s authn/authz filter on the metrics endpoint. This ServiceMonitor config setsscheme: httpsbut does not configure any bearer token/auth settings, so Prometheus scrapes are likely to be rejected. Add an endpoint auth configuration (e.g.,bearerTokenFile) when secure metrics are enabled (and/or allow configuring the full endpoint auth block via values).