Skip to content

Commit 8ffa08d

Browse files
committed
Register metrics manager for node server and begin emitting metrics.
1 parent bab5983 commit 8ffa08d

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

cmd/gce-pd-csi-driver/main.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,22 @@ func handle() {
155155
}
156156

157157
var metricsManager *metrics.MetricsManager = nil
158-
if *runControllerService && *httpEndpoint != "" {
158+
runServiceWithMetrics := *runControllerService || *runNodeService
159+
if runServiceWithMetrics && *httpEndpoint != "" {
159160
mm := metrics.NewMetricsManager()
160161
mm.InitializeHttpHandler(*httpEndpoint, *metricsPath)
161-
mm.RegisterPDCSIMetric()
162162

163-
if metrics.IsGKEComponentVersionAvailable() {
164-
mm.EmitGKEComponentVersion()
163+
switch {
164+
case *runControllerService:
165+
mm.RegisterPDCSIMetric()
166+
if metrics.IsGKEComponentVersionAvailable() {
167+
mm.EmitGKEComponentVersion()
168+
}
169+
case *runNodeService:
170+
if err := mm.EmmitProcessStartTime(); err != nil {
171+
klog.Errorf("Failed to emit process start time: %v", err.Error())
172+
}
173+
mm.RegisterMountMetric()
165174
}
166175
metricsManager = &mm
167176
}
@@ -255,6 +264,7 @@ func handle() {
255264
EnableDeviceInUseCheck: *enableDeviceInUseCheck,
256265
DeviceInUseTimeout: *deviceInUseTimeout,
257266
EnableDataCache: *enableDataCacheFlag,
267+
MetricsManager: metricsManager,
258268
}
259269
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, nsArgs)
260270
if *maxConcurrentFormatAndMount > 0 {

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

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, devi
156156
enableDeviceInUseCheck: args.EnableDeviceInUseCheck,
157157
deviceInUseErrors: newDeviceErrMap(args.DeviceInUseTimeout),
158158
EnableDataCache: args.EnableDataCache,
159+
metricsManager: args.MetricsManager,
159160
}
160161
}
161162

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

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
3737
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"
3838
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
39+
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/metrics"
3940
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
4041
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/resizefs"
4142
)
@@ -71,6 +72,8 @@ type GCENodeServer struct {
7172
// Embed UnimplementedNodeServer to ensure the driver returns Unimplemented for any
7273
// new RPC methods that might be introduced in future versions of the spec.
7374
csi.UnimplementedNodeServer
75+
76+
metricsManager *metrics.MetricsManager
7477
}
7578

7679
type NodeServerArgs struct {
@@ -81,6 +84,8 @@ type NodeServerArgs struct {
8184
DeviceInUseTimeout time.Duration
8285

8386
EnableDataCache bool
87+
88+
MetricsManager *metrics.MetricsManager
8489
}
8590

8691
var _ csi.NodeServer = &GCENodeServer{}
@@ -406,6 +411,10 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
406411
return &csi.NodeStageVolumeResponse{}, nil
407412
}
408413
}
414+
415+
if ns.metricsManager != nil {
416+
ns.metricsManager.RecordMountErrorMetric(err)
417+
}
409418
return nil, status.Error(codes.Internal,
410419
fmt.Sprintf("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v",
411420
devicePath, stagingTargetPath, fstype, options, err.Error()))

0 commit comments

Comments
 (0)