@@ -113,7 +113,7 @@ const (
113
113
114
114
replicationTypeNone = "none"
115
115
replicationTypeRegionalPD = "regional-pd"
116
-
116
+ diskNotFound = ""
117
117
// The maximum number of entries that we can include in the
118
118
// ListVolumesResposne
119
119
// In reality, the limit here is 4MB (based on gRPC client response limits),
@@ -221,7 +221,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
221
221
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
222
222
if err != nil {
223
223
if ! gce .IsGCEError (err , "notFound" ) {
224
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
224
+ return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
225
225
}
226
226
}
227
227
if err == nil {
@@ -277,7 +277,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
277
277
if gce .IsGCEError (err , "notFound" ) {
278
278
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
279
279
} else {
280
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
280
+ return nil , common .LoggedError ("CreateVolume, getDisk error when validating: " , err )
281
281
}
282
282
}
283
283
@@ -337,9 +337,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
337
337
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
338
338
if err != nil {
339
339
// Emit metric for expected disk type from storage class
340
- if params .DiskType != "" {
341
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
342
- }
340
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
343
341
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
344
342
}
345
343
case replicationTypeRegionalPD :
@@ -349,9 +347,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
349
347
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
350
348
if err != nil {
351
349
// Emit metric for expected disk type from storage class
352
- if params .DiskType != "" {
353
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
354
- }
350
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
355
351
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
356
352
}
357
353
default :
@@ -361,9 +357,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
361
357
ready , err := isDiskReady (disk )
362
358
if err != nil {
363
359
// Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
364
- if params .DiskType != "" {
365
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
366
- }
360
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
367
361
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
368
362
}
369
363
if ! ready {
@@ -406,7 +400,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
406
400
407
401
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
408
402
if err != nil {
409
- return nil , common .LoggedError ("unknown Delete disk error : " , err )
403
+ return nil , common .LoggedError ("Failed to delete disk : " , err )
410
404
}
411
405
412
406
klog .V (4 ).Infof ("DeleteVolume succeeded for disk %v" , volKey )
@@ -506,10 +500,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
506
500
defer gceCS .volumeLocks .Release (lockingVolumeID )
507
501
diskToPublish , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
508
502
if err != nil {
503
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
509
504
if gce .IsGCENotFoundError (err ) {
510
505
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
511
506
}
512
- return nil , status .Errorf (codes .Internal , "Unknown get disk error : %v" , err .Error ())
507
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk : %v" , err .Error ())
513
508
}
514
509
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
515
510
if err != nil {
@@ -520,7 +515,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
520
515
if gce .IsGCENotFoundError (err ) {
521
516
return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
522
517
}
523
- return nil , status .Errorf (codes .Internal , "Unknown get instance error : %v" , err .Error ())
518
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
524
519
}
525
520
526
521
readWrite := "READ_WRITE"
@@ -556,16 +551,17 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
556
551
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 )
557
552
}
558
553
// Emit metric for error
559
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
560
- return nil , status .Errorf (codes .Internal , "unknown Attach error : %v" , err .Error ())
554
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
555
+ return nil , status .Errorf (codes .Internal , "Failed to Attach : %v" , err .Error ())
561
556
}
562
557
563
558
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
564
559
if err != nil {
565
560
// Emit metric for error
566
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
567
- return nil , status .Errorf (codes .Internal , "unknown WaitForAttach error : %v" , err .Error ())
561
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
562
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach : %v" , err .Error ())
568
563
}
564
+
569
565
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
570
566
return pubVolResp , nil
571
567
}
@@ -666,15 +662,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
666
662
}
667
663
diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
668
664
if err != nil {
669
- common .LoggedError ("Unknown get disk error: " , err )
665
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
666
+ common .LoggedError ("Failed to getDisk: " , err )
670
667
}
671
668
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
672
669
if err != nil {
673
- //Do not emit metric if disk is unknown
674
- if diskToUnpublish != nil {
675
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskToUnpublish .GetPDType ())
676
- }
677
- return nil , common .LoggedError ("unknown detach error: " , err )
670
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
671
+ return nil , common .LoggedError ("Failed to detach: " , err )
678
672
}
679
673
680
674
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
@@ -712,7 +706,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
712
706
if gce .IsGCENotFoundError (err ) {
713
707
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
714
708
}
715
- return nil , common .LoggedError ("Unknown get disk error : " , err )
709
+ return nil , common .LoggedError ("Failed to getDisk : " , err )
716
710
}
717
711
718
712
// Check Volume Context is Empty
@@ -775,7 +769,7 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
775
769
if gce .IsGCEInvalidError (err ) {
776
770
return nil , status .Errorf (codes .Aborted , "ListVolumes error with invalid request: %v" , err .Error ())
777
771
}
778
- return nil , common .LoggedError ("Unknown list disk error : " , err )
772
+ return nil , common .LoggedError ("Failed to list disk: " , err )
779
773
}
780
774
gceCS .disks = diskList
781
775
gceCS .seen = map [string ]int {}
@@ -858,7 +852,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
858
852
if gce .IsGCENotFoundError (err ) {
859
853
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
860
854
}
861
- return nil , common .LoggedError ("CreateSnapshot unknown get disk error : " , err )
855
+ return nil , common .LoggedError ("CreateSnapshot, failed to getDisk : " , err )
862
856
}
863
857
864
858
snapshotParams , err := common .ExtractAndDefaultSnapshotParameters (req .GetParameters (), gceCS .Driver .name )
@@ -893,35 +887,30 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
893
887
}
894
888
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
895
889
if err != nil {
896
- common .LoggedError ("Unknown get disk error : " , err )
890
+ common .LoggedError ("Failed to getDisk : " , err )
897
891
}
898
892
// Check if PD snapshot already exists
899
893
var snapshot * compute.Snapshot
900
894
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
901
895
if err != nil {
902
896
if ! gce .IsGCEError (err , "notFound" ) {
903
- return nil , status .Errorf (codes .Internal , "Unknown get snapshot error : %v" , err .Error ())
897
+ return nil , status .Errorf (codes .Internal , "Failed to get snapshot: %v" , err .Error ())
904
898
}
905
899
// If we could not find the snapshot, we create a new one
906
900
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
907
901
if err != nil {
908
902
if gce .IsGCEError (err , "notFound" ) {
903
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
909
904
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
910
905
}
911
- //Do not emit metric if disk is unknown
912
- if sourceDisk != nil {
913
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
914
- }
915
- return nil , common .LoggedError ("Unknown create snapshot error: " , err )
906
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
907
+ return nil , common .LoggedError ("Failed to create snapshot: " , err )
916
908
}
917
909
}
918
910
919
911
err = gceCS .validateExistingSnapshot (snapshot , volKey )
920
912
if err != nil {
921
- //Do not emit metric if disk is unknown
922
- if sourceDisk != nil {
923
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
924
- }
913
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
925
914
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
926
915
}
927
916
@@ -955,15 +944,15 @@ func (gceCS *GCEControllerServer) createImage(ctx context.Context, project strin
955
944
image , err = gceCS .CloudProvider .GetImage (ctx , project , imageName )
956
945
if err != nil {
957
946
if ! gce .IsGCEError (err , "notFound" ) {
958
- return nil , common .LoggedError ("Unknown get image error : " , err )
947
+ return nil , common .LoggedError ("Failed to get image: " , err )
959
948
}
960
949
// create a new image
961
950
image , err = gceCS .CloudProvider .CreateImage (ctx , project , volKey , imageName , snapshotParams )
962
951
if err != nil {
963
952
if gce .IsGCEError (err , "notFound" ) {
964
953
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
965
954
}
966
- return nil , common .LoggedError ("Unknown create image error : " , err )
955
+ return nil , common .LoggedError ("Failed to create image: " , err )
967
956
}
968
957
}
969
958
@@ -1093,12 +1082,12 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
1093
1082
case common .DiskSnapshotType :
1094
1083
err = gceCS .CloudProvider .DeleteSnapshot (ctx , project , key )
1095
1084
if err != nil {
1096
- return nil , common .LoggedError ("unknown Delete snapshot error : " , err )
1085
+ return nil , common .LoggedError ("Failed to DeleteSnapshot : " , err )
1097
1086
}
1098
1087
case common .DiskImageType :
1099
1088
err = gceCS .CloudProvider .DeleteImage (ctx , project , key )
1100
1089
if err != nil {
1101
- return nil , common .LoggedError ("unknown Delete image error: " , err )
1090
+ return nil , common .LoggedError ("Failed to DeleteImage error: " , err )
1102
1091
}
1103
1092
default :
1104
1093
return nil , status .Errorf (codes .InvalidArgument , "unknown snapshot type %s" , snapshotType )
@@ -1130,7 +1119,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1130
1119
if gce .IsGCEInvalidError (err ) {
1131
1120
return nil , status .Errorf (codes .Aborted , "ListSnapshots error with invalid request: %v" , err .Error ())
1132
1121
}
1133
- return nil , common .LoggedError ("Unknown list snapshots error : " , err )
1122
+ return nil , common .LoggedError ("Failed to list snapshots: " , err )
1134
1123
}
1135
1124
gceCS .snapshots = snapshotList
1136
1125
gceCS .snapshotTokens = map [string ]int {}
@@ -1176,21 +1165,19 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1176
1165
1177
1166
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1178
1167
if err != nil {
1168
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1179
1169
if gce .IsGCENotFoundError (err ) {
1180
1170
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1181
1171
}
1182
1172
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1183
1173
}
1184
1174
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1185
1175
if err != nil {
1186
- common .LoggedError ("Unknown get disk error : " , err )
1176
+ common .LoggedError ("Failed to getDisk : " , err )
1187
1177
}
1188
1178
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1189
1179
if err != nil {
1190
- //Do not emit metric if disk is unknown
1191
- if sourceDisk != nil {
1192
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , sourceDisk .GetPDType ())
1193
- }
1180
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1194
1181
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1195
1182
}
1196
1183
@@ -1214,15 +1201,15 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
1214
1201
if gce .IsGCEError (err , "invalid" ) {
1215
1202
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1216
1203
}
1217
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1204
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1218
1205
}
1219
1206
1220
1207
images , _ , err = gceCS .CloudProvider .ListImages (ctx , filter )
1221
1208
if err != nil {
1222
1209
if gce .IsGCEError (err , "invalid" ) {
1223
1210
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1224
1211
}
1225
- return nil , common .LoggedError ("Unknown list image error : " , err )
1212
+ return nil , common .LoggedError ("Failed to list image: " , err )
1226
1213
}
1227
1214
1228
1215
entries := []* csi.ListSnapshotsResponse_Entry {}
@@ -1263,7 +1250,7 @@ func (gceCS *GCEControllerServer) getSnapshotByID(ctx context.Context, snapshotI
1263
1250
// return empty list if no snapshot is found
1264
1251
return & csi.ListSnapshotsResponse {}, nil
1265
1252
}
1266
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1253
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1267
1254
}
1268
1255
e , err := generateDiskSnapshotEntry (snapshot )
1269
1256
if err != nil {
0 commit comments