Repository navigation
Add prometheus metrics #248
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
alicefr
wants to merge
8
commits into
bootc-dev:main
Choose a base branch
from
alicefr:prometheus
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e035ead
feat: add Prometheus metrics collector for pools and nodes
alicefr f9b0a40
test: add unit tests for metrics collector
alicefr c0cded0
feat: add metrics Service, ServiceMonitor, and RBAC
alicefr e9a1496
test: add envtest tests for metrics collector
alicefr 0363f0e
test: add e2e test for metrics endpoint scraping
alicefr b7d8f44
docs: add docs for monitoring
alicefr 078bf8d
fix: gate metrics flag and port on metrics.enabled in Helm chart
alicefr be5de9c
fix: schedule metrics curl pod on the controller node
alicefr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| {{- if .Values.metrics.enabled }} | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: {{ include "bootc-operator.fullname" . }}-metrics-auth | ||
| labels: | ||
| {{- include "bootc-operator.labels" . | nindent 4 }} | ||
| rules: | ||
| - apiGroups: | ||
| - authentication.k8s.io | ||
| resources: | ||
| - tokenreviews | ||
| verbs: | ||
| - create | ||
| - apiGroups: | ||
| - authorization.k8s.io | ||
| resources: | ||
| - subjectaccessreviews | ||
| verbs: | ||
| - create | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: {{ include "bootc-operator.fullname" . }}-metrics-auth | ||
| labels: | ||
| {{- include "bootc-operator.labels" . | nindent 4 }} | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: {{ include "bootc-operator.fullname" . }}-metrics-auth | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: {{ include "bootc-operator.fullname" . }}-controller | ||
| namespace: {{ .Release.Namespace }} | ||
| {{- 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,13 @@ | ||
| {{- if .Values.metrics.enabled }} | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: {{ include "bootc-operator.fullname" . }}-metrics-reader | ||
| labels: | ||
| {{- include "bootc-operator.labels" . | nindent 4 }} | ||
| rules: | ||
| - nonResourceURLs: | ||
| - /metrics | ||
| verbs: | ||
| - get | ||
| {{- 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,18 @@ | ||
| {{- if .Values.metrics.enabled }} | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: {{ include "bootc-operator.fullname" . }}-metrics | ||
| labels: | ||
| {{- include "bootc-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: controller | ||
| spec: | ||
| ports: | ||
| - name: https | ||
| port: {{ .Values.metrics.service.port }} | ||
| targetPort: metrics | ||
| protocol: TCP | ||
| selector: | ||
| app.kubernetes.io/name: {{ include "bootc-operator.name" . }} | ||
| app.kubernetes.io/component: controller | ||
| {{- end }} |
26 changes: 26 additions & 0 deletions
26
chart/bootc-operator/templates/metrics-servicemonitor.yaml
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,26 @@ | ||
| {{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: ServiceMonitor | ||
| metadata: | ||
| name: {{ include "bootc-operator.fullname" . }} | ||
| {{- if .Values.metrics.serviceMonitor.namespace }} | ||
| namespace: {{ .Values.metrics.serviceMonitor.namespace }} | ||
| {{- end }} | ||
| labels: | ||
| {{- include "bootc-operator.labels" . | nindent 4 }} | ||
| spec: | ||
| endpoints: | ||
| - port: https | ||
| scheme: https | ||
| interval: {{ .Values.metrics.serviceMonitor.interval }} | ||
| bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
| tlsConfig: | ||
| insecureSkipVerify: true | ||
| selector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: {{ include "bootc-operator.name" . }} | ||
| app.kubernetes.io/component: controller | ||
| namespaceSelector: | ||
| matchNames: | ||
| - {{ .Release.Namespace }} | ||
| {{- 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
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,17 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: metrics-auth-role | ||
| rules: | ||
| - apiGroups: | ||
| - authentication.k8s.io | ||
| resources: | ||
| - tokenreviews | ||
| verbs: | ||
| - create | ||
| - apiGroups: | ||
| - authorization.k8s.io | ||
| resources: | ||
| - subjectaccessreviews | ||
| verbs: | ||
| - create |
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,12 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: metrics-auth-rolebinding | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: metrics-auth-role | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: controller-manager | ||
| namespace: system |
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,9 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: metrics-reader | ||
| rules: | ||
| - nonResourceURLs: | ||
| - /metrics | ||
| verbs: | ||
| - get |
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,84 @@ | ||
| # Monitoring | ||
|
|
||
| The Bootc Operator exposes Prometheus metrics on a secure HTTPS | ||
| endpoint. This guide covers how to set up Prometheus and Grafana to | ||
| scrape and visualize the operator metrics. | ||
|
|
||
| ## Exposed metrics | ||
|
|
||
| The operator exposes the following custom metrics: | ||
|
|
||
| | Metric | Type | Labels | Description | | ||
| |--------|------|--------|-------------| | ||
| | `bootcoperator_pool_nodes_total` | Gauge | `pool` | Total number of nodes in a BootcNodePool | | ||
| | `bootcoperator_pool_nodes_updated` | Gauge | `pool` | Nodes running the target digest | | ||
| | `bootcoperator_pool_nodes_updating` | Gauge | `pool` | Nodes actively being updated | | ||
| | `bootcoperator_pool_nodes_degraded` | Gauge | `pool` | Nodes in a degraded state | | ||
| | `bootcoperator_pool_rollout_paused` | Gauge | `pool` | Whether rollout is paused (0 or 1) | | ||
| | `bootcoperator_node_booted_image_info` | Gauge | `node`, `pool`, `image`, `digest`, `version` | Info metric for the booted OS image | | ||
|
|
||
| In addition to these custom metrics, the operator exposes standard | ||
| controller-runtime metrics (workqueue depth, reconcile duration, etc.). | ||
|
|
||
| ## Enabling the ServiceMonitor | ||
|
|
||
| The Helm chart includes a `ServiceMonitor` resource that tells | ||
| Prometheus where to scrape. Enable it during install or upgrade: | ||
|
|
||
| ```bash | ||
| helm upgrade --install bootc-operator \ | ||
| oci://ghcr.io/bootc-dev/bootc-operator/charts/bootc-operator \ | ||
| --namespace bootc-operator \ | ||
| --set metrics.serviceMonitor.enabled=true | ||
| ``` | ||
|
|
||
| Verify the ServiceMonitor was created: | ||
|
|
||
| ```bash | ||
| kubectl -n bootc-operator get servicemonitor | ||
| ``` | ||
|
|
||
| ## Installing Prometheus and Grafana | ||
|
|
||
| The recommended way to deploy Prometheus and Grafana is the | ||
| [kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) | ||
| Helm chart: | ||
|
|
||
| ```bash | ||
| helm repo add prometheus-community \ | ||
| https://prometheus-community.github.io/helm-charts | ||
| helm repo update | ||
|
|
||
| helm install monitoring prometheus-community/kube-prometheus-stack \ | ||
| --namespace monitoring --create-namespace \ | ||
| --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false | ||
| ``` | ||
|
|
||
| Setting `serviceMonitorSelectorNilUsesHelmValues=false` allows | ||
| Prometheus to discover ServiceMonitors from all namespaces, including | ||
| `bootc-operator`. | ||
|
|
||
| ## Granting Prometheus access to the metrics endpoint | ||
|
|
||
| The operator metrics endpoint requires authentication. The Helm chart | ||
| creates a `ClusterRole` called `<release>-metrics-reader` that grants | ||
| `GET` access to `/metrics`. Bind it to the Prometheus ServiceAccount: | ||
|
|
||
| ```bash | ||
| kubectl create clusterrolebinding prometheus-metrics-reader \ | ||
| --clusterrole=bootc-operator-metrics-reader \ | ||
| --serviceaccount=monitoring:monitoring-kube-prometheus-prometheus | ||
| ``` | ||
|
|
||
| Adjust the ServiceAccount name if your Prometheus installation uses a | ||
| different one. | ||
|
|
||
| ## Helm values reference | ||
|
|
||
| | Key | Default | Description | | ||
| |-----|---------|-------------| | ||
| | `metrics.enabled` | `true` | Deploy the metrics Service | | ||
| | `metrics.service.port` | `8443` | Service port for the metrics endpoint | | ||
| | `metrics.serviceMonitor.enabled` | `false` | Create a ServiceMonitor resource | | ||
| | `metrics.serviceMonitor.interval` | `30s` | Scrape interval | | ||
| | `metrics.serviceMonitor.namespace` | `""` | Namespace for the ServiceMonitor (defaults to release namespace) | |
Oops, something went wrong.
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.
We enable the metrics listener here, but config/default doesn’t include a metrics Service