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