Skip to content

Commit

Permalink
feat: add node metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Oct 17, 2023
1 parent 459bfe2 commit 86ce2a1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 0 deletions.
Binary file modified charts/latest/azurefile-csi-driver-v1.29.0.tgz
Binary file not shown.
Expand Up @@ -124,6 +124,7 @@ spec:
- "--allow-empty-cloud-config={{ .Values.node.allowEmptyCloudConfig }}"
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
- "--enable-windows-host-process=true"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
env:
- name: AZURE_CREDENTIAL_FILE
valueFrom:
Expand Down
Expand Up @@ -137,6 +137,7 @@ spec:
- "--allow-empty-cloud-config={{ .Values.node.allowEmptyCloudConfig }}"
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
- "--allow-inline-volume-key-access-with-identity={{ .Values.node.allowInlineVolumeKeyAccessWithIdentity }}"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
ports:
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
name: healthz
Expand Down
Expand Up @@ -135,6 +135,7 @@ spec:
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
- "--mount-permissions={{ .Values.linux.mountPermissions }}"
- "--allow-inline-volume-key-access-with-identity={{ .Values.node.allowInlineVolumeKeyAccessWithIdentity }}"
- "--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/azurefile-csi-driver/values.yaml
Expand Up @@ -124,6 +124,7 @@ node:
cloudConfigSecretNamespace: kube-system
allowEmptyCloudConfig: true
allowInlineVolumeKeyAccessWithIdentity: false
metricsPort: 29615
livenessProbe:
healthPort: 29613
logLevel: 5
Expand Down
1 change: 1 addition & 0 deletions deploy/csi-azurefile-node-windows-hostprocess.yaml
Expand Up @@ -87,6 +87,7 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --nodeid=$(KUBE_NODE_NAME)
- --enable-windows-host-process=true
- --metrics-address="0.0.0.0:29615"
env:
- name: AZURE_CREDENTIAL_FILE
valueFrom:
Expand Down
1 change: 1 addition & 0 deletions deploy/csi-azurefile-node-windows.yaml
Expand Up @@ -100,6 +100,7 @@ spec:
- --v=5
- --endpoint=$(CSI_ENDPOINT)
- --nodeid=$(KUBE_NODE_NAME)
- --metrics-address="0.0.0.0:29615"
ports:
- containerPort: 29613
name: healthz
Expand Down
1 change: 1 addition & 0 deletions deploy/csi-azurefile-node.yaml
Expand Up @@ -91,6 +91,7 @@ spec:
- "--v=5"
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(KUBE_NODE_NAME)"
- "--metrics-address=0.0.0.0:29615"
ports:
- containerPort: 29613
name: healthz
Expand Down
23 changes: 23 additions & 0 deletions pkg/azurefile/nodeserver.go
Expand Up @@ -37,6 +37,7 @@ import (
"golang.org/x/net/context"

azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
"sigs.k8s.io/cloud-provider-azure/pkg/metrics"
)

// NodePublishVolume mount the volume from staging to target path
Expand Down Expand Up @@ -158,6 +159,12 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
volumeMountGroup := req.GetVolumeCapability().GetMount().GetVolumeMountGroup()
gidPresent := checkGidPresentInMountFlags(mountFlags)

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

_, accountName, accountKey, fileShareName, diskName, _, err := d.GetAccountInfo(ctx, volumeID, req.GetSecrets(), context)
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("GetAccountInfo(%s) failed with error: %v", volumeID, err))
Expand Down Expand Up @@ -369,6 +376,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
}
}
}

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

Expand All @@ -388,6 +397,12 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
}
defer d.volumeLocks.Release(volumeID)

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

klog.V(2).Infof("NodeUnstageVolume: CleanupMountPoint volume %s on %s", volumeID, stagingTargetPath)
if err := CleanupMountPoint(d.mounter, stagingTargetPath, true /*extensiveMountPointCheck*/); err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount staging target %s: %v", stagingTargetPath, err)
Expand All @@ -400,6 +415,7 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
}
klog.V(2).Infof("NodeUnstageVolume: unmount volume %s on %s successfully", volumeID, stagingTargetPath)

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

Expand Down Expand Up @@ -472,6 +488,12 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
klog.V(6).Infof("NodeGetVolumeStats: begin to get VolumeStats on volume %s path %s", req.VolumeId, req.VolumePath)
}

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

resp, err := GetVolumeStats(req.VolumePath, d.enableWindowsHostProcess)
if err == nil && resp != nil {
if d.printVolumeStatsCallLogs {
Expand All @@ -485,6 +507,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
d.volStatsCache.Set(newVolID, *resp)
}
}
isOperationSucceeded = true
return resp, err
}

Expand Down

0 comments on commit 86ce2a1

Please sign in to comment.