add a metric for retroactive sc errors

This commit is contained in:
Roman Bednar 2022-09-16 10:43:38 +02:00
parent 256ade5aa4
commit 42422a1d16
2 changed files with 30 additions and 0 deletions

View File

@ -65,6 +65,8 @@ func Register(pvLister PVLister, pvcLister PVCLister, pluginMgr *volume.VolumePl
registerMetrics.Do(func() {
legacyregistry.CustomMustRegister(newPVAndPVCCountCollector(pvLister, pvcLister, pluginMgr))
legacyregistry.MustRegister(volumeOperationErrorsMetric)
legacyregistry.MustRegister(retroactiveStorageClassMetric)
legacyregistry.MustRegister(retroactiveStorageClassErrorMetric)
})
}
@ -122,6 +124,20 @@ var (
StabilityLevel: metrics.ALPHA,
},
[]string{"plugin_name", "operation_name"})
retroactiveStorageClassMetric = metrics.NewCounter(
&metrics.CounterOpts{
Name: "retroactive_storageclass_total",
Help: "Total number of retroactive StorageClass assignments to persistent volume claim",
StabilityLevel: metrics.ALPHA,
})
retroactiveStorageClassErrorMetric = metrics.NewCounter(
&metrics.CounterOpts{
Name: "retroactive_storageclass_errors_total",
Help: "Total number of failed retroactive StorageClass assignments to persistent volume claim",
StabilityLevel: metrics.ALPHA,
})
)
// volumeCount counts by PluginName and VolumeMode.
@ -231,6 +247,18 @@ func (collector *pvAndPVCCountCollector) pvcCollect(ch chan<- metrics.Metric) {
}
}
// RecordRetroactiveStorageClassMetric increments only retroactive_storageclass_total
// metric or both retroactive_storageclass_total and retroactive_storageclass_errors_total
// if success is false.
func RecordRetroactiveStorageClassMetric(success bool) {
if !success {
retroactiveStorageClassMetric.Inc()
retroactiveStorageClassErrorMetric.Inc()
} else {
retroactiveStorageClassMetric.Inc()
}
}
// RecordVolumeOperationErrorMetric records error count into metric
// volume_operation_total_errors for provisioning/deletion operations
func RecordVolumeOperationErrorMetric(pluginName, opName string) {

View File

@ -355,10 +355,12 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(ctx context.Context, cl
klog.V(4).Infof("FeatureGate[%s] is enabled, attempting to assign storage class to unbound PersistentVolumeClaim[%s]", features.RetroactiveDefaultStorageClass, claimToClaimKey(claim))
updated, err := ctrl.assignDefaultStorageClass(claim)
if err != nil {
metrics.RecordRetroactiveStorageClassMetric(false)
return fmt.Errorf("can't update PersistentVolumeClaim[%q]: %w", claimToClaimKey(claim), err)
}
if updated {
klog.V(4).Infof("PersistentVolumeClaim[%q] update successful, restarting claim sync", claimToClaimKey(claim))
metrics.RecordRetroactiveStorageClassMetric(true)
return nil
}
}