Skip to content

[Feature Request] Migrate to Structured Logging #312

Description

@marcoma2018

Summary

OpenKruise rollout currently uses klog for unstructured logging, which makes troubleshooting and observability challenging. This feature request proposes migrating to structured logging to improve developer experience and operational efficiency.

Current Challenges

  • Using klog with plain text log format
  • Difficult to query and filter logs programmatically
  • Limited integration with modern observability tools (Loki, ELK, etc.)
  • Manual parsing required for log analysis

Proposed Solution

Migrate to structured logging (JSON format) while maintaining backward compatibility:

// Current

I0118 10:30:45.123456 kruise-controller: Reconciling CloneSet default/my-cloneset, replicas: 3, ready: 2

// Proposed

{
  "timestamp": "2024-01-18T10:30:45.123456Z",
  "level": "INFO",
  "component": "kruise-controller",
  "message": "Reconciling CloneSet",
  "resource": {
    "kind": "CloneSet",
    "namespace": "default",
    "name": "my-cloneset"
  },
  "replicas": 3,
  "ready": 2
}

Benefits

For Developers

  • Faster debugging: Query specific resources, components, or error types instantly
  • Better correlation: Link related logs using trace IDs or request IDs
  • Automated analysis: Enable log aggregation and pattern detection

For Operations

  • Enhanced monitoring: Set up precise alerts based on structured fields
  • Improved observability: Seamless integration with Loki, Elasticsearch, and other log collectors
  • Efficient querying: Filter by component, resource type, or custom fields

Examples of Improved Queries

kubectl logs -n kruise-rollout deployment/kruise-controller-manager | jq 'select(.level=="ERROR" and (.msg | contains("CloneSet")))'

kubectl logs -n kruise-rollout deployment/kruise-controller-manager | jq 'select(.msg | contains("my-cloneset"))'

This enhancement aligns with cloud-native best practices and significantly improves the debugging experience for both contributors and end users.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions