Skip to content

Commit b8fc4a5

Browse files
authored
Fix for calculating time for all node servers method (#153)
1 parent b494df1 commit b8fc4a5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/ibmcsidriver/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
215215
lockWaitStart := time.Now()
216216
csiCS.mutex.Lock(nodeID)
217217
defer csiCS.mutex.Unlock(nodeID)
218-
metrics.UpdateDurationFromStart(ctxLogger, metrics.FunctionLabel("ControllerPublishVolume.Lock"), lockWaitStart)
218+
defer metrics.UpdateDurationFromStart(ctxLogger, metrics.FunctionLabel("ControllerPublishVolume.Lock"), lockWaitStart)
219219

220220
volumeCapabilities := []*csi.VolumeCapability{volumeCapability}
221221
// Validate volume capabilities, are all capabilities supported by driver or not

pkg/ibmcsidriver/node.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ package ibmcsidriver
1919

2020
import (
2121
"fmt"
22-
"google.golang.org/grpc/codes"
23-
"google.golang.org/grpc/status"
24-
"k8s.io/klog/v2"
2522
"os"
2623
"path/filepath"
2724
"runtime"
2825
"strconv"
2926
"strings"
3027
"sync"
3128

29+
"google.golang.org/grpc/codes"
30+
"google.golang.org/grpc/status"
31+
"k8s.io/klog/v2"
32+
3233
"os/exec"
3334
"time"
3435

@@ -110,7 +111,7 @@ func (csiNS *CSINodeServer) NodePublishVolume(ctx context.Context, req *csi.Node
110111
controlleRequestID := publishContext[PublishInfoRequestID]
111112
ctxLogger, requestID := utils.GetContextLoggerWithRequestID(ctx, false, &controlleRequestID)
112113
ctxLogger.Info("CSINodeServer-NodePublishVolume...", zap.Reflect("Request", *req))
113-
metrics.UpdateDurationFromStart(ctxLogger, "NodePublishVolume", time.Now())
114+
defer metrics.UpdateDurationFromStart(ctxLogger, "NodePublishVolume", time.Now())
114115
csiNS.mux.Lock()
115116
defer csiNS.mux.Unlock()
116117

@@ -184,7 +185,7 @@ func (csiNS *CSINodeServer) NodePublishVolume(ctx context.Context, req *csi.Node
184185
func (csiNS *CSINodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
185186
ctxLogger, requestID := utils.GetContextLogger(ctx, false)
186187
ctxLogger.Info("CSINodeServer-NodeUnpublishVolume...", zap.Reflect("Request", *req))
187-
metrics.UpdateDurationFromStart(ctxLogger, "NodeUnpublishVolume", time.Now())
188+
defer metrics.UpdateDurationFromStart(ctxLogger, "NodeUnpublishVolume", time.Now())
188189
csiNS.mux.Lock()
189190
defer csiNS.mux.Unlock()
190191
// Validate Arguments
@@ -214,7 +215,7 @@ func (csiNS *CSINodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeSt
214215
controlleRequestID := publishContext[PublishInfoRequestID]
215216
ctxLogger, requestID := utils.GetContextLoggerWithRequestID(ctx, false, &controlleRequestID)
216217
ctxLogger.Info("CSINodeServer-NodeStageVolume...", zap.Reflect("Request", *req))
217-
metrics.UpdateDurationFromStart(ctxLogger, "NodeStageVolume", time.Now())
218+
defer metrics.UpdateDurationFromStart(ctxLogger, "NodeStageVolume", time.Now())
218219

219220
csiNS.mux.Lock()
220221
defer csiNS.mux.Unlock()
@@ -314,7 +315,7 @@ func (csiNS *CSINodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeSt
314315
func (csiNS *CSINodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
315316
ctxLogger, requestID := utils.GetContextLogger(ctx, false)
316317
ctxLogger.Info("CSINodeServer-NodeUnstageVolume ... ", zap.Reflect("Request", *req))
317-
metrics.UpdateDurationFromStart(ctxLogger, "NodeUnstageVolume", time.Now())
318+
defer metrics.UpdateDurationFromStart(ctxLogger, "NodeUnstageVolume", time.Now())
318319
csiNS.mux.Lock()
319320
defer csiNS.mux.Unlock()
320321

@@ -400,7 +401,7 @@ func (csiNS *CSINodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.Nod
400401
var resp *csi.NodeGetVolumeStatsResponse
401402
ctxLogger, requestID := utils.GetContextLogger(ctx, false)
402403
ctxLogger.Info("CSINodeServer-NodeGetVolumeStats... ", zap.Reflect("Request", *req)) //nolint:staticcheck
403-
metrics.UpdateDurationFromStart(ctxLogger, "NodeGetVolumeStats", time.Now())
404+
defer metrics.UpdateDurationFromStart(ctxLogger, "NodeGetVolumeStats", time.Now())
404405
if req == nil || req.VolumeId == "" { //nolint:staticcheck
405406
return nil, commonError.GetCSIError(ctxLogger, commonError.EmptyVolumeID, requestID, nil)
406407
}

0 commit comments

Comments
 (0)