@@ -41,6 +41,7 @@ import (
4141 "k8s.io/apimachinery/pkg/util/wait"
4242 "k8s.io/klog/v2"
4343 "k8s.io/utils/ptr"
44+ csiMetrics "sigs.k8s.io/azurefile-csi-driver/pkg/metrics"
4445 azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
4546 "sigs.k8s.io/cloud-provider-azure/pkg/metrics"
4647 "sigs.k8s.io/cloud-provider-azure/pkg/provider/storage"
@@ -515,6 +516,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
515516 requestName = "controller_create_volume_from_volume"
516517 }
517518 }
519+
520+ csiMC := csiMetrics .NewCSIMetricContext (requestName )
521+ isOperationSucceeded := false
522+ defer func () {
523+ csiMC .ObserveWithLabels (isOperationSucceeded ,
524+ "protocol" , string (shareProtocol ),
525+ "storage_account_type" , sku )
526+ }()
527+
518528 if sourceID != "" {
519529 _ , srcAccountName , _ , _ , _ , _ , err = GetFileShareInfo (sourceID ) //nolint:dogsled
520530 if err != nil {
@@ -558,7 +568,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
558568 }
559569
560570 mc := metrics .NewMetricContext (azureFileCSIDriverName , requestName , d .cloud .ResourceGroup , subsID , d .Name )
561- isOperationSucceeded := false
562571 defer func () {
563572 mc .ObserveOperationWithResult (isOperationSucceeded , VolumeID , volumeID )
564573 }()
@@ -782,6 +791,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
782791
783792// DeleteVolume delete an azure file
784793func (d * Driver ) DeleteVolume (ctx context.Context , req * csi.DeleteVolumeRequest ) (* csi.DeleteVolumeResponse , error ) {
794+ requestName := "controller_delete_volume"
795+ csiMC := csiMetrics .NewCSIMetricContext (requestName )
796+ isOperationSucceeded := false
797+ defer func () {
798+ csiMC .Observe (isOperationSucceeded )
799+ }()
800+
785801 volumeID := req .GetVolumeId ()
786802 if len (volumeID ) == 0 {
787803 return nil , status .Error (codes .InvalidArgument , "Volume ID missing in request" )
@@ -826,8 +842,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
826842 secret = createStorageAccountSecret (accountName , accountKey )
827843 }
828844
829- mc := metrics .NewMetricContext (azureFileCSIDriverName , "controller_delete_volume" , resourceGroupName , subsID , d .Name )
830- isOperationSucceeded := false
845+ mc := metrics .NewMetricContext (azureFileCSIDriverName , requestName , resourceGroupName , subsID , d .Name )
831846 defer func () {
832847 mc .ObserveOperationWithResult (isOperationSucceeded , VolumeID , volumeID )
833848 }()
@@ -937,6 +952,13 @@ func (d *Driver) ControllerUnpublishVolume(_ context.Context, _ *csi.ControllerU
937952
938953// CreateSnapshot create a snapshot
939954func (d * Driver ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
955+ requestName := "controller_create_snapshot"
956+ csiMC := csiMetrics .NewCSIMetricContext (requestName )
957+ isOperationSucceeded := false
958+ defer func () {
959+ csiMC .Observe (isOperationSucceeded )
960+ }()
961+
940962 sourceVolumeID := req .GetSourceVolumeId ()
941963 snapshotName := req .Name
942964 if len (snapshotName ) == 0 {
@@ -974,8 +996,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
974996 useDataPlaneAPI = d .useDataPlaneAPI (ctx , sourceVolumeID , accountName )
975997 }
976998
977- mc := metrics .NewMetricContext (azureFileCSIDriverName , "controller_create_snapshot" , rgName , subsID , d .Name )
978- isOperationSucceeded := false
999+ mc := metrics .NewMetricContext (azureFileCSIDriverName , requestName , rgName , subsID , d .Name )
9791000 defer func () {
9801001 mc .ObserveOperationWithResult (isOperationSucceeded , SourceResourceID , sourceVolumeID , SnapshotName , snapshotName )
9811002 }()
@@ -1088,6 +1109,13 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
10881109
10891110// DeleteSnapshot delete a snapshot (todo)
10901111func (d * Driver ) DeleteSnapshot (ctx context.Context , req * csi.DeleteSnapshotRequest ) (* csi.DeleteSnapshotResponse , error ) {
1112+ requestName := "controller_delete_snapshot"
1113+ csiMC := csiMetrics .NewCSIMetricContext (requestName )
1114+ isOperationSucceeded := false
1115+ defer func () {
1116+ csiMC .Observe (isOperationSucceeded )
1117+ }()
1118+
10911119 if len (req .SnapshotId ) == 0 {
10921120 return nil , status .Error (codes .InvalidArgument , "Snapshot ID must be provided" )
10931121 }
@@ -1109,8 +1137,7 @@ func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequ
11091137 subsID = d .cloud .SubscriptionID
11101138 }
11111139
1112- mc := metrics .NewMetricContext (azureFileCSIDriverName , "controller_delete_snapshot" , rgName , subsID , d .Name )
1113- isOperationSucceeded := false
1140+ mc := metrics .NewMetricContext (azureFileCSIDriverName , requestName , rgName , subsID , d .Name )
11141141 defer func () {
11151142 mc .ObserveOperationWithResult (isOperationSucceeded , SnapshotID , req .SnapshotId )
11161143 }()
@@ -1280,6 +1307,13 @@ func (d *Driver) execAzcopyCopy(srcPath, dstPath string, azcopyCopyOptions, auth
12801307
12811308// ControllerExpandVolume controller expand volume
12821309func (d * Driver ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
1310+ requestName := "controller_expand_volume"
1311+ csiMC := csiMetrics .NewCSIMetricContext (requestName )
1312+ isOperationSucceeded := false
1313+ defer func () {
1314+ csiMC .Observe (isOperationSucceeded )
1315+ }()
1316+
12831317 volumeID := req .GetVolumeId ()
12841318 if len (volumeID ) == 0 {
12851319 return nil , status .Error (codes .InvalidArgument , "Volume ID missing in request" )
@@ -1318,8 +1352,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
13181352 }
13191353 }
13201354
1321- mc := metrics .NewMetricContext (azureFileCSIDriverName , "controller_expand_volume" , resourceGroupName , subsID , d .Name )
1322- isOperationSucceeded := false
1355+ mc := metrics .NewMetricContext (azureFileCSIDriverName , requestName , resourceGroupName , subsID , d .Name )
13231356 defer func () {
13241357 mc .ObserveOperationWithResult (isOperationSucceeded , VolumeID , volumeID )
13251358 }()
@@ -1402,9 +1435,6 @@ func (d *Driver) snapshotExists(ctx context.Context, sourceVolumeID, snapshotNam
14021435
14031436 // List share snapshots.
14041437 listSnapshot := serviceURL .NewListSharesPager (& service.ListSharesOptions {Include : service.ListSharesInclude {Metadata : true , Snapshots : true }})
1405- if err != nil {
1406- return false , "" , time.Time {}, 0 , err
1407- }
14081438 for listSnapshot .More () {
14091439 response , err := listSnapshot .NextPage (ctx )
14101440 if err != nil {
0 commit comments