@@ -12,21 +12,22 @@ import (
1212 "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
1313 "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"
1414 "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/k8sclient"
15+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/metrics"
1516)
1617
1718const byIdDir = "/dev/disk/by-id"
1819
19- func NewDeviceCacheForNode (ctx context.Context , period time.Duration , nodeName string , driverName string , deviceUtils deviceutils.DeviceUtils ) (* DeviceCache , error ) {
20+ func NewDeviceCacheForNode (ctx context.Context , period time.Duration , nodeName string , driverName string , deviceUtils deviceutils.DeviceUtils , metricsManager * metrics. MetricsManager ) (* DeviceCache , error ) {
2021 node , err := k8sclient .GetNodeWithRetry (ctx , nodeName )
2122 if err != nil {
2223 return nil , fmt .Errorf ("failed to get node %s: %w" , nodeName , err )
2324 }
2425
25- return newDeviceCacheForNode (period , node , driverName , deviceUtils ), nil
26+ return newDeviceCacheForNode (period , node , driverName , deviceUtils , metricsManager ), nil
2627}
2728
2829func NewTestDeviceCache (period time.Duration , node * v1.Node ) * DeviceCache {
29- return newDeviceCacheForNode (period , node , "pd.csi.storage.gke.io" , deviceutils .NewDeviceUtils ())
30+ return newDeviceCacheForNode (period , node , "pd.csi.storage.gke.io" , deviceutils .NewDeviceUtils (), nil )
3031}
3132
3233func NewTestNodeWithVolumes (volumes []string ) * v1.Node {
@@ -42,12 +43,13 @@ func NewTestNodeWithVolumes(volumes []string) *v1.Node {
4243 }
4344}
4445
45- func newDeviceCacheForNode (period time.Duration , node * v1.Node , driverName string , deviceUtils deviceutils.DeviceUtils ) * DeviceCache {
46+ func newDeviceCacheForNode (period time.Duration , node * v1.Node , driverName string , deviceUtils deviceutils.DeviceUtils , metricsManager * metrics. MetricsManager ) * DeviceCache {
4647 deviceCache := & DeviceCache {
47- symlinks : make (map [string ]deviceMapping ),
48- period : period ,
49- deviceUtils : deviceUtils ,
50- dir : byIdDir ,
48+ symlinks : make (map [string ]deviceMapping ),
49+ period : period ,
50+ deviceUtils : deviceUtils ,
51+ dir : byIdDir ,
52+ metricsManager : metricsManager ,
5153 }
5254
5355 // Look at the status.volumesInUse field. For each, take the last section
@@ -163,6 +165,9 @@ func (d *DeviceCache) listAndUpdate() {
163165 // Check if the realPath has changed
164166 if realPath != device .realPath {
165167 klog .Warningf ("Change in device path for volume %s (symlink: %s), previous path: %s, new path: %s" , device .volumeID , symlink , device .realPath , realPath )
168+ if d .metricsManager != nil {
169+ d .metricsManager .RecordUnexpectedDevicePathChangesMetric ()
170+ }
166171
167172 // Update the cache with the new realPath
168173 device .realPath = realPath
0 commit comments