Skip to content

Commit 6aa33b7

Browse files
FRosnerclaude
andcommitted
Add PVC metrics for VolumeAttributesClass (VAC) support
Expose the desired vs. currently-applied VolumeAttributesClass on a PersistentVolumeClaim, and the state of any in-progress ModifyVolume operation, via three new EXPERIMENTAL metrics: kube_persistentvolumeclaim_volume_attributes_class, kube_persistentvolumeclaim_status_current_volume_attributes_class, and kube_persistentvolumeclaim_status_modify_volume_status. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 88266e4 commit 6aa33b7

3 files changed

Lines changed: 149 additions & 12 deletions

File tree

docs/metrics/storage/persistentvolumeclaim-metrics.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
| kube_persistentvolumeclaim_status_phase | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `phase`=&lt;Pending\Bound\Lost&gt; | STABLE |
1212
| kube_persistentvolumeclaim_created | Gauge | Unix creation timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |
1313
| kube_persistentvolumeclaim_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |
14+
| kube_persistentvolumeclaim_volume_attributes_class | Gauge | The name of the VolumeAttributesClass requested by the persistent volume claim. | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `volume_attributes_class`=&lt;volume-attributes-class-name&gt; | EXPERIMENTAL |
15+
| kube_persistentvolumeclaim_status_current_volume_attributes_class | Gauge | The current VolumeAttributesClass applied to the persistent volume claim, as reported by the CSI driver. | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `volume_attributes_class`=&lt;volume-attributes-class-name&gt; | EXPERIMENTAL |
16+
| kube_persistentvolumeclaim_status_modify_volume_status | Gauge | Information about the status of an in-progress ModifyVolume operation on the persistent volume claim. | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `status`=&lt;Pending\InProgress\Infeasible&gt; <br> `target_volume_attributes_class`=&lt;volume-attributes-class-name&gt; | EXPERIMENTAL |
1417

1518
Note:
1619

internal/store/persistentvolumeclaim.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,94 @@ func persistentVolumeClaimMetricFamilies(allowAnnotationsList, allowLabelsList [
112112
}
113113
}),
114114
),
115+
*generator.NewFamilyGeneratorWithStability(
116+
"kube_persistentvolumeclaim_volume_attributes_class",
117+
"The name of the VolumeAttributesClass requested by the persistent volume claim.",
118+
metric.Gauge,
119+
basemetrics.ALPHA,
120+
"",
121+
wrapPersistentVolumeClaimFunc(func(p *v1.PersistentVolumeClaim) *metric.Family {
122+
volumeAttributesClassName := ""
123+
if p.Spec.VolumeAttributesClassName != nil {
124+
volumeAttributesClassName = *p.Spec.VolumeAttributesClassName
125+
}
126+
127+
return &metric.Family{
128+
Metrics: []*metric.Metric{
129+
{
130+
LabelKeys: []string{"volume_attributes_class"},
131+
LabelValues: []string{volumeAttributesClassName},
132+
Value: 1,
133+
},
134+
},
135+
}
136+
}),
137+
),
138+
*generator.NewFamilyGeneratorWithStability(
139+
"kube_persistentvolumeclaim_status_current_volume_attributes_class",
140+
"The current VolumeAttributesClass applied to the persistent volume claim, as reported by the CSI driver.",
141+
metric.Gauge,
142+
basemetrics.ALPHA,
143+
"",
144+
wrapPersistentVolumeClaimFunc(func(p *v1.PersistentVolumeClaim) *metric.Family {
145+
currentVolumeAttributesClassName := ""
146+
if p.Status.CurrentVolumeAttributesClassName != nil {
147+
currentVolumeAttributesClassName = *p.Status.CurrentVolumeAttributesClassName
148+
}
149+
150+
return &metric.Family{
151+
Metrics: []*metric.Metric{
152+
{
153+
LabelKeys: []string{"volume_attributes_class"},
154+
LabelValues: []string{currentVolumeAttributesClassName},
155+
Value: 1,
156+
},
157+
},
158+
}
159+
}),
160+
),
161+
*generator.NewFamilyGeneratorWithStability(
162+
"kube_persistentvolumeclaim_status_modify_volume_status",
163+
"Information about the status of an in-progress ModifyVolume operation on the persistent volume claim.",
164+
metric.Gauge,
165+
basemetrics.ALPHA,
166+
"",
167+
wrapPersistentVolumeClaimFunc(func(p *v1.PersistentVolumeClaim) *metric.Family {
168+
modifyVolumeStatus := p.Status.ModifyVolumeStatus
169+
170+
if modifyVolumeStatus == nil {
171+
return &metric.Family{
172+
Metrics: []*metric.Metric{},
173+
}
174+
}
175+
176+
status := modifyVolumeStatus.Status
177+
targetVolumeAttributesClass := modifyVolumeStatus.TargetVolumeAttributesClassName
178+
179+
ms := []*metric.Metric{
180+
{
181+
LabelValues: []string{string(v1.PersistentVolumeClaimModifyVolumePending), targetVolumeAttributesClass},
182+
Value: boolFloat64(status == v1.PersistentVolumeClaimModifyVolumePending),
183+
},
184+
{
185+
LabelValues: []string{string(v1.PersistentVolumeClaimModifyVolumeInProgress), targetVolumeAttributesClass},
186+
Value: boolFloat64(status == v1.PersistentVolumeClaimModifyVolumeInProgress),
187+
},
188+
{
189+
LabelValues: []string{string(v1.PersistentVolumeClaimModifyVolumeInfeasible), targetVolumeAttributesClass},
190+
Value: boolFloat64(status == v1.PersistentVolumeClaimModifyVolumeInfeasible),
191+
},
192+
}
193+
194+
for _, m := range ms {
195+
m.LabelKeys = []string{"status", "target_volume_attributes_class"}
196+
}
197+
198+
return &metric.Family{
199+
Metrics: ms,
200+
}
201+
}),
202+
),
115203
*generator.NewFamilyGeneratorWithStability(
116204
"kube_persistentvolumeclaim_status_phase",
117205
"The phase the persistent volume claim is currently in.",

0 commit comments

Comments
 (0)