feat: Add access mode metric for PersistentVolumes#2823
feat: Add access mode metric for PersistentVolumes#2823viragvoros wants to merge 3 commits intokubernetes:mainfrom
Conversation
|
Welcome @viragvoros! |
2b6ab10 to
17c531d
Compare
|
/assign |
Expose a kube_persistentvolume_access_mode metric that mirrors the existing PVC access mode metric. This allows consumers to filter and aggregate PersistentVolumes by access mode directly, without having to scrape kube_persistentvolumeclaim_access_mode. Using a small set of access-mode labels keeps cardinality low while still allowing PV metrics to be sliced by access mode. Signed-off-by: vvoeroes <virag.voeroes@inovex.de>
17c531d to
d01f7e8
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: viragvoros The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
I wonder if it's worth adding a new metric here or enhancing kube_persistentvolume_volume_mode instead? |
|
I considered merging There is also a cardinality consideration for metric consumers. If only a combined Users who need both dimensions can still correlate them via PV labels. |
There was a problem hiding this comment.
Pull request overview
This PR adds a new PersistentVolume metric (kube_persistentvolume_access_mode) to expose PV access modes directly (mirroring the existing PVC access mode metric), along with test coverage and documentation updates.
Changes:
- Add
kube_persistentvolume_access_modemetric generation in the PV store. - Extend PV store tests to validate emitted access mode samples.
- Document the new PV access mode metric in the storage metrics docs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/store/persistentvolume.go | Introduces a new metric family generator for PV access modes and wires it into the PV metric families list. |
| internal/store/persistentvolume_test.go | Adds a test case asserting the new metric output for a PV with multiple access modes. |
| docs/metrics/storage/persistentvolume-metrics.md | Documents the new kube_persistentvolume_access_mode metric in the PV metrics table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ms = append(ms, &metric.Metric{ | ||
| LabelKeys: []string{"access_mode"}, | ||
| LabelValues: []string{string(am)}, | ||
| Value: 1, | ||
| }) |
There was a problem hiding this comment.
The docs state that only the four official Kubernetes access modes are emitted, but this implementation emits whatever values appear in p.Spec.AccessModes without filtering. To keep behavior aligned with the docs (and to avoid potentially exposing unexpected/invalid values), restrict emission to the known modes (ReadWriteOnce, ReadOnlyMany, ReadWriteMany, ReadWriteOncePod) or update the docs to match the actual behavior.
| ms = append(ms, &metric.Metric{ | |
| LabelKeys: []string{"access_mode"}, | |
| LabelValues: []string{string(am)}, | |
| Value: 1, | |
| }) | |
| switch am { | |
| case v1.ReadWriteOnce, v1.ReadOnlyMany, v1.ReadWriteMany, v1.ReadWriteOncePod: | |
| ms = append(ms, &metric.Metric{ | |
| LabelKeys: []string{"access_mode"}, | |
| LabelValues: []string{string(am)}, | |
| Value: 1, | |
| }) | |
| default: | |
| // Ignore any non-standard or invalid access mode values to align with documented behavior. | |
| } |
| | kube_persistentvolume_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `persistentvolume`=<persistentvolume-name> <br> | EXPERIMENTAL | | ||
| | kube_persistentvolume_csi_attributes | Gauge | CSI attributes of the Persistent Volume, disabled by default, manage with [--metric-opt-in-list](../../developer/cli-arguments.md)) | | `persistentvolume`=<persistentvolume-name> <br> `csi_mounter`=<csi-mounter> <br> `csi_map_options`=<csi-map-options> | EXPERIMENTAL | | ||
| | kube_persistentvolume_volume_mode | Gauge | Volume Mode information for the PersistentVolume. | | `persistentvolume`=<persistentvolume-name> <br>`volumemode`=<volumemode> | EXPERIMENTAL | | ||
| | kube_persistentvolume_access_mode | Gauge | Access modes of the PersistentVolume. Only the four official access modes are emitted. | | `persistentvolume`=<persistentvolume-name> <br>`access_mode`=<ReadWriteOnce \| ReadOnlyMany \| ReadWriteMany \| ReadWriteOncePod> | STABLE | |
There was a problem hiding this comment.
In the metrics table, the access_mode value list is written using raw angle brackets (<...>), which can be interpreted as HTML and render incorrectly. Consider escaping the brackets (</>) to match the formatting used elsewhere in this doc, and ensure the wording matches the actual emission behavior (currently claims only official modes are emitted).
|
Hi @mrueg, thank you for the review. I updated the new metric to match the guidance for newly introduced metrics. Also fixed the docs formatting and removed the sentence that said only the four official access modes are emitted, as the implementation exposes the values in |
What this PR does / why we need it:
This PR adds a
kube_persistentvolume_access_modemetric that exposes the access modes ofPersistentVolumeobjects, in a way that mirrors the existing PVC access mode metric.At the moment, if we want to filter or aggregate PersistentVolumes by access mode (e.g.
ReadWriteOnce,ReadWriteMany,ReadOnlyMany), we have to rely onkube_persistentvolumeclaim_access_modeand join throughPVC metrics. That forces us to scrape the PVC access mode metrics even when we only care about PVs, and increases metric cardinality.
By exposing a dedicated PV access mode metric with a small label set, we can:
otherwise needed,
while still keeping metric cardinality low.
Details of the change
kube_persistentvolume_access_modemetric in the PV store:access_modelabel uses the standard Kubernetes accessmodes (
ReadWriteOnce,ReadOnlyMany,ReadWriteMany, etc.)internal/store/persistentvolume_test.goHow does this change affect the cardinality of KSM:
Previously, dashboards and alerts that needed PV access mode information had to join against PVC access mode metrics and therefore scrape
kube_persistentvolumeclaim_access_mode, which may have higher cardinality in large clusters.With
kube_persistentvolume_access_mode, users can query PV access modes directly from the PV metrics.