File tree Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -116,14 +116,9 @@ func (mm *MetricsManager) RecordOperationErrorMetrics(
116
116
}
117
117
118
118
func (mm * MetricsManager ) RecordMountErrorMetric (fs_format string , err error ) {
119
- errType := "OK"
120
- mntErr := & mount.MountError {}
121
- if errors .As (err , mntErr ) {
122
- errType = string (mntErr .Type )
123
- }
119
+ errType := mountErrorType (err )
124
120
mountErrorMetric .WithLabelValues (pdcsiDriverName , fs_format , errType ).Inc ()
125
-
126
- klog .Infof ("Recorded mount error type: %q" , mntErr .Type )
121
+ klog .Infof ("Recorded mount error type: %q" , errType )
127
122
}
128
123
129
124
func (mm * MetricsManager ) EmmitProcessStartTime () error {
@@ -198,3 +193,16 @@ func errorCodeLabelValue(operationErr error) string {
198
193
}
199
194
return err
200
195
}
196
+
197
+ func mountErrorType (err error ) string {
198
+ if err == nil {
199
+ return "OK"
200
+ }
201
+
202
+ mntErr := & mount.MountError {}
203
+ if ! errors .As (err , mntErr ) {
204
+ return "UnknownError"
205
+ }
206
+
207
+ return string (mntErr .Type )
208
+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import (
29
29
"google.golang.org/api/googleapi"
30
30
"google.golang.org/grpc/codes"
31
31
"google.golang.org/grpc/status"
32
+ "k8s.io/mount-utils"
32
33
33
34
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
34
35
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
@@ -186,3 +187,35 @@ func TestErrorCodeLabelValue(t *testing.T) {
186
187
}
187
188
}
188
189
}
190
+
191
+ func TestMountOperationError (t * testing.T ) {
192
+ testCases := []struct {
193
+ name string
194
+ err error
195
+ want string
196
+ }{
197
+ {
198
+ name : "no error" ,
199
+ want : "OK" ,
200
+ },
201
+ {
202
+ name : "unknown error" ,
203
+ err : fmt .Errorf ("fake error" ),
204
+ want : "UnknownError" ,
205
+ },
206
+ {
207
+ name : "mount error" ,
208
+ err : mount .NewMountError (mount .FormatFailed , "file system format failed" ),
209
+ want : string (mount .FormatFailed ),
210
+ },
211
+ }
212
+
213
+ for _ , tc := range testCases {
214
+ t .Run (tc .name , func (t * testing.T ) {
215
+ got := mountErrorType (tc .err )
216
+ if diff := cmp .Diff (tc .want , got ); diff != "" {
217
+ t .Errorf ("%s: -want err, +got err\n %s" , tc .name , diff )
218
+ }
219
+ })
220
+ }
221
+ }
You can’t perform that action at this time.
0 commit comments