Skip to content

Feature Request: Migrate from klog to Zap for True Structured Logging Support #1060

@james-rem

Description

@james-rem

Feature Request: Migrate from klog to Zap for True Structured Logging Support

Summary

Replace the current klog-based logging implementation in csi-driver-smb with Uber's Zap logging library to enable proper structured logging with JSON output and improved observability.

Problem Statement

The current logging implementation in csi-driver-smb uses klog v2, which has significant limitations for structured logging:

  1. No Native JSON Output: klog's "structured" logging (InfoS, ErrorS) outputs key=value format, not JSON
  2. Limited Field Types: klog doesn't handle complex field types well (nested objects, arrays)
  3. Poor Integration with Modern Observability: Most log aggregation systems (ELK, Grafana, Datadog) expect JSON logs
  4. Difficult Debugging: Key=value format is harder to parse and search compared to proper JSON
  5. No Context Propagation: Limited ability to carry request context through log messages

Current State Example

klog.InfoS("Processing mount request",
  "volumeId", req.VolumeId,
  "targetPath", req.TargetPath,
  "mountOptions", req.VolumeCapability.GetMount().MountFlags)

Output:

I0409 12:34:56.123456 1234 nodeserver.go:45] "Processing mount request" volumeId="pvc-123" targetPath="/var/lib/kubelet/pods/..." mountOptions=[rw,file_mode=0777]

This format is:

  • Not parseable as JSON
  • Difficult to query in log aggregation systems
  • Missing timestamps in structured format
  • Lacks correlation IDs for tracing

Proposed Solution

Migrate to Uber Zap for structured logging with the following benefits:

1. True JSON Output

logger.Info("Processing mount request",
  zap.String("volumeId", req.VolumeId),
  zap.String("targetPath", req.TargetPath),
  zap.Strings("mountOptions", req.VolumeCapability.GetMount().MountFlags),
  zap.String("requestId", requestId))

Output:

{
"level": "info",
"ts": 1712345678.123456,
"caller": "smb/nodeserver.go:45",
"msg": "Processing mount request",
"volumeId": "pvc-123",
"targetPath": "/var/lib/kubelet/pods/...",
"mountOptions": ["rw", "file_mode=0777"],
"requestId": "req-abc123"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions