Skip to content

Commit e09df21

Browse files
committed
feat: create opt-in kube_persistentvolume_csi_attributes metric
Signed-off-by: João Vilaça <[email protected]>
1 parent 9facc36 commit e09df21

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

docs/persistentvolume-metrics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PersistentVolume Metrics
22

33
| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status |
4-
| ---------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
4+
|------------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
55
| kube_persistentvolume_annotations | Gauge | Kubernetes annotations converted to Prometheus labels controlled via [--metric-annotations-allowlist](./cli-arguments.md) | | `persistentvolume`=&lt;persistentvolume-name&gt; <br> `annotation_PERSISTENTVOLUME_ANNOTATION`=&lt;PERSISTENTVOLUME_ANNOTATION&gt; | EXPERIMENTAL |
66
| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=&lt;pv-name&gt; | STABLE |
77
| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=&lt;pv-name&gt; <br>`phase`=&lt;Bound\|Failed\|Pending\|Available\|Released&gt; | STABLE |
@@ -10,6 +10,7 @@
1010
| kube_persistentvolume_info | Gauge | Information about Persistent Volumes | | `persistentvolume`=&lt;pv-name&gt; <br> `storageclass`=&lt;storageclass-name&gt; <br> `gce_persistent_disk_name`=&lt;pd-name&gt; <br> `host_path`=&lt;path-of-a-host-volume&gt; <br> `host_path_type`=&lt;host-mount-type&gt; <br> `ebs_volume_id`=&lt;ebs-volume-id&gt; <br> `azure_disk_name`=&lt;azure-disk-name&gt; <br> `fc_wwids`=&lt;fc-wwids-comma-separated&gt; <br> `fc_lun`=&lt;fc-lun&gt; <br> `fc_target_wwns`=&lt;fc-target-wwns-comma-separated&gt; <br> `iscsi_target_portal`=&lt;iscsi-target-portal&gt; <br> `iscsi_iqn`=&lt;iscsi-iqn&gt; <br> `iscsi_lun`=&lt;iscsi-lun&gt; <br> `iscsi_initiator_name`=&lt;iscsi-initiator-name&gt; <br> `local_path`=&lt;path-of-a-local-volume&gt; <br> `local_fs`=&lt;local-volume-fs-type&gt; <br> `nfs_server`=&lt;nfs-server&gt; <br> `nfs_path`=&lt;nfs-path&gt; <br> `csi_driver`=&lt;csi-driver&gt; <br> `csi_volume_handle`=&lt;csi-volume-handle&gt; | STABLE |
1111
| kube_persistentvolume_created | Gauge | Unix creation timestamp | seconds | `persistentvolume`=&lt;persistentvolume-name&gt; <br> | EXPERIMENTAL |
1212
| kube_persistentvolume_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `persistentvolume`=&lt;persistentvolume-name&gt; <br> | EXPERIMENTAL |
13+
| kube_persistentvolume_csi_attributes | Gauge | CSI attributes of the Persistent Volume, disabled by default, manage with [--metric-opt-in-list](./cli-arguments.md)) | | `persistentvolume`=&lt;persistentvolume-name&gt; <br> `csi_mounter`=&lt;csi-mounter&gt; <br> `csi_map_options`=&lt;csi-map-options&gt; | EXPERIMENTAL |
1314

1415
## Useful metrics queries
1516

internal/store/persistentvolume.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var (
4343
descPersistentVolumeLabelsName = "kube_persistentvolume_labels"
4444
descPersistentVolumeLabelsHelp = "Kubernetes labels converted to Prometheus labels."
4545
descPersistentVolumeLabelsDefaultLabels = []string{"persistentvolume"}
46+
47+
descPersistentVolumeCSIAttributesName = "kube_persistentvolume_csi_attributes"
48+
descPersistentVolumeCSIAttributesHelp = "CSI attributes of the Persistent Volume."
4649
)
4750

4851
func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
@@ -349,6 +352,46 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
349352
}
350353
}),
351354
),
355+
*generator.NewOptInFamilyGenerator(
356+
descPersistentVolumeCSIAttributesName,
357+
descPersistentVolumeCSIAttributesHelp,
358+
metric.Gauge,
359+
basemetrics.ALPHA,
360+
"",
361+
wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family {
362+
if p.Spec.CSI == nil {
363+
return &metric.Family{
364+
Metrics: []*metric.Metric{},
365+
}
366+
}
367+
368+
var csiMounter, csiMapOptions string
369+
for k, v := range p.Spec.PersistentVolumeSource.CSI.VolumeAttributes {
370+
// storage attributes handled by external CEPH CSI driver
371+
if k == "mapOptions" {
372+
csiMapOptions = v
373+
} else if k == "mounter" {
374+
csiMounter = v
375+
}
376+
}
377+
378+
return &metric.Family{
379+
Metrics: []*metric.Metric{
380+
{
381+
LabelKeys: []string{
382+
"csi_mounter",
383+
"csi_map_options",
384+
},
385+
LabelValues: []string{
386+
csiMounter,
387+
csiMapOptions,
388+
},
389+
Value: 1,
390+
},
391+
},
392+
}
393+
}),
394+
),
352395
}
353396
}
354397

internal/store/persistentvolume_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,52 @@ func TestPersistentVolumeStore(t *testing.T) {
697697
`,
698698
MetricNames: []string{"kube_persistentvolume_deletion_timestamp"},
699699
},
700+
{
701+
Obj: &v1.PersistentVolume{
702+
ObjectMeta: metav1.ObjectMeta{
703+
Name: "test-pv-available",
704+
},
705+
Spec: v1.PersistentVolumeSpec{
706+
PersistentVolumeSource: v1.PersistentVolumeSource{
707+
CSI: &v1.CSIPersistentVolumeSource{
708+
Driver: "test-driver",
709+
VolumeHandle: "test-volume-handle",
710+
},
711+
},
712+
},
713+
},
714+
Want: `
715+
# HELP kube_persistentvolume_csi_attributes CSI attributes of the Persistent Volume.
716+
# TYPE kube_persistentvolume_csi_attributes gauge
717+
kube_persistentvolume_csi_attributes{persistentvolume="test-pv-available",csi_mounter="",csi_map_options=""} 1
718+
`,
719+
MetricNames: []string{"kube_persistentvolume_csi_attributes"},
720+
},
721+
{
722+
Obj: &v1.PersistentVolume{
723+
ObjectMeta: metav1.ObjectMeta{
724+
Name: "test-pv-available",
725+
},
726+
Spec: v1.PersistentVolumeSpec{
727+
PersistentVolumeSource: v1.PersistentVolumeSource{
728+
CSI: &v1.CSIPersistentVolumeSource{
729+
Driver: "test-driver",
730+
VolumeHandle: "test-volume-handle",
731+
VolumeAttributes: map[string]string{
732+
"mounter": "rbd",
733+
"mapOptions": "krbd:rxbounce",
734+
},
735+
},
736+
},
737+
},
738+
},
739+
Want: `
740+
# HELP kube_persistentvolume_csi_attributes CSI attributes of the Persistent Volume.
741+
# TYPE kube_persistentvolume_csi_attributes gauge
742+
kube_persistentvolume_csi_attributes{persistentvolume="test-pv-available",csi_mounter="rbd",csi_map_options="krbd:rxbounce"} 1
743+
`,
744+
MetricNames: []string{"kube_persistentvolume_csi_attributes"},
745+
},
700746
}
701747
for i, c := range cases {
702748
c.Func = generator.ComposeMetricGenFuncs(persistentVolumeMetricFamilies(c.AllowAnnotationsList, c.AllowLabelsList))

0 commit comments

Comments
 (0)