@@ -130,7 +130,7 @@ const (
130
130
131
131
replicationTypeNone = "none"
132
132
replicationTypeRegionalPD = "regional-pd"
133
-
133
+ diskNotFound = ""
134
134
// The maximum number of entries that we can include in the
135
135
// ListVolumesResposne
136
136
// In reality, the limit here is 4MB (based on gRPC client response limits),
@@ -285,7 +285,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
285
285
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
286
286
if err != nil {
287
287
if ! gce .IsGCEError (err , "notFound" ) {
288
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
288
+ return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
289
289
}
290
290
}
291
291
if err == nil {
@@ -341,7 +341,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
341
341
if gce .IsGCEError (err , "notFound" ) {
342
342
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
343
343
} else {
344
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
344
+ return nil , common .LoggedError ("CreateVolume, getDisk error when validating: " , err )
345
345
}
346
346
}
347
347
@@ -401,9 +401,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
401
401
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
402
402
if err != nil {
403
403
// Emit metric for expected disk type from storage class
404
- if params .DiskType != "" {
405
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
406
- }
404
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
407
405
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
408
406
}
409
407
case replicationTypeRegionalPD :
@@ -413,9 +411,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
413
411
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
414
412
if err != nil {
415
413
// Emit metric for expected disk type from storage class
416
- if params .DiskType != "" {
417
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
418
- }
414
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
419
415
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
420
416
}
421
417
default :
@@ -425,9 +421,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
425
421
ready , err := isDiskReady (disk )
426
422
if err != nil {
427
423
// Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
428
- if params .DiskType != "" {
429
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
430
- }
424
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
431
425
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
432
426
}
433
427
if ! ready {
@@ -470,7 +464,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
470
464
471
465
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
472
466
if err != nil {
473
- return nil , common .LoggedError ("unknown Delete disk error : " , err )
467
+ return nil , common .LoggedError ("Failed to delete disk : " , err )
474
468
}
475
469
476
470
klog .V (4 ).Infof ("DeleteVolume succeeded for disk %v" , volKey )
@@ -570,10 +564,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
570
564
defer gceCS .volumeLocks .Release (lockingVolumeID )
571
565
diskToPublish , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
572
566
if err != nil {
567
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
573
568
if gce .IsGCENotFoundError (err ) {
574
569
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
575
570
}
576
- return nil , status .Errorf (codes .Internal , "Unknown get disk error : %v" , err .Error ())
571
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk : %v" , err .Error ())
577
572
}
578
573
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
579
574
if err != nil {
@@ -584,7 +579,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
584
579
if gce .IsGCENotFoundError (err ) {
585
580
return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
586
581
}
587
- return nil , status .Errorf (codes .Internal , "Unknown get instance error : %v" , err .Error ())
582
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
588
583
}
589
584
590
585
readWrite := "READ_WRITE"
@@ -620,16 +615,17 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
620
615
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 )
621
616
}
622
617
// Emit metric for error
623
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
624
- return nil , status .Errorf (codes .Internal , "unknown Attach error : %v" , err .Error ())
618
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
619
+ return nil , status .Errorf (codes .Internal , "Failed to Attach : %v" , err .Error ())
625
620
}
626
621
627
622
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
628
623
if err != nil {
629
624
// Emit metric for error
630
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
631
- return nil , status .Errorf (codes .Internal , "unknown WaitForAttach error : %v" , err .Error ())
625
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
626
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach : %v" , err .Error ())
632
627
}
628
+
633
629
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
634
630
return pubVolResp , nil
635
631
}
@@ -729,15 +725,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
729
725
}
730
726
diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
731
727
if err != nil {
732
- common .LoggedError ("Unknown get disk error: " , err )
728
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
729
+ common .LoggedError ("Failed to getDisk: " , err )
733
730
}
734
731
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
735
732
if err != nil {
736
- //Do not emit metric if disk is unknown
737
- if diskToUnpublish != nil {
738
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskToUnpublish .GetPDType ())
739
- }
740
- return nil , common .LoggedError ("unknown detach error: " , err )
733
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
734
+ return nil , common .LoggedError ("Failed to detach: " , err )
741
735
}
742
736
743
737
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
@@ -775,7 +769,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
775
769
if gce .IsGCENotFoundError (err ) {
776
770
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
777
771
}
778
- return nil , common .LoggedError ("Unknown get disk error : " , err )
772
+ return nil , common .LoggedError ("Failed to getDisk : " , err )
779
773
}
780
774
781
775
// Check Volume Context is Empty
@@ -838,7 +832,7 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
838
832
if gce .IsGCEInvalidError (err ) {
839
833
return nil , status .Errorf (codes .Aborted , "ListVolumes error with invalid request: %v" , err .Error ())
840
834
}
841
- return nil , common .LoggedError ("Unknown list disk error : " , err )
835
+ return nil , common .LoggedError ("Failed to list disk: " , err )
842
836
}
843
837
gceCS .disks = diskList
844
838
gceCS .seen = map [string ]int {}
@@ -921,7 +915,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
921
915
if gce .IsGCENotFoundError (err ) {
922
916
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
923
917
}
924
- return nil , common .LoggedError ("CreateSnapshot unknown get disk error : " , err )
918
+ return nil , common .LoggedError ("CreateSnapshot, failed to getDisk : " , err )
925
919
}
926
920
927
921
snapshotParams , err := common .ExtractAndDefaultSnapshotParameters (req .GetParameters (), gceCS .Driver .name )
@@ -956,35 +950,30 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
956
950
}
957
951
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
958
952
if err != nil {
959
- common .LoggedError ("Unknown get disk error : " , err )
953
+ common .LoggedError ("Failed to getDisk : " , err )
960
954
}
961
955
// Check if PD snapshot already exists
962
956
var snapshot * compute.Snapshot
963
957
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
964
958
if err != nil {
965
959
if ! gce .IsGCEError (err , "notFound" ) {
966
- return nil , status .Errorf (codes .Internal , "Unknown get snapshot error : %v" , err .Error ())
960
+ return nil , status .Errorf (codes .Internal , "Failed to get snapshot: %v" , err .Error ())
967
961
}
968
962
// If we could not find the snapshot, we create a new one
969
963
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
970
964
if err != nil {
971
965
if gce .IsGCEError (err , "notFound" ) {
966
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
972
967
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
973
968
}
974
- //Do not emit metric if disk is unknown
975
- if sourceDisk != nil {
976
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
977
- }
978
- return nil , common .LoggedError ("Unknown create snapshot error: " , err )
969
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
970
+ return nil , common .LoggedError ("Failed to create snapshot: " , err )
979
971
}
980
972
}
981
973
982
974
err = gceCS .validateExistingSnapshot (snapshot , volKey )
983
975
if err != nil {
984
- //Do not emit metric if disk is unknown
985
- if sourceDisk != nil {
986
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
987
- }
976
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
988
977
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
989
978
}
990
979
@@ -1018,15 +1007,15 @@ func (gceCS *GCEControllerServer) createImage(ctx context.Context, project strin
1018
1007
image , err = gceCS .CloudProvider .GetImage (ctx , project , imageName )
1019
1008
if err != nil {
1020
1009
if ! gce .IsGCEError (err , "notFound" ) {
1021
- return nil , common .LoggedError ("Unknown get image error : " , err )
1010
+ return nil , common .LoggedError ("Failed to get image: " , err )
1022
1011
}
1023
1012
// create a new image
1024
1013
image , err = gceCS .CloudProvider .CreateImage (ctx , project , volKey , imageName , snapshotParams )
1025
1014
if err != nil {
1026
1015
if gce .IsGCEError (err , "notFound" ) {
1027
1016
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
1028
1017
}
1029
- return nil , common .LoggedError ("Unknown create image error : " , err )
1018
+ return nil , common .LoggedError ("Failed to create image: " , err )
1030
1019
}
1031
1020
}
1032
1021
@@ -1156,12 +1145,12 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
1156
1145
case common .DiskSnapshotType :
1157
1146
err = gceCS .CloudProvider .DeleteSnapshot (ctx , project , key )
1158
1147
if err != nil {
1159
- return nil , common .LoggedError ("unknown Delete snapshot error : " , err )
1148
+ return nil , common .LoggedError ("Failed to DeleteSnapshot : " , err )
1160
1149
}
1161
1150
case common .DiskImageType :
1162
1151
err = gceCS .CloudProvider .DeleteImage (ctx , project , key )
1163
1152
if err != nil {
1164
- return nil , common .LoggedError ("unknown Delete image error: " , err )
1153
+ return nil , common .LoggedError ("Failed to DeleteImage error: " , err )
1165
1154
}
1166
1155
default :
1167
1156
return nil , status .Errorf (codes .InvalidArgument , "unknown snapshot type %s" , snapshotType )
@@ -1193,7 +1182,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1193
1182
if gce .IsGCEInvalidError (err ) {
1194
1183
return nil , status .Errorf (codes .Aborted , "ListSnapshots error with invalid request: %v" , err .Error ())
1195
1184
}
1196
- return nil , common .LoggedError ("Unknown list snapshots error : " , err )
1185
+ return nil , common .LoggedError ("Failed to list snapshots: " , err )
1197
1186
}
1198
1187
gceCS .snapshots = snapshotList
1199
1188
gceCS .snapshotTokens = map [string ]int {}
@@ -1239,21 +1228,19 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1239
1228
1240
1229
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1241
1230
if err != nil {
1231
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1242
1232
if gce .IsGCENotFoundError (err ) {
1243
1233
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1244
1234
}
1245
1235
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1246
1236
}
1247
1237
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1248
1238
if err != nil {
1249
- common .LoggedError ("Unknown get disk error : " , err )
1239
+ common .LoggedError ("Failed to getDisk : " , err )
1250
1240
}
1251
1241
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1252
1242
if err != nil {
1253
- //Do not emit metric if disk is unknown
1254
- if sourceDisk != nil {
1255
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , sourceDisk .GetPDType ())
1256
- }
1243
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1257
1244
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1258
1245
}
1259
1246
@@ -1277,15 +1264,15 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
1277
1264
if gce .IsGCEError (err , "invalid" ) {
1278
1265
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1279
1266
}
1280
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1267
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1281
1268
}
1282
1269
1283
1270
images , _ , err = gceCS .CloudProvider .ListImages (ctx , filter )
1284
1271
if err != nil {
1285
1272
if gce .IsGCEError (err , "invalid" ) {
1286
1273
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1287
1274
}
1288
- return nil , common .LoggedError ("Unknown list image error : " , err )
1275
+ return nil , common .LoggedError ("Failed to list image: " , err )
1289
1276
}
1290
1277
1291
1278
entries := []* csi.ListSnapshotsResponse_Entry {}
@@ -1326,7 +1313,7 @@ func (gceCS *GCEControllerServer) getSnapshotByID(ctx context.Context, snapshotI
1326
1313
// return empty list if no snapshot is found
1327
1314
return & csi.ListSnapshotsResponse {}, nil
1328
1315
}
1329
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1316
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1330
1317
}
1331
1318
e , err := generateDiskSnapshotEntry (snapshot )
1332
1319
if err != nil {
0 commit comments