@@ -194,6 +194,12 @@ func useVolumeCloning(req *csi.CreateVolumeRequest) bool {
194
194
195
195
func (gceCS * GCEControllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
196
196
var err error
197
+ diskTypeForMetric := ""
198
+ defer func () {
199
+ if err != nil {
200
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , diskTypeForMetric )
201
+ }
202
+ }()
197
203
// Validate arguments
198
204
volumeCapabilities := req .GetVolumeCapabilities ()
199
205
name := req .GetName ()
@@ -275,6 +281,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
275
281
276
282
// Validate if disk already exists
277
283
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
284
+ diskTypeForMetric = metrics .GetDiskType (existingDisk )
278
285
if err != nil {
279
286
if ! gce .IsGCEError (err , "notFound" ) {
280
287
return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
@@ -329,6 +336,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
329
336
330
337
// Verify that the volume in VolumeContentSource exists.
331
338
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
339
+ diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
332
340
if err != nil {
333
341
if gce .IsGCEError (err , "notFound" ) {
334
342
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -385,15 +393,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
385
393
386
394
// Create the disk
387
395
var disk * gce.CloudDisk
396
+ diskTypeForMetric = params .DiskType
388
397
switch params .ReplicationType {
389
398
case replicationTypeNone :
390
399
if len (zones ) != 1 {
391
400
return nil , status .Errorf (codes .Internal , "CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones )
392
401
}
393
402
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
394
403
if err != nil {
395
- // Emit metric for expected disk type from storage class
396
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
397
404
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
398
405
}
399
406
case replicationTypeRegionalPD :
@@ -402,8 +409,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
402
409
}
403
410
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
404
411
if err != nil {
405
- // Emit metric for expected disk type from storage class
406
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
407
412
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
408
413
}
409
414
default :
@@ -412,8 +417,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
412
417
413
418
ready , err := isDiskReady (disk )
414
419
if err != nil {
415
- // Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
416
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
417
420
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
418
421
}
419
422
if ! ready {
@@ -426,6 +429,13 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
426
429
}
427
430
428
431
func (gceCS * GCEControllerServer ) DeleteVolume (ctx context.Context , req * csi.DeleteVolumeRequest ) (* csi.DeleteVolumeResponse , error ) {
432
+ var err error
433
+ diskTypeForMetric := ""
434
+ defer func () {
435
+ if err != nil {
436
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteVolume" , err , diskTypeForMetric )
437
+ }
438
+ }()
429
439
// Validate arguments
430
440
volumeID := req .GetVolumeId ()
431
441
if len (volumeID ) == 0 {
@@ -441,6 +451,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
441
451
}
442
452
443
453
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
454
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
455
+ diskTypeForMetric = metrics .GetDiskType (disk )
444
456
if err != nil {
445
457
if gce .IsGCENotFoundError (err ) {
446
458
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -464,12 +476,20 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
464
476
}
465
477
466
478
func (gceCS * GCEControllerServer ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
479
+ var err error
480
+ diskTypeForMetric := ""
481
+ defer func () {
482
+ if err != nil {
483
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskTypeForMetric )
484
+ }
485
+ }()
467
486
// Only valid requests will be accepted
468
- _ , _ , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
487
+ project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
469
488
if err != nil {
470
489
return nil , err
471
490
}
472
-
491
+ diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
492
+ diskTypeForMetric = metrics .GetDiskType (diskToPublish )
473
493
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
474
494
if gceCS .errorBackoff .blocking (backoffId ) {
475
495
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -525,7 +545,6 @@ func parseMachineType(machineTypeUrl string) string {
525
545
526
546
func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
527
547
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
528
-
529
548
if err != nil {
530
549
return nil , err
531
550
}
@@ -554,9 +573,8 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
554
573
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
555
574
}
556
575
defer gceCS .volumeLocks .Release (lockingVolumeID )
557
- diskToPublish , err : = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
576
+ _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
558
577
if err != nil {
559
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
560
578
if gce .IsGCENotFoundError (err ) {
561
579
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
562
580
}
@@ -606,15 +624,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
606
624
machineType := parseMachineType (instance .MachineType )
607
625
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 )
608
626
}
609
- // Emit metric for error
610
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
611
627
return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
612
628
}
613
629
614
630
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
615
631
if err != nil {
616
- // Emit metric for error
617
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
618
632
return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
619
633
}
620
634
@@ -623,12 +637,20 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
623
637
}
624
638
625
639
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
626
- // Only valid requests will be queued
627
- _ , _ , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
640
+ var err error
641
+ diskTypeForMetric := ""
642
+ defer func () {
643
+ if err != nil {
644
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric )
645
+ }
646
+ }()
647
+ project , volKey , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
628
648
if err != nil {
629
649
return nil , err
630
650
}
631
-
651
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
652
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
653
+ // Only valid requests will be queued
632
654
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
633
655
if gceCS .errorBackoff .blocking (backoffId ) {
634
656
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -715,14 +737,8 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
715
737
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v. Already not attached." , volKey , nodeID )
716
738
return & csi.ControllerUnpublishVolumeResponse {}, nil
717
739
}
718
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
719
- if err != nil {
720
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
721
- common .LoggedError ("Failed to getDisk: " , err )
722
- }
723
740
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
724
741
if err != nil {
725
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
726
742
return nil , common .LoggedError ("Failed to detach: " , err )
727
743
}
728
744
@@ -731,6 +747,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
731
747
}
732
748
733
749
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
750
+ var err error
751
+ diskTypeForMetric := ""
752
+ defer func () {
753
+ if err != nil {
754
+ gceCS .Metrics .RecordOperationErrorMetrics ("ValidateVolumeCapabilities" , err , diskTypeForMetric )
755
+ }
756
+ }()
734
757
if req .GetVolumeCapabilities () == nil || len (req .GetVolumeCapabilities ()) == 0 {
735
758
return nil , status .Error (codes .InvalidArgument , "Volume Capabilities must be provided" )
736
759
}
@@ -742,7 +765,6 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
742
765
if err != nil {
743
766
return nil , status .Errorf (codes .InvalidArgument , "Volume ID is invalid: %v" , err .Error ())
744
767
}
745
-
746
768
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
747
769
if err != nil {
748
770
if gce .IsGCENotFoundError (err ) {
@@ -757,6 +779,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
757
779
defer gceCS .volumeLocks .Release (volumeID )
758
780
759
781
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
782
+ diskTypeForMetric = metrics .GetDiskType (disk )
760
783
if err != nil {
761
784
if gce .IsGCENotFoundError (err ) {
762
785
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
@@ -883,6 +906,13 @@ func (gceCS *GCEControllerServer) ControllerGetCapabilities(ctx context.Context,
883
906
}
884
907
885
908
func (gceCS * GCEControllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
909
+ var err error
910
+ diskTypeForMetric := ""
911
+ defer func () {
912
+ if err != nil {
913
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskTypeForMetric )
914
+ }
915
+ }()
886
916
// Validate arguments
887
917
volumeID := req .GetSourceVolumeId ()
888
918
if len (req .Name ) == 0 {
@@ -902,7 +932,8 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
902
932
defer gceCS .volumeLocks .Release (volumeID )
903
933
904
934
// Check if volume exists
905
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
935
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
936
+ diskTypeForMetric = metrics .GetDiskType (disk )
906
937
if err != nil {
907
938
if gce .IsGCENotFoundError (err ) {
908
939
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
@@ -940,10 +971,6 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
940
971
if err != nil {
941
972
return nil , status .Errorf (codes .InvalidArgument , "Invalid volume key: %v" , volKey )
942
973
}
943
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
944
- if err != nil {
945
- common .LoggedError ("Failed to getDisk: " , err )
946
- }
947
974
// Check if PD snapshot already exists
948
975
var snapshot * compute.Snapshot
949
976
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
@@ -955,17 +982,14 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
955
982
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
956
983
if err != nil {
957
984
if gce .IsGCEError (err , "notFound" ) {
958
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
959
985
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
960
986
}
961
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
962
987
return nil , common .LoggedError ("Failed to create snapshot: " , err )
963
988
}
964
989
}
965
990
966
991
err = gceCS .validateExistingSnapshot (snapshot , volKey )
967
992
if err != nil {
968
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
969
993
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
970
994
}
971
995
@@ -1119,6 +1143,13 @@ func isCSISnapshotReady(status string) (bool, error) {
1119
1143
}
1120
1144
1121
1145
func (gceCS * GCEControllerServer ) DeleteSnapshot (ctx context.Context , req * csi.DeleteSnapshotRequest ) (* csi.DeleteSnapshotResponse , error ) {
1146
+ var err error
1147
+ diskTypeForMetric := ""
1148
+ defer func () {
1149
+ if err != nil {
1150
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteSnapshot" , err , diskTypeForMetric )
1151
+ }
1152
+ }()
1122
1153
// Validate arguments
1123
1154
snapshotID := req .GetSnapshotId ()
1124
1155
if len (snapshotID ) == 0 {
@@ -1203,6 +1234,13 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1203
1234
}
1204
1235
1205
1236
func (gceCS * GCEControllerServer ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
1237
+ var err error
1238
+ diskTypeForMetric := ""
1239
+ defer func () {
1240
+ if err != nil {
1241
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskTypeForMetric )
1242
+ }
1243
+ }()
1206
1244
volumeID := req .GetVolumeId ()
1207
1245
if len (volumeID ) == 0 {
1208
1246
return nil , status .Error (codes .InvalidArgument , "ControllerExpandVolume volume ID must be provided" )
@@ -1217,22 +1255,17 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1217
1255
if err != nil {
1218
1256
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1219
1257
}
1220
-
1258
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1259
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1221
1260
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1222
1261
if err != nil {
1223
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1224
1262
if gce .IsGCENotFoundError (err ) {
1225
1263
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1226
1264
}
1227
1265
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1228
1266
}
1229
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1230
- if err != nil {
1231
- common .LoggedError ("Failed to getDisk: " , err )
1232
- }
1233
1267
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1234
1268
if err != nil {
1235
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1236
1269
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1237
1270
}
1238
1271
0 commit comments