@@ -202,6 +202,12 @@ func useVolumeCloning(req *csi.CreateVolumeRequest) bool {
202
202
203
203
func (gceCS * GCEControllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
204
204
var err error
205
+ diskTypeForMetric := ""
206
+ defer func () {
207
+ if err != nil {
208
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , diskTypeForMetric )
209
+ }
210
+ }()
205
211
// Validate arguments
206
212
volumeCapabilities := req .GetVolumeCapabilities ()
207
213
name := req .GetName ()
@@ -283,6 +289,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
283
289
284
290
// Validate if disk already exists
285
291
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
292
+ diskTypeForMetric = metrics .GetDiskType (existingDisk )
286
293
if err != nil {
287
294
if ! gce .IsGCEError (err , "notFound" ) {
288
295
return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
@@ -337,6 +344,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
337
344
338
345
// Verify that the volume in VolumeContentSource exists.
339
346
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
347
+ diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
340
348
if err != nil {
341
349
if gce .IsGCEError (err , "notFound" ) {
342
350
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -393,15 +401,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
393
401
394
402
// Create the disk
395
403
var disk * gce.CloudDisk
404
+ diskTypeForMetric = params .DiskType
396
405
switch params .ReplicationType {
397
406
case replicationTypeNone :
398
407
if len (zones ) != 1 {
399
408
return nil , status .Errorf (codes .Internal , "CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones )
400
409
}
401
410
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
402
411
if err != nil {
403
- // Emit metric for expected disk type from storage class
404
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
405
412
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
406
413
}
407
414
case replicationTypeRegionalPD :
@@ -410,8 +417,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
410
417
}
411
418
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
412
419
if err != nil {
413
- // Emit metric for expected disk type from storage class
414
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
415
420
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
416
421
}
417
422
default :
@@ -420,8 +425,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
420
425
421
426
ready , err := isDiskReady (disk )
422
427
if err != nil {
423
- // Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
424
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
425
428
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
426
429
}
427
430
if ! ready {
@@ -434,6 +437,13 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
434
437
}
435
438
436
439
func (gceCS * GCEControllerServer ) DeleteVolume (ctx context.Context , req * csi.DeleteVolumeRequest ) (* csi.DeleteVolumeResponse , error ) {
440
+ var err error
441
+ diskTypeForMetric := ""
442
+ defer func () {
443
+ if err != nil {
444
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteVolume" , err , diskTypeForMetric )
445
+ }
446
+ }()
437
447
// Validate arguments
438
448
volumeID := req .GetVolumeId ()
439
449
if len (volumeID ) == 0 {
@@ -449,6 +459,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
449
459
}
450
460
451
461
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
462
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
463
+ diskTypeForMetric = metrics .GetDiskType (disk )
452
464
if err != nil {
453
465
if gce .IsGCENotFoundError (err ) {
454
466
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -472,12 +484,20 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
472
484
}
473
485
474
486
func (gceCS * GCEControllerServer ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
487
+ var err error
488
+ diskTypeForMetric := ""
489
+ defer func () {
490
+ if err != nil {
491
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskTypeForMetric )
492
+ }
493
+ }()
475
494
// Only valid requests will be accepted
476
- _ , _ , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
495
+ project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
477
496
if err != nil {
478
497
return nil , err
479
498
}
480
-
499
+ diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
500
+ diskTypeForMetric = metrics .GetDiskType (diskToPublish )
481
501
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
482
502
if gceCS .errorBackoff .blocking (backoffId ) {
483
503
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -533,7 +553,6 @@ func parseMachineType(machineTypeUrl string) string {
533
553
534
554
func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
535
555
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
536
-
537
556
if err != nil {
538
557
return nil , err
539
558
}
@@ -562,9 +581,8 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
562
581
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
563
582
}
564
583
defer gceCS .volumeLocks .Release (lockingVolumeID )
565
- diskToPublish , err : = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
584
+ _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
566
585
if err != nil {
567
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
568
586
if gce .IsGCENotFoundError (err ) {
569
587
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
570
588
}
@@ -614,15 +632,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
614
632
machineType := parseMachineType (instance .MachineType )
615
633
return nil , status .Errorf (codes .InvalidArgument , "'%s' is not a compatible disk type with the machine type %s, please review the GCP online documentation for available persistent disk options" , udErr .DiskType , machineType )
616
634
}
617
- // Emit metric for error
618
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
619
635
return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
620
636
}
621
637
622
638
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
623
639
if err != nil {
624
- // Emit metric for error
625
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
626
640
return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
627
641
}
628
642
@@ -631,12 +645,20 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
631
645
}
632
646
633
647
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
634
- // Only valid requests will be queued
635
- _ , _ , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
648
+ var err error
649
+ diskTypeForMetric := ""
650
+ defer func () {
651
+ if err != nil {
652
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric )
653
+ }
654
+ }()
655
+ project , volKey , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
636
656
if err != nil {
637
657
return nil , err
638
658
}
639
-
659
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
660
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
661
+ // Only valid requests will be queued
640
662
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
641
663
if gceCS .errorBackoff .blocking (backoffId ) {
642
664
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -723,14 +745,8 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
723
745
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v. Already not attached." , volKey , nodeID )
724
746
return & csi.ControllerUnpublishVolumeResponse {}, nil
725
747
}
726
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
727
- if err != nil {
728
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
729
- common .LoggedError ("Failed to getDisk: " , err )
730
- }
731
748
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
732
749
if err != nil {
733
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
734
750
return nil , common .LoggedError ("Failed to detach: " , err )
735
751
}
736
752
@@ -739,6 +755,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
739
755
}
740
756
741
757
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
758
+ var err error
759
+ diskTypeForMetric := ""
760
+ defer func () {
761
+ if err != nil {
762
+ gceCS .Metrics .RecordOperationErrorMetrics ("ValidateVolumeCapabilities" , err , diskTypeForMetric )
763
+ }
764
+ }()
742
765
if req .GetVolumeCapabilities () == nil || len (req .GetVolumeCapabilities ()) == 0 {
743
766
return nil , status .Error (codes .InvalidArgument , "Volume Capabilities must be provided" )
744
767
}
@@ -750,7 +773,6 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
750
773
if err != nil {
751
774
return nil , status .Errorf (codes .InvalidArgument , "Volume ID is invalid: %v" , err .Error ())
752
775
}
753
-
754
776
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
755
777
if err != nil {
756
778
if gce .IsGCENotFoundError (err ) {
@@ -765,6 +787,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
765
787
defer gceCS .volumeLocks .Release (volumeID )
766
788
767
789
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
790
+ diskTypeForMetric = metrics .GetDiskType (disk )
768
791
if err != nil {
769
792
if gce .IsGCENotFoundError (err ) {
770
793
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
@@ -891,6 +914,13 @@ func (gceCS *GCEControllerServer) ControllerGetCapabilities(ctx context.Context,
891
914
}
892
915
893
916
func (gceCS * GCEControllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
917
+ var err error
918
+ diskTypeForMetric := ""
919
+ defer func () {
920
+ if err != nil {
921
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskTypeForMetric )
922
+ }
923
+ }()
894
924
// Validate arguments
895
925
volumeID := req .GetSourceVolumeId ()
896
926
if len (req .Name ) == 0 {
@@ -910,7 +940,8 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
910
940
defer gceCS .volumeLocks .Release (volumeID )
911
941
912
942
// Check if volume exists
913
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
943
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
944
+ diskTypeForMetric = metrics .GetDiskType (disk )
914
945
if err != nil {
915
946
if gce .IsGCENotFoundError (err ) {
916
947
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
@@ -948,10 +979,6 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
948
979
if err != nil {
949
980
return nil , status .Errorf (codes .InvalidArgument , "Invalid volume key: %v" , volKey )
950
981
}
951
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
952
- if err != nil {
953
- common .LoggedError ("Failed to getDisk: " , err )
954
- }
955
982
// Check if PD snapshot already exists
956
983
var snapshot * compute.Snapshot
957
984
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
@@ -963,17 +990,14 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
963
990
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
964
991
if err != nil {
965
992
if gce .IsGCEError (err , "notFound" ) {
966
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
967
993
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
968
994
}
969
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
970
995
return nil , common .LoggedError ("Failed to create snapshot: " , err )
971
996
}
972
997
}
973
998
974
999
err = gceCS .validateExistingSnapshot (snapshot , volKey )
975
1000
if err != nil {
976
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
977
1001
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
978
1002
}
979
1003
@@ -1127,6 +1151,13 @@ func isCSISnapshotReady(status string) (bool, error) {
1127
1151
}
1128
1152
1129
1153
func (gceCS * GCEControllerServer ) DeleteSnapshot (ctx context.Context , req * csi.DeleteSnapshotRequest ) (* csi.DeleteSnapshotResponse , error ) {
1154
+ var err error
1155
+ diskTypeForMetric := ""
1156
+ defer func () {
1157
+ if err != nil {
1158
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteSnapshot" , err , diskTypeForMetric )
1159
+ }
1160
+ }()
1130
1161
// Validate arguments
1131
1162
snapshotID := req .GetSnapshotId ()
1132
1163
if len (snapshotID ) == 0 {
@@ -1211,6 +1242,13 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1211
1242
}
1212
1243
1213
1244
func (gceCS * GCEControllerServer ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
1245
+ var err error
1246
+ diskTypeForMetric := ""
1247
+ defer func () {
1248
+ if err != nil {
1249
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskTypeForMetric )
1250
+ }
1251
+ }()
1214
1252
volumeID := req .GetVolumeId ()
1215
1253
if len (volumeID ) == 0 {
1216
1254
return nil , status .Error (codes .InvalidArgument , "ControllerExpandVolume volume ID must be provided" )
@@ -1225,22 +1263,17 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1225
1263
if err != nil {
1226
1264
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1227
1265
}
1228
-
1266
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1267
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1229
1268
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1230
1269
if err != nil {
1231
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1232
1270
if gce .IsGCENotFoundError (err ) {
1233
1271
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1234
1272
}
1235
1273
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1236
1274
}
1237
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1238
- if err != nil {
1239
- common .LoggedError ("Failed to getDisk: " , err )
1240
- }
1241
1275
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1242
1276
if err != nil {
1243
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1244
1277
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1245
1278
}
1246
1279
0 commit comments