@@ -147,6 +147,12 @@ func isDiskReady(disk *gce.CloudDisk) (bool, error) {
147
147
148
148
func (gceCS * GCEControllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
149
149
var err error
150
+ diskTypeForMetric := ""
151
+ defer func () {
152
+ if err != nil {
153
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , diskTypeForMetric )
154
+ }
155
+ }()
150
156
// Validate arguments
151
157
volumeCapabilities := req .GetVolumeCapabilities ()
152
158
name := req .GetName ()
@@ -219,6 +225,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
219
225
220
226
// Validate if disk already exists
221
227
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
228
+ diskTypeForMetric = metrics .GetDiskType (existingDisk )
222
229
if err != nil {
223
230
if ! gce .IsGCEError (err , "notFound" ) {
224
231
return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
@@ -273,6 +280,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
273
280
274
281
// Verify that the volume in VolumeContentSource exists.
275
282
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
283
+ diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
276
284
if err != nil {
277
285
if gce .IsGCEError (err , "notFound" ) {
278
286
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -329,15 +337,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
329
337
330
338
// Create the disk
331
339
var disk * gce.CloudDisk
340
+ diskTypeForMetric = params .DiskType
332
341
switch params .ReplicationType {
333
342
case replicationTypeNone :
334
343
if len (zones ) != 1 {
335
344
return nil , status .Errorf (codes .Internal , "CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones )
336
345
}
337
346
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
338
347
if err != nil {
339
- // Emit metric for expected disk type from storage class
340
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
341
348
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
342
349
}
343
350
case replicationTypeRegionalPD :
@@ -346,8 +353,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
346
353
}
347
354
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
348
355
if err != nil {
349
- // Emit metric for expected disk type from storage class
350
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
351
356
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
352
357
}
353
358
default :
@@ -356,8 +361,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
356
361
357
362
ready , err := isDiskReady (disk )
358
363
if err != nil {
359
- // Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
360
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
361
364
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
362
365
}
363
366
if ! ready {
@@ -370,6 +373,13 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
370
373
}
371
374
372
375
func (gceCS * GCEControllerServer ) DeleteVolume (ctx context.Context , req * csi.DeleteVolumeRequest ) (* csi.DeleteVolumeResponse , error ) {
376
+ var err error
377
+ diskTypeForMetric := ""
378
+ defer func () {
379
+ if err != nil {
380
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteVolume" , err , diskTypeForMetric )
381
+ }
382
+ }()
373
383
// Validate arguments
374
384
volumeID := req .GetVolumeId ()
375
385
if len (volumeID ) == 0 {
@@ -385,6 +395,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
385
395
}
386
396
387
397
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
398
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
399
+ diskTypeForMetric = metrics .GetDiskType (disk )
388
400
if err != nil {
389
401
if gce .IsGCENotFoundError (err ) {
390
402
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -408,12 +420,20 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
408
420
}
409
421
410
422
func (gceCS * GCEControllerServer ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
423
+ var err error
424
+ diskTypeForMetric := ""
425
+ defer func () {
426
+ if err != nil {
427
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskTypeForMetric )
428
+ }
429
+ }()
411
430
// Only valid requests will be accepted
412
- _ , _ , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
431
+ project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
413
432
if err != nil {
414
433
return nil , err
415
434
}
416
-
435
+ diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
436
+ diskTypeForMetric = metrics .GetDiskType (diskToPublish )
417
437
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
418
438
if gceCS .errorBackoff .blocking (backoffId ) {
419
439
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -469,7 +489,6 @@ func parseMachineType(machineTypeUrl string) string {
469
489
470
490
func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
471
491
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
472
-
473
492
if err != nil {
474
493
return nil , err
475
494
}
@@ -498,9 +517,8 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
498
517
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
499
518
}
500
519
defer gceCS .volumeLocks .Release (lockingVolumeID )
501
- diskToPublish , err : = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
520
+ _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
502
521
if err != nil {
503
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
504
522
if gce .IsGCENotFoundError (err ) {
505
523
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
506
524
}
@@ -550,15 +568,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
550
568
machineType := parseMachineType (instance .MachineType )
551
569
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 )
552
570
}
553
- // Emit metric for error
554
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
555
571
return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
556
572
}
557
573
558
574
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
559
575
if err != nil {
560
- // Emit metric for error
561
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics .GetDiskType (diskToPublish ))
562
576
return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
563
577
}
564
578
@@ -567,12 +581,20 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
567
581
}
568
582
569
583
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
570
- // Only valid requests will be queued
571
- _ , _ , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
584
+ var err error
585
+ diskTypeForMetric := ""
586
+ defer func () {
587
+ if err != nil {
588
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric )
589
+ }
590
+ }()
591
+ project , volKey , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
572
592
if err != nil {
573
593
return nil , err
574
594
}
575
-
595
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
596
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
597
+ // Only valid requests will be queued
576
598
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
577
599
if gceCS .errorBackoff .blocking (backoffId ) {
578
600
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
@@ -660,14 +682,8 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
660
682
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v. Already not attached." , volKey , nodeID )
661
683
return & csi.ControllerUnpublishVolumeResponse {}, nil
662
684
}
663
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
664
- if err != nil {
665
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
666
- common .LoggedError ("Failed to getDisk: " , err )
667
- }
668
685
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
669
686
if err != nil {
670
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
671
687
return nil , common .LoggedError ("Failed to detach: " , err )
672
688
}
673
689
@@ -676,6 +692,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
676
692
}
677
693
678
694
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
695
+ var err error
696
+ diskTypeForMetric := ""
697
+ defer func () {
698
+ if err != nil {
699
+ gceCS .Metrics .RecordOperationErrorMetrics ("ValidateVolumeCapabilities" , err , diskTypeForMetric )
700
+ }
701
+ }()
679
702
if req .GetVolumeCapabilities () == nil || len (req .GetVolumeCapabilities ()) == 0 {
680
703
return nil , status .Error (codes .InvalidArgument , "Volume Capabilities must be provided" )
681
704
}
@@ -687,7 +710,6 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
687
710
if err != nil {
688
711
return nil , status .Errorf (codes .InvalidArgument , "Volume ID is invalid: %v" , err .Error ())
689
712
}
690
-
691
713
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
692
714
if err != nil {
693
715
if gce .IsGCENotFoundError (err ) {
@@ -702,6 +724,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
702
724
defer gceCS .volumeLocks .Release (volumeID )
703
725
704
726
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
727
+ diskTypeForMetric = metrics .GetDiskType (disk )
705
728
if err != nil {
706
729
if gce .IsGCENotFoundError (err ) {
707
730
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
@@ -828,6 +851,13 @@ func (gceCS *GCEControllerServer) ControllerGetCapabilities(ctx context.Context,
828
851
}
829
852
830
853
func (gceCS * GCEControllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
854
+ var err error
855
+ diskTypeForMetric := ""
856
+ defer func () {
857
+ if err != nil {
858
+ gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskTypeForMetric )
859
+ }
860
+ }()
831
861
// Validate arguments
832
862
volumeID := req .GetSourceVolumeId ()
833
863
if len (req .Name ) == 0 {
@@ -847,7 +877,8 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
847
877
defer gceCS .volumeLocks .Release (volumeID )
848
878
849
879
// Check if volume exists
850
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
880
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
881
+ diskTypeForMetric = metrics .GetDiskType (disk )
851
882
if err != nil {
852
883
if gce .IsGCENotFoundError (err ) {
853
884
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
@@ -885,10 +916,6 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
885
916
if err != nil {
886
917
return nil , status .Errorf (codes .InvalidArgument , "Invalid volume key: %v" , volKey )
887
918
}
888
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
889
- if err != nil {
890
- common .LoggedError ("Failed to getDisk: " , err )
891
- }
892
919
// Check if PD snapshot already exists
893
920
var snapshot * compute.Snapshot
894
921
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
@@ -900,17 +927,14 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
900
927
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
901
928
if err != nil {
902
929
if gce .IsGCEError (err , "notFound" ) {
903
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
904
930
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
905
931
}
906
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
907
932
return nil , common .LoggedError ("Failed to create snapshot: " , err )
908
933
}
909
934
}
910
935
911
936
err = gceCS .validateExistingSnapshot (snapshot , volKey )
912
937
if err != nil {
913
- defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
914
938
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
915
939
}
916
940
@@ -1064,6 +1088,13 @@ func isCSISnapshotReady(status string) (bool, error) {
1064
1088
}
1065
1089
1066
1090
func (gceCS * GCEControllerServer ) DeleteSnapshot (ctx context.Context , req * csi.DeleteSnapshotRequest ) (* csi.DeleteSnapshotResponse , error ) {
1091
+ var err error
1092
+ diskTypeForMetric := ""
1093
+ defer func () {
1094
+ if err != nil {
1095
+ gceCS .Metrics .RecordOperationErrorMetrics ("DeleteSnapshot" , err , diskTypeForMetric )
1096
+ }
1097
+ }()
1067
1098
// Validate arguments
1068
1099
snapshotID := req .GetSnapshotId ()
1069
1100
if len (snapshotID ) == 0 {
@@ -1148,6 +1179,13 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1148
1179
}
1149
1180
1150
1181
func (gceCS * GCEControllerServer ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
1182
+ var err error
1183
+ diskTypeForMetric := ""
1184
+ defer func () {
1185
+ if err != nil {
1186
+ gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskTypeForMetric )
1187
+ }
1188
+ }()
1151
1189
volumeID := req .GetVolumeId ()
1152
1190
if len (volumeID ) == 0 {
1153
1191
return nil , status .Error (codes .InvalidArgument , "ControllerExpandVolume volume ID must be provided" )
@@ -1162,22 +1200,17 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1162
1200
if err != nil {
1163
1201
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1164
1202
}
1165
-
1203
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1204
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1166
1205
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1167
1206
if err != nil {
1168
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1169
1207
if gce .IsGCENotFoundError (err ) {
1170
1208
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1171
1209
}
1172
1210
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1173
1211
}
1174
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1175
- if err != nil {
1176
- common .LoggedError ("Failed to getDisk: " , err )
1177
- }
1178
1212
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1179
1213
if err != nil {
1180
- defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1181
1214
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1182
1215
}
1183
1216
0 commit comments