Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1069 from andyzhangx/add-node-metrics
Browse files Browse the repository at this point in the history
feat: add node metrics
  • Loading branch information
andyzhangx authored Oct 18, 2023
2 parents c84d27d + a74154b commit 87a48b6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Binary file modified charts/latest/blob-csi-driver-v0.0.0.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions charts/latest/blob-csi-driver/templates/csi-blob-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ spec:
- "--mount-permissions={{ .Values.node.mountPermissions }}"
- "--allow-inline-volume-key-access-with-idenitity={{ .Values.node.allowInlineVolumeKeyAccessWithIdentity }}"
- "--enable-aznfs-mount={{ .Values.node.enableAznfsMount }}"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
ports:
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
name: healthz
Expand Down
1 change: 1 addition & 0 deletions charts/latest/blob-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ node:
allowEmptyCloudConfig: true
allowInlineVolumeKeyAccessWithIdentity: false
maxUnavailable: 1
metricsPort: 29635
livenessProbe:
healthPort: 29633
logLevel: 5
Expand Down
1 change: 1 addition & 0 deletions deploy/csi-blob-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ spec:
- "--blobfuse-proxy-endpoint=$(BLOBFUSE_PROXY_ENDPOINT)"
- "--nodeid=$(KUBE_NODE_NAME)"
- "--user-agent-suffix=OSS-kubectl"
- "--metrics-address=0.0.0.0:29635"
ports:
- containerPort: 29633
name: healthz
Expand Down
2 changes: 2 additions & 0 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewFakeDriver() *Driver {
driver.Name = fakeDriverName
driver.Version = vendorVersion
driver.subnetLockMap = util.NewLockMap()
driver.cloud = &azure.Cloud{}
return driver
}

Expand Down Expand Up @@ -92,6 +93,7 @@ func TestNewDriver(t *testing.T) {
fakedriver.accountSearchCache = driver.accountSearchCache
fakedriver.dataPlaneAPIVolCache = driver.dataPlaneAPIVolCache
fakedriver.volStatsCache = driver.volStatsCache
fakedriver.cloud = driver.cloud
assert.Equal(t, driver, fakedriver)
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

volumehelper "sigs.k8s.io/blob-csi-driver/pkg/util"
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
"sigs.k8s.io/cloud-provider-azure/pkg/metrics"

"github.com/Azure/azure-sdk-for-go/storage"
"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -238,6 +239,12 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
attrib := req.GetVolumeContext()
secrets := req.GetSecrets()

mc := metrics.NewMetricContext(blobCSIDriverName, "node_stage_volume", d.cloud.ResourceGroup, "", d.Name)
isOperationSucceeded := false
defer func() {
mc.ObserveOperationWithResult(isOperationSucceeded, VolumeID, volumeID)
}()

var serverAddress, storageEndpointSuffix, protocol, ephemeralVolMountOptions string
var ephemeralVol, isHnsEnabled bool

Expand Down Expand Up @@ -340,6 +347,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
klog.V(2).Infof("skip chmod on targetPath(%s) since mountPermissions is set as 0", targetPath)
}

isOperationSucceeded = true
klog.V(2).Infof("volume(%s) mount %s on %s succeeded", volumeID, source, targetPath)
return &csi.NodeStageVolumeResponse{}, nil
}
Expand Down Expand Up @@ -442,13 +450,20 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
}
defer d.volumeLocks.Release(volumeID)

mc := metrics.NewMetricContext(blobCSIDriverName, "node_unstage_volume", d.cloud.ResourceGroup, "", d.Name)
isOperationSucceeded := false
defer func() {
mc.ObserveOperationWithResult(isOperationSucceeded, VolumeID, volumeID)
}()

klog.V(2).Infof("NodeUnstageVolume: volume %s unmounting on %s", volumeID, stagingTargetPath)
err := mount.CleanupMountPoint(stagingTargetPath, d.mounter, true /*extensiveMountPointCheck*/)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount staging target %q: %v", stagingTargetPath, err)
}
klog.V(2).Infof("NodeUnstageVolume: volume %s unmount on %s successfully", volumeID, stagingTargetPath)

isOperationSucceeded = true
return &csi.NodeUnstageVolumeResponse{}, nil
}

Expand Down Expand Up @@ -491,6 +506,12 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
return &resp, nil
}

mc := metrics.NewMetricContext(blobCSIDriverName, "node_get_volume_stats", d.cloud.ResourceGroup, "", d.Name)
isOperationSucceeded := false
defer func() {
mc.ObserveOperationWithResult(isOperationSucceeded, VolumeID, req.VolumeId)
}()

if _, err := os.Lstat(req.VolumePath); err != nil {
if os.IsNotExist(err) {
return nil, status.Errorf(codes.NotFound, "path %s does not exist", req.VolumePath)
Expand Down Expand Up @@ -548,6 +569,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
},
}

isOperationSucceeded = true
klog.V(6).Infof("NodeGetVolumeStats: volume stats for volume %s path %s is %v", req.VolumeId, req.VolumePath, resp)
// cache the volume stats per volume
d.volStatsCache.Set(req.VolumeId, *resp)
Expand Down

0 comments on commit 87a48b6

Please sign in to comment.