@@ -21,7 +21,6 @@ import (
21
21
"math/rand"
22
22
neturl "net/url"
23
23
"sort"
24
- "strconv"
25
24
"strings"
26
25
"time"
27
26
@@ -303,12 +302,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
303
302
304
303
func (gceCS * GCEControllerServer ) createVolumeInternal (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
305
304
var err error
306
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
307
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
308
- enableStoragePools := metrics .DefaultEnableStoragePools
309
- defer func () {
310
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
311
- }()
305
+ // Apply Parameters (case-insensitive). We leave validation of
306
+ // the values to the cloud provider.
307
+ params , err := gceCS .parameterProcessor ().ExtractAndDefaultParameters (req .GetParameters (), gceCS .Driver .extraVolumeLabels , gceCS .Driver .extraTags )
308
+ metrics .UpdateRequestMetadataFromParams (ctx , params )
309
+ if err != nil {
310
+ return nil , status .Errorf (codes .InvalidArgument , "failed to extract parameters: %v" , err .Error ())
311
+ }
312
+
312
313
// Validate arguments
313
314
volumeCapabilities := req .GetVolumeCapabilities ()
314
315
capacityRange := req .GetCapacityRange ()
@@ -328,17 +329,6 @@ func (gceCS *GCEControllerServer) createVolumeInternal(ctx context.Context, req
328
329
if err != nil {
329
330
return nil , status .Errorf (codes .InvalidArgument , "VolumeCapabilities is invalid: %v" , err .Error ())
330
331
}
331
-
332
- // Apply Parameters (case-insensitive). We leave validation of
333
- // the values to the cloud provider.
334
- params , err := gceCS .parameterProcessor ().ExtractAndDefaultParameters (req .GetParameters (), gceCS .Driver .extraVolumeLabels , gceCS .Driver .extraTags )
335
- diskTypeForMetric = params .DiskType
336
- enableConfidentialCompute = strconv .FormatBool (params .EnableConfidentialCompute )
337
- hasStoragePools := len (params .StoragePools ) > 0
338
- enableStoragePools = strconv .FormatBool (hasStoragePools )
339
- if err != nil {
340
- return nil , status .Errorf (codes .InvalidArgument , "failed to extract parameters: %v" , err .Error ())
341
- }
342
332
// https://github.com/container-storage-interface/spec/blob/master/spec.md#createvolume
343
333
// mutable_parameters MUST take precedence over the values from parameters.
344
334
mutableParams := req .GetMutableParameters ()
@@ -782,14 +772,6 @@ func (gceCS *GCEControllerServer) ControllerModifyVolume(ctx context.Context, re
782
772
return nil , status .Error (codes .InvalidArgument , "volume ID must be provided" )
783
773
}
784
774
785
- diskType := metrics .DefaultDiskTypeForMetric
786
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
787
- enableStoragePools := metrics .DefaultEnableStoragePools
788
-
789
- defer func () {
790
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerModifyVolume" , err , diskType , enableConfidentialCompute , enableStoragePools )
791
- }()
792
-
793
775
project , volKey , err := common .VolumeIDToKey (volumeID )
794
776
if err != nil {
795
777
// Cannot find volume associated with this ID because VolumeID is not in the correct format
@@ -806,6 +788,7 @@ func (gceCS *GCEControllerServer) ControllerModifyVolume(ctx context.Context, re
806
788
klog .V (4 ).Infof ("Modify Volume Parameters for %s: %v" , volumeID , volumeModifyParams )
807
789
808
790
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionBeta )
791
+ metrics .UpdateRequestMetadataFromDisk (ctx , existingDisk )
809
792
810
793
if err != nil {
811
794
err = fmt .Errorf ("Failed to get volume: %w" , err )
@@ -816,9 +799,9 @@ func (gceCS *GCEControllerServer) ControllerModifyVolume(ctx context.Context, re
816
799
err = status .Errorf (codes .Internal , "failed to get volume : %s" , volumeID )
817
800
return nil , err
818
801
}
819
- diskType = existingDisk .GetPDType ()
820
802
821
803
// Check if the disk supports dynamic IOPS/Throughput provisioning
804
+ diskType := existingDisk .GetPDType ()
822
805
supportsIopsChange := gceCS .diskSupportsIopsChange (diskType )
823
806
supportsThroughputChange := gceCS .diskSupportsThroughputChange (diskType )
824
807
if ! supportsIopsChange && ! supportsThroughputChange {
@@ -834,8 +817,6 @@ func (gceCS *GCEControllerServer) ControllerModifyVolume(ctx context.Context, re
834
817
return nil , err
835
818
}
836
819
837
- enableStoragePools = strconv .FormatBool (existingDisk .GetEnableStoragePools ())
838
-
839
820
err = gceCS .CloudProvider .UpdateDisk (ctx , project , volKey , existingDisk , volumeModifyParams )
840
821
if err != nil {
841
822
klog .Errorf ("Failed to modify volume %s: %v" , volumeID , err )
@@ -883,12 +864,6 @@ func getGCEApiVersion(multiWriter bool) gce.GCEAPIVersion {
883
864
func (gceCS * GCEControllerServer ) deleteMultiZoneDisk (ctx context.Context , req * csi.DeleteVolumeRequest , project string , volKey * meta.Key ) (* csi.DeleteVolumeResponse , error ) {
884
865
// List disks with same name
885
866
var err error
886
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
887
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
888
- enableStoragePools := metrics .DefaultEnableStoragePools
889
- defer func () {
890
- gceCS .Metrics .RecordOperationErrorMetrics ("DeleteVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
891
- }()
892
867
existingZones := []string {gceCS .CloudProvider .GetDefaultZone ()}
893
868
zones , err := getDefaultZonesInRegion (ctx , gceCS , existingZones )
894
869
if err != nil {
@@ -910,7 +885,7 @@ func (gceCS *GCEControllerServer) deleteMultiZoneDisk(ctx context.Context, req *
910
885
}
911
886
disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , zonalVolKey , gce .GCEAPIVersionV1 )
912
887
// TODO: Consolidate the parameters here, rather than taking the last.
913
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
888
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
914
889
err := gceCS .CloudProvider .DeleteDisk (ctx , project , zonalVolKey )
915
890
if err != nil {
916
891
deleteDiskErrs = append (deleteDiskErrs , gceCS .CloudProvider .DeleteDisk (ctx , project , volKey ))
@@ -927,12 +902,6 @@ func (gceCS *GCEControllerServer) deleteMultiZoneDisk(ctx context.Context, req *
927
902
928
903
func (gceCS * GCEControllerServer ) deleteSingleDeviceDisk (ctx context.Context , req * csi.DeleteVolumeRequest , project string , volKey * meta.Key ) (* csi.DeleteVolumeResponse , error ) {
929
904
var err error
930
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
931
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
932
- enableStoragePools := metrics .DefaultEnableStoragePools
933
- defer func () {
934
- gceCS .Metrics .RecordOperationErrorMetrics ("DeleteVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
935
- }()
936
905
volumeID := req .GetVolumeId ()
937
906
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
938
907
if err != nil {
@@ -948,7 +917,7 @@ func (gceCS *GCEControllerServer) deleteSingleDeviceDisk(ctx context.Context, re
948
917
}
949
918
defer gceCS .volumeLocks .Release (volumeID )
950
919
disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
951
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
920
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
952
921
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
953
922
if err != nil {
954
923
return nil , common .LoggedError ("Failed to delete disk: " , err )
@@ -960,12 +929,6 @@ func (gceCS *GCEControllerServer) deleteSingleDeviceDisk(ctx context.Context, re
960
929
961
930
func (gceCS * GCEControllerServer ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
962
931
var err error
963
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
964
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
965
- enableStoragePools := metrics .DefaultEnableStoragePools
966
- defer func () {
967
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
968
- }()
969
932
// Only valid requests will be accepted
970
933
_ , _ , _ , err = gceCS .validateControllerPublishVolumeRequest (ctx , req )
971
934
if err != nil {
@@ -978,7 +941,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
978
941
}
979
942
980
943
resp , err , disk := gceCS .executeControllerPublishVolume (ctx , req )
981
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
944
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
982
945
if err != nil {
983
946
klog .Infof ("For node %s adding backoff due to error for volume %s: %v" , req .NodeId , req .VolumeId , err )
984
947
gceCS .errorBackoff .next (backoffId , common .CodeForError (err ))
@@ -1192,12 +1155,6 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
1192
1155
1193
1156
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
1194
1157
var err error
1195
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
1196
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
1197
- enableStoragePools := metrics .DefaultEnableStoragePools
1198
- defer func () {
1199
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
1200
- }()
1201
1158
_ , _ , err = gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
1202
1159
if err != nil {
1203
1160
return nil , err
@@ -1209,7 +1166,7 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
1209
1166
return nil , status .Errorf (gceCS .errorBackoff .code (backoffId ), "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
1210
1167
}
1211
1168
resp , err , disk := gceCS .executeControllerUnpublishVolume (ctx , req )
1212
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
1169
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
1213
1170
if err != nil {
1214
1171
klog .Infof ("For node %s adding backoff due to error for volume %s: %v" , req .NodeId , req .VolumeId , err )
1215
1172
gceCS .errorBackoff .next (backoffId , common .CodeForError (err ))
@@ -1316,12 +1273,6 @@ func (gceCS *GCEControllerServer) parameterProcessor() *common.ParameterProcesso
1316
1273
1317
1274
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
1318
1275
var err error
1319
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
1320
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
1321
- enableStoragePools := metrics .DefaultEnableStoragePools
1322
- defer func () {
1323
- gceCS .Metrics .RecordOperationErrorMetrics ("ValidateVolumeCapabilities" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
1324
- }()
1325
1276
if req .GetVolumeCapabilities () == nil || len (req .GetVolumeCapabilities ()) == 0 {
1326
1277
return nil , status .Error (codes .InvalidArgument , "Volume Capabilities must be provided" )
1327
1278
}
@@ -1348,7 +1299,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
1348
1299
defer gceCS .volumeLocks .Release (volumeID )
1349
1300
1350
1301
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1351
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
1302
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
1352
1303
if err != nil {
1353
1304
if gce .IsGCENotFoundError (err ) {
1354
1305
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
@@ -1564,12 +1515,6 @@ func (gceCS *GCEControllerServer) ControllerGetCapabilities(ctx context.Context,
1564
1515
1565
1516
func (gceCS * GCEControllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
1566
1517
var err error
1567
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
1568
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
1569
- enableStoragePools := metrics .DefaultEnableStoragePools
1570
- defer func () {
1571
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
1572
- }()
1573
1518
// Validate arguments
1574
1519
volumeID := req .GetSourceVolumeId ()
1575
1520
if len (req .Name ) == 0 {
@@ -1595,7 +1540,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
1595
1540
1596
1541
// Check if volume exists
1597
1542
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1598
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( disk )
1543
+ metrics .UpdateRequestMetadataFromDisk ( ctx , disk )
1599
1544
if err != nil {
1600
1545
if gce .IsGCENotFoundError (err ) {
1601
1546
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
@@ -1823,12 +1768,6 @@ func isCSISnapshotReady(status string) (bool, error) {
1823
1768
1824
1769
func (gceCS * GCEControllerServer ) DeleteSnapshot (ctx context.Context , req * csi.DeleteSnapshotRequest ) (* csi.DeleteSnapshotResponse , error ) {
1825
1770
var err error
1826
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
1827
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
1828
- enableStoragePools := metrics .DefaultEnableStoragePools
1829
- defer func () {
1830
- gceCS .Metrics .RecordOperationErrorMetrics ("DeleteSnapshot" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
1831
- }()
1832
1771
// Validate arguments
1833
1772
snapshotID := req .GetSnapshotId ()
1834
1773
if len (snapshotID ) == 0 {
@@ -1913,14 +1852,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1913
1852
}
1914
1853
1915
1854
func (gceCS * GCEControllerServer ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
1916
-
1917
1855
var err error
1918
- diskTypeForMetric := metrics .DefaultDiskTypeForMetric
1919
- enableConfidentialCompute := metrics .DefaultEnableConfidentialCompute
1920
- enableStoragePools := metrics .DefaultEnableStoragePools
1921
- defer func () {
1922
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskTypeForMetric , enableConfidentialCompute , enableStoragePools )
1923
- }()
1924
1856
volumeID := req .GetVolumeId ()
1925
1857
if len (volumeID ) == 0 {
1926
1858
return nil , status .Error (codes .InvalidArgument , "ControllerExpandVolume volume ID must be provided" )
@@ -1950,7 +1882,7 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1950
1882
}
1951
1883
1952
1884
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1953
- diskTypeForMetric , enableConfidentialCompute , enableStoragePools = metrics .GetMetricParameters ( sourceDisk )
1885
+ metrics .UpdateRequestMetadataFromDisk ( ctx , sourceDisk )
1954
1886
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1955
1887
1956
1888
if err != nil {
0 commit comments