Skip to content

Commit 6c3322f

Browse files
committed
Emit mount metric on errors and successes
1 parent 621d844 commit 6c3322f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pkg/gce-pd-csi-driver/node.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,6 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
448448
}
449449
}
450450

451-
if ns.metricsManager != nil {
452-
ns.metricsManager.RecordMountErrorMetric(fstype, err)
453-
}
454451
return nil, status.Error(codes.Internal,
455452
fmt.Sprintf("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v",
456453
devicePath, stagingTargetPath, fstype, options, err.Error()))

pkg/gce-pd-csi-driver/utils_linux.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ func (ns *GCENodeServer) formatAndMount(source, target, fstype string, options [
7575
}
7676
}()
7777
}
78-
return m.FormatAndMount(source, target, fstype, options)
78+
79+
err := m.FormatAndMount(source, target, fstype, options)
80+
if ns.metricsManager != nil {
81+
ns.metricsManager.RecordMountErrorMetric(fstype, err)
82+
}
83+
return err
7984
}
8085

8186
func preparePublishPath(path string, m *mount.SafeFormatAndMount) error {

pkg/metrics/metrics.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ func (mm *MetricsManager) RecordOperationErrorMetrics(
116116
}
117117

118118
func (mm *MetricsManager) RecordMountErrorMetric(fs_format string, err error) {
119+
errType := "OK"
119120
mntErr := &mount.MountError{}
120121
if errors.As(err, mntErr) {
121-
mountErrorMetric.WithLabelValues(pdcsiDriverName, fs_format, string(mntErr.Type)).Inc()
122+
errType = string(mntErr.Type)
122123
}
124+
mountErrorMetric.WithLabelValues(pdcsiDriverName, fs_format, errType).Inc()
123125

124126
klog.Infof("Recorded mount error type: %q", mntErr.Type)
125127
}

0 commit comments

Comments
 (0)