@@ -28,6 +28,7 @@ import (
28
28
"time"
29
29
30
30
volumehelper "sigs.k8s.io/blob-csi-driver/pkg/util"
31
+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
31
32
32
33
"github.com/Azure/azure-sdk-for-go/storage"
33
34
"github.com/container-storage-interface/spec/lib/go/csi"
@@ -475,13 +476,26 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
475
476
return nil , status .Error (codes .InvalidArgument , "NodeGetVolumeStats volume path was empty" )
476
477
}
477
478
479
+ // check if the volume stats is cached
480
+ cache , err := d .volStatsCache .Get (req .VolumeId , azcache .CacheReadTypeDefault )
481
+ if err != nil {
482
+ return nil , status .Errorf (codes .Internal , err .Error ())
483
+ }
484
+ if cache != nil {
485
+ resp := cache .(csi.NodeGetVolumeStatsResponse )
486
+ klog .V (6 ).Infof ("NodeGetVolumeStats: volume stats for volume %s path %s is cached" , req .VolumeId , req .VolumePath )
487
+ return & resp , nil
488
+ }
489
+
478
490
if _ , err := os .Lstat (req .VolumePath ); err != nil {
479
491
if os .IsNotExist (err ) {
480
492
return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
481
493
}
482
494
return nil , status .Errorf (codes .Internal , "failed to stat file %s: %v" , req .VolumePath , err )
483
495
}
484
496
497
+ klog .V (6 ).Infof ("NodeGetVolumeStats: begin to get VolumeStats on volume %s path %s" , req .VolumeId , req .VolumePath )
498
+
485
499
volumeMetrics , err := volume .NewMetricsStatFS (req .VolumePath ).GetMetrics ()
486
500
if err != nil {
487
501
return nil , status .Errorf (codes .Internal , "failed to get metrics: %v" , err )
@@ -513,7 +527,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
513
527
return nil , status .Errorf (codes .Internal , "failed to transform disk inodes used(%v)" , volumeMetrics .InodesUsed )
514
528
}
515
529
516
- return & csi.NodeGetVolumeStatsResponse {
530
+ resp := & csi.NodeGetVolumeStatsResponse {
517
531
Usage : []* csi.VolumeUsage {
518
532
{
519
533
Unit : csi .VolumeUsage_BYTES ,
@@ -528,7 +542,12 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
528
542
Used : inodesUsed ,
529
543
},
530
544
},
531
- }, nil
545
+ }
546
+
547
+ klog .V (6 ).Infof ("NodeGetVolumeStats: volume stats for volume %s path %s is %v" , req .VolumeId , req .VolumePath , resp )
548
+ // cache the volume stats per volume
549
+ d .volStatsCache .Set (req .VolumeId , * resp )
550
+ return resp , nil
532
551
}
533
552
534
553
// ensureMountPoint: create mount point if not exists
0 commit comments