@@ -123,7 +123,7 @@ const (
123
123
124
124
replicationTypeNone = "none"
125
125
replicationTypeRegionalPD = "regional-pd"
126
-
126
+ diskNotFound = ""
127
127
// The maximum number of entries that we can include in the
128
128
// ListVolumesResposne
129
129
// In reality, the limit here is 4MB (based on gRPC client response limits),
@@ -278,7 +278,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
278
278
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
279
279
if err != nil {
280
280
if ! gce .IsGCEError (err , "notFound" ) {
281
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
281
+ return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
282
282
}
283
283
}
284
284
if err == nil {
@@ -334,7 +334,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
334
334
if gce .IsGCEError (err , "notFound" ) {
335
335
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
336
336
} else {
337
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
337
+ return nil , common .LoggedError ("CreateVolume, getDisk error when validating: " , err )
338
338
}
339
339
}
340
340
@@ -394,9 +394,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
394
394
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
395
395
if err != nil {
396
396
// Emit metric for expected disk type from storage class
397
- if params .DiskType != "" {
398
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
399
- }
397
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
400
398
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
401
399
}
402
400
case replicationTypeRegionalPD :
@@ -406,9 +404,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
406
404
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
407
405
if err != nil {
408
406
// Emit metric for expected disk type from storage class
409
- if params .DiskType != "" {
410
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
411
- }
407
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
412
408
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
413
409
}
414
410
default :
@@ -418,9 +414,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
418
414
ready , err := isDiskReady (disk )
419
415
if err != nil {
420
416
// Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
421
- if params .DiskType != "" {
422
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
423
- }
417
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
424
418
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
425
419
}
426
420
if ! ready {
@@ -463,7 +457,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
463
457
464
458
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
465
459
if err != nil {
466
- return nil , common .LoggedError ("unknown Delete disk error : " , err )
460
+ return nil , common .LoggedError ("Failed to delete disk : " , err )
467
461
}
468
462
469
463
klog .V (4 ).Infof ("DeleteVolume succeeded for disk %v" , volKey )
@@ -563,10 +557,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
563
557
defer gceCS .volumeLocks .Release (lockingVolumeID )
564
558
diskToPublish , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
565
559
if err != nil {
560
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
566
561
if gce .IsGCENotFoundError (err ) {
567
562
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
568
563
}
569
- return nil , status .Errorf (codes .Internal , "Unknown get disk error : %v" , err .Error ())
564
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk : %v" , err .Error ())
570
565
}
571
566
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
572
567
if err != nil {
@@ -577,7 +572,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
577
572
if gce .IsGCENotFoundError (err ) {
578
573
return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
579
574
}
580
- return nil , status .Errorf (codes .Internal , "Unknown get instance error : %v" , err .Error ())
575
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
581
576
}
582
577
583
578
readWrite := "READ_WRITE"
@@ -613,16 +608,17 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
613
608
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 )
614
609
}
615
610
// Emit metric for error
616
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
617
- return nil , status .Errorf (codes .Internal , "unknown Attach error : %v" , err .Error ())
611
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
612
+ return nil , status .Errorf (codes .Internal , "Failed to Attach : %v" , err .Error ())
618
613
}
619
614
620
615
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
621
616
if err != nil {
622
617
// Emit metric for error
623
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
624
- return nil , status .Errorf (codes .Internal , "unknown WaitForAttach error : %v" , err .Error ())
618
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
619
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach : %v" , err .Error ())
625
620
}
621
+
626
622
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
627
623
return pubVolResp , nil
628
624
}
@@ -723,15 +719,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
723
719
}
724
720
diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
725
721
if err != nil {
726
- common .LoggedError ("Unknown get disk error: " , err )
722
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
723
+ common .LoggedError ("Failed to getDisk: " , err )
727
724
}
728
725
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
729
726
if err != nil {
730
- //Do not emit metric if disk is unknown
731
- if diskToUnpublish != nil {
732
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskToUnpublish .GetPDType ())
733
- }
734
- return nil , common .LoggedError ("unknown detach error: " , err )
727
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
728
+ return nil , common .LoggedError ("Failed to detach: " , err )
735
729
}
736
730
737
731
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
@@ -769,7 +763,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
769
763
if gce .IsGCENotFoundError (err ) {
770
764
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
771
765
}
772
- return nil , common .LoggedError ("Unknown get disk error : " , err )
766
+ return nil , common .LoggedError ("Failed to getDisk : " , err )
773
767
}
774
768
775
769
// Check Volume Context is Empty
@@ -832,7 +826,7 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
832
826
if gce .IsGCEInvalidError (err ) {
833
827
return nil , status .Errorf (codes .Aborted , "ListVolumes error with invalid request: %v" , err .Error ())
834
828
}
835
- return nil , common .LoggedError ("Unknown list disk error : " , err )
829
+ return nil , common .LoggedError ("Failed to list disk: " , err )
836
830
}
837
831
gceCS .disks = diskList
838
832
gceCS .seen = map [string ]int {}
@@ -915,7 +909,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
915
909
if gce .IsGCENotFoundError (err ) {
916
910
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
917
911
}
918
- return nil , common .LoggedError ("CreateSnapshot unknown get disk error : " , err )
912
+ return nil , common .LoggedError ("CreateSnapshot, failed to getDisk : " , err )
919
913
}
920
914
921
915
snapshotParams , err := common .ExtractAndDefaultSnapshotParameters (req .GetParameters (), gceCS .Driver .name )
@@ -950,35 +944,30 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
950
944
}
951
945
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
952
946
if err != nil {
953
- common .LoggedError ("Unknown get disk error : " , err )
947
+ common .LoggedError ("Failed to getDisk : " , err )
954
948
}
955
949
// Check if PD snapshot already exists
956
950
var snapshot * compute.Snapshot
957
951
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
958
952
if err != nil {
959
953
if ! gce .IsGCEError (err , "notFound" ) {
960
- return nil , status .Errorf (codes .Internal , "Unknown get snapshot error : %v" , err .Error ())
954
+ return nil , status .Errorf (codes .Internal , "Failed to get snapshot: %v" , err .Error ())
961
955
}
962
956
// If we could not find the snapshot, we create a new one
963
957
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
964
958
if err != nil {
965
959
if gce .IsGCEError (err , "notFound" ) {
960
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
966
961
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
967
962
}
968
- //Do not emit metric if disk is unknown
969
- if sourceDisk != nil {
970
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
971
- }
972
- return nil , common .LoggedError ("Unknown create snapshot error: " , err )
963
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
964
+ return nil , common .LoggedError ("Failed to create snapshot: " , err )
973
965
}
974
966
}
975
967
976
968
err = gceCS .validateExistingSnapshot (snapshot , volKey )
977
969
if err != nil {
978
- //Do not emit metric if disk is unknown
979
- if sourceDisk != nil {
980
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
981
- }
970
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
982
971
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
983
972
}
984
973
@@ -1012,15 +1001,15 @@ func (gceCS *GCEControllerServer) createImage(ctx context.Context, project strin
1012
1001
image , err = gceCS .CloudProvider .GetImage (ctx , project , imageName )
1013
1002
if err != nil {
1014
1003
if ! gce .IsGCEError (err , "notFound" ) {
1015
- return nil , common .LoggedError ("Unknown get image error : " , err )
1004
+ return nil , common .LoggedError ("Failed to get image: " , err )
1016
1005
}
1017
1006
// create a new image
1018
1007
image , err = gceCS .CloudProvider .CreateImage (ctx , project , volKey , imageName , snapshotParams )
1019
1008
if err != nil {
1020
1009
if gce .IsGCEError (err , "notFound" ) {
1021
1010
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
1022
1011
}
1023
- return nil , common .LoggedError ("Unknown create image error : " , err )
1012
+ return nil , common .LoggedError ("Failed to create image: " , err )
1024
1013
}
1025
1014
}
1026
1015
@@ -1150,12 +1139,12 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
1150
1139
case common .DiskSnapshotType :
1151
1140
err = gceCS .CloudProvider .DeleteSnapshot (ctx , project , key )
1152
1141
if err != nil {
1153
- return nil , common .LoggedError ("unknown Delete snapshot error : " , err )
1142
+ return nil , common .LoggedError ("Failed to DeleteSnapshot : " , err )
1154
1143
}
1155
1144
case common .DiskImageType :
1156
1145
err = gceCS .CloudProvider .DeleteImage (ctx , project , key )
1157
1146
if err != nil {
1158
- return nil , common .LoggedError ("unknown Delete image error: " , err )
1147
+ return nil , common .LoggedError ("Failed to DeleteImage error: " , err )
1159
1148
}
1160
1149
default :
1161
1150
return nil , status .Errorf (codes .InvalidArgument , "unknown snapshot type %s" , snapshotType )
@@ -1187,7 +1176,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1187
1176
if gce .IsGCEInvalidError (err ) {
1188
1177
return nil , status .Errorf (codes .Aborted , "ListSnapshots error with invalid request: %v" , err .Error ())
1189
1178
}
1190
- return nil , common .LoggedError ("Unknown list snapshots error : " , err )
1179
+ return nil , common .LoggedError ("Failed to list snapshots: " , err )
1191
1180
}
1192
1181
gceCS .snapshots = snapshotList
1193
1182
gceCS .snapshotTokens = map [string ]int {}
@@ -1233,21 +1222,19 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1233
1222
1234
1223
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1235
1224
if err != nil {
1225
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1236
1226
if gce .IsGCENotFoundError (err ) {
1237
1227
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1238
1228
}
1239
1229
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1240
1230
}
1241
1231
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1242
1232
if err != nil {
1243
- common .LoggedError ("Unknown get disk error : " , err )
1233
+ common .LoggedError ("Failed to getDisk : " , err )
1244
1234
}
1245
1235
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1246
1236
if err != nil {
1247
- //Do not emit metric if disk is unknown
1248
- if sourceDisk != nil {
1249
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , sourceDisk .GetPDType ())
1250
- }
1237
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1251
1238
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1252
1239
}
1253
1240
@@ -1271,15 +1258,15 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
1271
1258
if gce .IsGCEError (err , "invalid" ) {
1272
1259
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1273
1260
}
1274
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1261
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1275
1262
}
1276
1263
1277
1264
images , _ , err = gceCS .CloudProvider .ListImages (ctx , filter )
1278
1265
if err != nil {
1279
1266
if gce .IsGCEError (err , "invalid" ) {
1280
1267
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1281
1268
}
1282
- return nil , common .LoggedError ("Unknown list image error : " , err )
1269
+ return nil , common .LoggedError ("Failed to list image: " , err )
1283
1270
}
1284
1271
1285
1272
entries := []* csi.ListSnapshotsResponse_Entry {}
@@ -1320,7 +1307,7 @@ func (gceCS *GCEControllerServer) getSnapshotByID(ctx context.Context, snapshotI
1320
1307
// return empty list if no snapshot is found
1321
1308
return & csi.ListSnapshotsResponse {}, nil
1322
1309
}
1323
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1310
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1324
1311
}
1325
1312
e , err := generateDiskSnapshotEntry (snapshot )
1326
1313
if err != nil {
0 commit comments