Skip to content

Commit

Permalink
chore: provide a driver flag to print volume stats call with log level 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Sep 18, 2023
1 parent 6251d95 commit 4c2c87a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/azurefile/azurefile.go
Expand Up @@ -208,6 +208,7 @@ type DriverOptions struct {
AppendNoShareSockOption bool
SkipMatchingTagCacheExpireInMinutes int
VolStatsCacheExpireInMinutes int
PrintVolumeStatsCallLogs bool
}

// Driver implements all interfaces of CSI drivers
Expand All @@ -231,6 +232,7 @@ type Driver struct {
enableWindowsHostProcess bool
appendClosetimeoOption bool
appendNoShareSockOption bool
printVolumeStatsCallLogs bool
fileClient *azureFileClient
mounter *mount.SafeFormatAndMount
// lock per volume attach (only for vhd disk feature)
Expand Down Expand Up @@ -284,6 +286,7 @@ func NewDriver(options *DriverOptions) *Driver {
driver.enableWindowsHostProcess = options.EnableWindowsHostProcess
driver.appendClosetimeoOption = options.AppendClosetimeoOption
driver.appendNoShareSockOption = options.AppendNoShareSockOption
driver.printVolumeStatsCallLogs = options.PrintVolumeStatsCallLogs
driver.volLockMap = newLockMap()
driver.subnetLockMap = newLockMap()
driver.volumeLocks = newVolumeLocks()
Expand Down
13 changes: 11 additions & 2 deletions pkg/azurefile/nodeserver.go
Expand Up @@ -466,10 +466,19 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
return nil, status.Errorf(codes.Internal, "failed to stat file %s: %v", req.VolumePath, err)
}

klog.V(6).Infof("NodeGetVolumeStats: begin to get VolumeStats on volume %s path %s", req.VolumeId, req.VolumePath)
if d.printVolumeStatsCallLogs {
klog.V(2).Infof("NodeGetVolumeStats: begin to get VolumeStats on volume %s path %s", req.VolumeId, req.VolumePath)
} else {
klog.V(6).Infof("NodeGetVolumeStats: begin to get VolumeStats on volume %s path %s", req.VolumeId, req.VolumePath)
}

resp, err := GetVolumeStats(req.VolumePath, d.enableWindowsHostProcess)
if err == nil && resp != nil {
klog.V(6).Infof("NodeGetVolumeStats: volume stats for volume %s path %s is %v", req.VolumeId, req.VolumePath, resp)
if d.printVolumeStatsCallLogs {
klog.V(2).Infof("NodeGetVolumeStats: volume stats for volume %s path %s is %v", req.VolumeId, req.VolumePath, resp)
} else {
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)
if newVolID != "" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/azurefileplugin/main.go
Expand Up @@ -61,6 +61,7 @@ var (
appendNoShareSockOption = flag.Bool("append-nosharesock-option", true, "Whether appending nosharesock option to smb mount command")
skipMatchingTagCacheExpireInMinutes = flag.Int("skip-matching-tag-cache-expire-in-minutes", 30, "The cache expire time in minutes for skipMatchingTagCache")
volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
printVolumeStatsCallLogs = flag.Bool("print-volume-stats-call-logs", false, "Whether to print volume statfs call logs with log level 2")
)

func main() {
Expand Down Expand Up @@ -107,6 +108,7 @@ func handle() {
AppendNoShareSockOption: *appendNoShareSockOption,
SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes,
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
PrintVolumeStatsCallLogs: *printVolumeStatsCallLogs,
}
driver := azurefile.NewDriver(&driverOptions)
if driver == nil {
Expand Down

0 comments on commit 4c2c87a

Please sign in to comment.