Skip to content

Conversation

@qiujian16
Copy link
Member

@qiujian16 qiujian16 commented Dec 2, 2025

This commit adds comprehensive log tracing support across the cloudevents subsystem and base controller. Key changes include:

  • Add logging package with tracing annotation utilities
  • Transfer log tracing annotations between CloudEvents and ManifestWork objects
  • Enhance base controller with improved logging context
  • Add comprehensive test coverage for log tracing functionality
  • Update base controller default queue key to be more descriptive

The log tracing feature enables better observability by propagating contextual logging metadata through the CloudEvents flow.

🤖 Generated with Claude Code

Summary

Related issue(s)

Fixes #

Summary by CodeRabbit

  • New Features

    • New log-tracing utilities to propagate tracing metadata between CloudEvents, work objects, and request contexts.
  • Improvements

    • Tracing now flows through create/update/delete and encode/decode paths for improved observability.
    • Controller logs standardized: worker startup field renamed and error-path logging simplified.
    • Default queue key identifier updated for string-triggered controllers.
  • Tests

    • Extensive unit tests added for tracing, encode/decode, controller run/queue behavior, and resync logic.

✏️ Tip: You can customize this high-level summary in your review settings.

@openshift-ci openshift-ci bot requested a review from deads2k December 2, 2025 03:16
@openshift-ci
Copy link

openshift-ci bot commented Dec 2, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link

coderabbitai bot commented Dec 2, 2025

Walkthrough

Adds a log-tracing package and integrates tracing propagation into CloudEvents codecs, clients, and controller flows; changes base controller default queue key and logging fields; and adds extensive unit tests for tracing, codecs, clients, and controller behavior.

Changes

Cohort / File(s) Summary
Logging module
pkg/logging/logging.go, pkg/logging/logging_test.go
New log-tracing utilities and tests: parse/serialize tracing maps between CloudEvent extensions, context, and Kubernetes object annotations; helpers to augment klog.Logger with tracing values; propagation helpers and unit tests for parsing, error handling, and propagation.
Base controller factory
pkg/basecontroller/factory/base_controller.go, pkg/basecontroller/factory/base_controller_test.go, pkg/basecontroller/factory/factory.go
DefaultQueueKey value changed to basecontroller-default-key; worker startup log field key changed; simplified error-handling/log calls in processNextWorkItem; added unit tests covering Run, processing, resync behavior, and requeue-on-error semantics.
Agent manifest bundle codec
pkg/cloudevents/clients/work/agent/codec/manifestbundle.go, pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go
Integrated log-tracing calls into Encode/Decode paths (object ↔ event) with error propagation; added tests validating tracing encode/decode and round-trips.
Source manifest bundle codec & client
pkg/cloudevents/clients/work/source/codec/manifestbundle.go, pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go, pkg/cloudevents/clients/work/source/client/manifestwork.go
Added tracing integration to codec Encode/Decode and to Create/Delete/Patch flows (annotate created/updated/deleting objects from context); small comment wording fix; tests for tracing behaviors (duplicate test block present in diff).
Generic CloudEvents client
pkg/cloudevents/generic/clients/baseclient.go
Use tracing-aware per-event logger in publish/subscribe flows (SetLogTracingByCloudEvent); inject per-event logger into receive context; replace some direct fmt logs with runtime error handling and enhanced logging calls.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • JSON parsing/serialization, error handling, and prefix filtering in pkg/logging/logging.go.
    • Correct error propagation and side-effects in codec Encode/Decode integrations.
    • Ensure base controller behavior is unchanged after DefaultQueueKey value change and logging adjustments.
    • Duplicate test block in pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go may be accidental and should be verified.

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • deads2k

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.04% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature being added: log tracing support for contextual logging, matching the primary changes across the codebase.
Description check ✅ Passed The description covers the main changes and includes a summary section explaining the log tracing feature, though it lacks explicit issue references and some sections remain incomplete per the template.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 556f433 and 7eb19e0.

📒 Files selected for processing (11)
  • pkg/basecontroller/factory/base_controller.go (2 hunks)
  • pkg/basecontroller/factory/base_controller_test.go (1 hunks)
  • pkg/basecontroller/factory/factory.go (1 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/clients/work/source/client/manifestwork.go (4 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/generic/clients/baseclient.go (3 hunks)
  • pkg/logging/logging.go (1 hunks)
  • pkg/logging/logging_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkg/basecontroller/factory/base_controller_test.go
  • pkg/basecontroller/factory/factory.go
  • pkg/cloudevents/generic/clients/baseclient.go
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go
  • pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go
🧰 Additional context used
🧬 Code graph analysis (5)
pkg/basecontroller/factory/base_controller.go (1)
pkg/basecontroller/factory/factory.go (1)
  • DefaultQueueKey (13-13)
pkg/cloudevents/clients/work/source/codec/manifestbundle.go (2)
pkg/cloudevents/generic/types/types.go (1)
  • ExtensionWorkMeta (83-83)
pkg/logging/logging.go (2)
  • LogTracingFromObjectToEvent (143-160)
  • LogTracingFromEventToObject (111-141)
pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (1)
pkg/logging/logging.go (2)
  • LogTracingFromObjectToEvent (143-160)
  • LogTracingFromEventToObject (111-141)
pkg/cloudevents/clients/work/source/client/manifestwork.go (1)
pkg/logging/logging.go (1)
  • SetLogTracingFromContext (93-109)
pkg/logging/logging_test.go (1)
pkg/logging/logging.go (9)
  • LogTracingPrefix (17-17)
  • SetLogTracingByObject (25-38)
  • ExtensionLogTracing (18-18)
  • SetLogTracingByCloudEvent (70-89)
  • ContextTracingOPIDKey (19-19)
  • DefaultContextTracingKeys (23-23)
  • ContextTracingKey (14-14)
  • LogTracingFromEventToObject (111-141)
  • LogTracingFromObjectToEvent (143-160)
🪛 Gitleaks (8.30.0)
pkg/logging/logging_test.go

[high] 139-139: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 155-155: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: unit
  • GitHub Check: integration
  • GitHub Check: verify
🔇 Additional comments (17)
pkg/basecontroller/factory/base_controller.go (3)

83-83: LGTM: Improved log field name for worker identification.

The change from "numberOfWorkers" to "worker-ID" more accurately describes that this is logging the individual worker sequence number (1, 2, 3...) rather than the total count.


160-160: LGTM: Good use of constant instead of magic string.

Replacing the hardcoded string literal with DefaultQueueKey improves maintainability and aligns with the constant definition in factory.go.


160-164: LGTM: Intentional log noise reduction for default queue operations.

The conditional logging strategy is well-designed:

  • Non-default keys or verbose mode: detailed logging with key context
  • Default periodic resync at normal verbosity: simplified logging to reduce noise

The error is correctly passed to HandleErrorWithContext without duplication in the structured logging fields.

pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (2)

72-75: LGTM - Tracing integration in Encode is correctly placed.

The log tracing is added after computing the status hash and before returning the event, ensuring tracing metadata is propagated to the CloudEvent.


157-160: LGTM - Tracing integration in Decode is correctly placed.

The log tracing is added after reconstructing the metadata and before creating the ManifestWork, ensuring tracing annotations are propagated from the CloudEvent to the object.

pkg/cloudevents/clients/work/source/codec/manifestbundle.go (2)

51-54: LGTM - Tracing integration in Encode follows the established pattern.

The log tracing is correctly placed after setting the metadata extension and before handling deletion or data marshalling, ensuring consistent tracing propagation.


128-131: LGTM - Tracing integration in Decode is correctly positioned.

The log tracing is added after setting the sequence annotation and before constructing the ManifestWork, maintaining consistency with the agent codec implementation.

pkg/cloudevents/clients/work/source/client/manifestwork.go (3)

113-114: LGTM - Context tracing correctly integrated in Create flow.

The tracing annotation is added after encoding manifests and before validation/publishing, ensuring context metadata is captured from the incoming request and propagated through the CloudEvents flow.


166-167: LGTM - Context tracing correctly integrated in Delete flow.

The tracing annotation is added to the deleting work before publishing the delete event, ensuring proper tracing throughout the deletion lifecycle.


306-307: LGTM - Context tracing correctly integrated in Patch flow.

The tracing annotation is added after computing the patched work and before validation/publishing, maintaining consistency with the Create operation.

pkg/logging/logging_test.go (1)

1-566: LGTM - Comprehensive test coverage for log tracing functionality.

The test suite thoroughly covers all public functions including edge cases (nil inputs, empty annotations/extensions, invalid JSON). The static analysis warnings on lines 139 and 155 are false positives—these are test operation IDs ("operation-123", "operation-456"), not actual API keys.

pkg/logging/logging.go (6)

14-23: LGTM - Clean type and constant definitions.

The ContextTracingKey type and associated constants provide a clear contract for tracing metadata. The DefaultContextTracingKeys variable allows for extensibility if additional tracing keys are needed in the future.


25-38: LGTM - Logger augmentation correctly filters tracing annotations.

The function properly filters annotations by the LogTracingPrefix, strips the prefix, and augments the logger with the tracing values. The nil check ensures safety.


70-89: LGTM - CloudEvent tracing extraction with proper error handling.

The function safely extracts tracing data from CloudEvent extensions, logs errors without failing the operation, and augments the logger. The graceful error handling ensures observability issues don't break the main flow.


91-109: LGTM - Context-to-object tracing propagation correctly implemented.

The function correctly adds the LogTracingPrefix to annotation keys when propagating from context (line 103), which is essential for the tracing to propagate through CloudEvents. The empty annotation guard prevents unnecessary object updates.

Based on past review comments, this addresses the critical prefix mismatch issue that was previously identified.


111-141: LGTM - Event-to-object tracing propagation is well-structured.

The function safely propagates tracing from CloudEvent extensions to object annotations with proper nil checks and prefix filtering. The empty annotation guard (line 136) prevents unnecessary updates when no tracing data exists.


143-160: LGTM - Object-to-event tracing propagation completes the bidirectional flow.

The function correctly filters annotations by prefix and propagates them to CloudEvent extensions, completing the round-trip tracing flow. The nil checks ensure safety in all scenarios.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot added the approved label Dec 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (1)

374-542: LGTM! Comprehensive test coverage for log tracing.

The test suite thoroughly validates the bidirectional propagation of log tracing data between ManifestWork annotations and CloudEvent extensions. All edge cases are covered, including encode/decode with and without tracing data.

Optional: Consider extracting common test setup code (e.g., creating basic CloudEvents or ManifestWork objects) into helper functions to reduce repetition, though the current inline approach is acceptable for test clarity.

pkg/logging/logging_test.go (1)

190-194: Consider parallel test safety when modifying global state.

The test temporarily modifies the global DefaultContextTracingKeys variable. While the defer correctly restores it, this pattern can cause race conditions if Go's parallel test execution is enabled (via t.Parallel()).

Consider one of these approaches:

  1. Make DefaultContextTracingKeys configurable per-call rather than global
  2. Use a mutex to synchronize access during tests
  3. Document that these tests must not run in parallel

Apply this pattern if refactoring to pass keys as a parameter:

-func SetLogTracingFromContext(ctx context.Context, object metav1.Object) {
+func SetLogTracingFromContext(ctx context.Context, object metav1.Object, keys []ContextTracingKey) {
+	if keys == nil {
+		keys = DefaultContextTracingKeys
+	}
	annotations := object.GetAnnotations()
	if annotations == nil {
		annotations = make(map[string]string)
	}
-	for _, key := range DefaultContextTracingKeys {
+	for _, key := range keys {
pkg/logging/logging.go (1)

81-92: Simplify unnecessary type conversion.

At line 86, value is already a string (from logTracingMap which is map[string]string), so the call to cloudeventstypes.ToString(value) is unnecessary.

Apply this diff to simplify:

	for key, value := range logTracingMap {
		if !strings.HasPrefix(key, LogTracingPrefix) {
			continue
		}
		tracingKey := strings.TrimPrefix(key, LogTracingPrefix)
-		tracingValue, err := cloudeventstypes.ToString(value)
-		if err != nil {
-			logger.Error(err, "Failed to get log tracing value")
-			return logger
-		}
-		logger = logger.WithValues(tracingKey, tracingValue)
+		logger = logger.WithValues(tracingKey, value)
	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a185f88 and 37c5a3b.

📒 Files selected for processing (11)
  • pkg/basecontroller/factory/base_controller.go (2 hunks)
  • pkg/basecontroller/factory/base_controller_test.go (1 hunks)
  • pkg/basecontroller/factory/factory.go (1 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/clients/work/source/client/manifestwork.go (4 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/generic/clients/baseclient.go (3 hunks)
  • pkg/logging/logging.go (1 hunks)
  • pkg/logging/logging_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-11T13:27:36.331Z
Learnt from: morvencao
Repo: open-cluster-management-io/sdk-go PR: 162
File: pkg/cloudevents/generic/options/pubsub/options.go:157-174
Timestamp: 2025-11-11T13:27:36.331Z
Learning: For open-cluster-management PubSub transport in pkg/cloudevents/generic/options/pubsub: broadcast topics (SourceBroadcast, AgentBroadcast) and their corresponding subscriptions are always required, not optional. The omitempty tags on types.Topics broadcast fields exist because the struct is shared with MQTT (where broadcasts are optional), but PubSub requires all broadcast channels for resync functionality.

Applied to files:

  • pkg/cloudevents/generic/clients/baseclient.go
📚 Learning: 2025-09-16T02:22:20.929Z
Learnt from: skeeey
Repo: open-cluster-management-io/sdk-go PR: 144
File: pkg/cloudevents/generic/options/grpc/protocol/protocol.go:200-213
Timestamp: 2025-09-16T02:22:20.929Z
Learning: In the GRPC CloudEvents protocol implementation, when startEventsReceiver encounters a stream error, it sends the error to reconnectErrorChan. The consumer of this channel handles the error by calling Close() on the protocol, which triggers close(p.closeChan), causing OpenInbound to unblock and call cancel() to properly terminate both the events receiver and heartbeat watcher goroutines.

Applied to files:

  • pkg/cloudevents/generic/clients/baseclient.go
🧬 Code graph analysis (8)
pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (1)
pkg/logging/logging.go (2)
  • LogTracingFromObjectToEvent (148-165)
  • LogTracingFromEventToObject (116-146)
pkg/cloudevents/generic/clients/baseclient.go (1)
pkg/logging/logging.go (1)
  • SetLogTracingByCloudEvent (70-94)
pkg/cloudevents/clients/work/source/codec/manifestbundle.go (2)
pkg/cloudevents/generic/types/types.go (1)
  • ExtensionWorkMeta (83-83)
pkg/logging/logging.go (2)
  • LogTracingFromObjectToEvent (148-165)
  • LogTracingFromEventToObject (116-146)
pkg/basecontroller/factory/base_controller_test.go (3)
pkg/basecontroller/factory/interfaces.go (1)
  • SyncContext (34-41)
pkg/basecontroller/factory/controller_context.go (1)
  • NewSyncContext (22-30)
pkg/basecontroller/factory/factory.go (3)
  • DefaultQueueKey (13-13)
  • New (59-61)
  • DefaultQueueKeysFunc (16-18)
pkg/cloudevents/clients/work/source/client/manifestwork.go (1)
pkg/logging/logging.go (1)
  • SetLogTracingFromContext (98-114)
pkg/logging/logging_test.go (1)
pkg/logging/logging.go (10)
  • LogTracingPrefix (17-17)
  • SetLogTracingByObject (25-38)
  • ExtensionLogTracing (18-18)
  • SetLogTracingByCloudEvent (70-94)
  • ContextTracingOPIDKey (19-19)
  • SetLogTracingFromContext (98-114)
  • DefaultContextTracingKeys (23-23)
  • ContextTracingKey (14-14)
  • LogTracingFromEventToObject (116-146)
  • LogTracingFromObjectToEvent (148-165)
pkg/basecontroller/factory/base_controller.go (1)
pkg/basecontroller/factory/factory.go (1)
  • DefaultQueueKey (13-13)
pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (5)
pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (1)
  • NewManifestBundleCodec (37-39)
pkg/cloudevents/clients/work/source/codec/manifestbundle.go (1)
  • NewManifestBundleCodec (23-25)
pkg/cloudevents/clients/utils/utils.go (1)
  • UID (222-225)
pkg/cloudevents/generic/types/types.go (3)
  • CloudEventsType (221-230)
  • CloudEventsDataType (210-214)
  • SubResourceSpec (30-30)
pkg/cloudevents/clients/work/payload/manifestbundle.go (2)
  • ManifestBundleEventDataType (11-15)
  • ManifestBundleStatus (34-52)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: unit
  • GitHub Check: integration
  • GitHub Check: verify
🔇 Additional comments (21)
pkg/basecontroller/factory/base_controller.go (2)

83-83: LGTM!

The log field rename from numberOfWorkers to worker-ID is more descriptive and accurately reflects that i represents the individual worker's identifier, not the total worker count.


160-164: LGTM! The conditional logging reduces noise for periodic resync errors.

When using DefaultQueueKey (typically from periodic resync), errors are logged with a simpler message at lower verbosity levels. The key is included only when V(4) is enabled or for custom queue keys, which helps with debugging specific resource failures without flooding logs during periodic resync issues.

pkg/cloudevents/clients/work/source/client/manifestwork.go (4)

7-8: LGTM!

Import added for the new logging package.


113-114: LGTM! Tracing propagation in Create.

The tracing annotation is correctly set before validation and publishing, ensuring contextual logging metadata flows through the CloudEvents system to the agent.


166-167: LGTM! Tracing propagation in Delete.

Tracing is set on deletingWork before publishing the delete event, maintaining observability through the deletion flow.


306-307: LGTM! Tracing propagation in Patch.

Tracing is set on newWork before validation and publishing, consistent with the Create method pattern.

pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (3)

9-9: LGTM!

Import added for the logging package.


72-75: LGTM! Tracing transfer from object to event in Encode.

Transfers log tracing annotations from the ManifestWork to the CloudEvent extensions during status encoding. The placement after status hash computation and before metadata serialization is appropriate.


157-160: LGTM! Tracing transfer from event to object in Decode.

Transfers log tracing from CloudEvent extensions to work object annotations during spec decoding. This enables the agent to receive and preserve tracing context from the source.

pkg/cloudevents/clients/work/source/codec/manifestbundle.go (4)

8-8: LGTM!

Import added for the logging package.


44-44: LGTM!

Minor comment improvement: "meta data" → "metadata".


51-54: LGTM! Tracing transfer from object to event in Encode.

Transfers log tracing annotations from the ManifestWork to CloudEvent extensions during spec encoding for the source-to-agent flow.


128-131: LGTM! Tracing transfer from event to object in Decode.

Transfers log tracing from CloudEvent extensions to work object annotations when decoding status updates from agents.

pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go (1)

459-724: LGTM! Comprehensive test coverage for log tracing.

The test suite thoroughly covers the log tracing functionality:

  • Encode preserves tracing annotations and filters non-tracing ones
  • Decode transfers tracing extensions to object annotations
  • Edge cases with no tracing data are handled correctly
  • Round-trip test validates end-to-end tracing preservation

The tests align well with the logging utilities in pkg/logging/logging.go.

pkg/cloudevents/generic/clients/baseclient.go (3)

6-6: LGTM!

Import added for the logging package.


123-123: LGTM! Log enrichment in publish.

The logger is now enriched with tracing information from the CloudEvent being published, improving observability for outgoing events.


205-213: LGTM! Log enrichment and context propagation in receive path.

Key improvements:

  • Creates a per-event logger enriched with tracing data via SetLogTracingByCloudEvent
  • Updates the context with this logger so downstream handlers (the receive callback) can access it via klog.FromContext(ctx)
  • Error handling uses HandleErrorWithContext with a clearer message

This ensures tracing metadata flows through the entire receive → decode → handler chain.

pkg/basecontroller/factory/base_controller_test.go (1)

1-363: LGTM! Comprehensive test coverage for the base controller.

The test file provides thorough coverage including:

  • Controller run lifecycle with various worker counts
  • Cache sync and periodic resync behavior
  • Work item processing with success/error paths
  • Queue requeue behavior on failures
  • Accessor methods (Name, SyncContext, Sync)
  • DefaultQueueKeysFunc behavior

The use of sync.WaitGroup for async synchronization and proper queue cleanup via ShutDown() demonstrates good test hygiene.

pkg/basecontroller/factory/factory.go (1)

12-13: More descriptive default queue key, but verify external consumer impact.

The rename from "key" to "basecontroller-default-key" is clearer and reduces collision risk with actual resource keys. However, this is a breaking change if external consumers depend on the exact string value of DefaultQueueKey. Confirm that:

  • No external consumers rely on the hardcoded "key" value
  • Public API documentation is updated if this constant is exported
  • Integration tests cover controllers using this default queue key
pkg/logging/logging_test.go (1)

245-566: LGTM! Thorough test coverage for tracing propagation.

The remaining test functions comprehensively validate:

  • Event-to-object and object-to-event tracing transfers
  • Nil input handling
  • Edge cases with missing/invalid data
  • Round-trip scenarios via extension helpers

Testing unexported helper functions (getTracingMapFromExtenstion, setTracingMapToExtenstion) in the same package is appropriate for verifying internal behavior.

pkg/logging/logging.go (1)

116-165: LGTM! Clean bidirectional tracing propagation.

Both LogTracingFromEventToObject and LogTracingFromObjectToEvent correctly:

  • Handle nil inputs gracefully
  • Filter keys by the tracing prefix
  • Initialize annotation maps when needed
  • Propagate tracing data between CloudEvents and Kubernetes objects

The symmetry between these functions ensures consistent behavior in both directions.

@qiujian16 qiujian16 force-pushed the add-log-tracing-support branch 2 times, most recently from 24d17f6 to 556f433 Compare December 2, 2025 03:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/basecontroller/factory/base_controller_test.go (2)

179-182: Consider more robust synchronization for rate-limited requeue.

The 10ms sleep is used to wait for rate-limited items to be requeued. While this pattern is common in controller tests, it can be flaky in heavily loaded environments.

Consider using a retry loop with a reasonable timeout to check queue length, which would be more resilient than a fixed sleep.


199-240: Clarify test purpose or rename.

The test name "TestBaseControllerDefaultQueueKey" and the comment "tests the error logging behavior with DefaultQueueKey" suggest it's testing logging functionality. However, the test only verifies requeue behavior on sync errors, which is already covered by TestBaseControllerProcessNextWorkItem.

Either enhance this test to actually verify error logging (e.g., using a custom log sink to capture log output) or rename it to better reflect what it tests, such as TestBaseControllerRequeueBehavior.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37c5a3b and 556f433.

📒 Files selected for processing (11)
  • pkg/basecontroller/factory/base_controller.go (2 hunks)
  • pkg/basecontroller/factory/base_controller_test.go (1 hunks)
  • pkg/basecontroller/factory/factory.go (1 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/clients/work/source/client/manifestwork.go (4 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle.go (3 hunks)
  • pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (1 hunks)
  • pkg/cloudevents/generic/clients/baseclient.go (3 hunks)
  • pkg/logging/logging.go (1 hunks)
  • pkg/logging/logging_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkg/basecontroller/factory/base_controller.go
  • pkg/cloudevents/clients/work/source/codec/manifestbundle.go
  • pkg/cloudevents/clients/work/agent/codec/manifestbundle_test.go
  • pkg/cloudevents/generic/clients/baseclient.go
  • pkg/basecontroller/factory/factory.go
🧰 Additional context used
🧬 Code graph analysis (4)
pkg/cloudevents/clients/work/source/client/manifestwork.go (1)
pkg/logging/logging.go (1)
  • SetLogTracingFromContext (93-109)
pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (1)
pkg/logging/logging.go (2)
  • LogTracingFromObjectToEvent (143-160)
  • LogTracingFromEventToObject (111-141)
pkg/logging/logging_test.go (1)
pkg/logging/logging.go (9)
  • LogTracingPrefix (17-17)
  • SetLogTracingByObject (25-38)
  • ExtensionLogTracing (18-18)
  • SetLogTracingByCloudEvent (70-89)
  • ContextTracingOPIDKey (19-19)
  • DefaultContextTracingKeys (23-23)
  • ContextTracingKey (14-14)
  • LogTracingFromEventToObject (111-141)
  • LogTracingFromObjectToEvent (143-160)
pkg/basecontroller/factory/base_controller_test.go (2)
pkg/basecontroller/factory/interfaces.go (1)
  • SyncContext (34-41)
pkg/basecontroller/factory/controller_context.go (1)
  • NewSyncContext (22-30)
🪛 Gitleaks (8.30.0)
pkg/logging/logging_test.go

[high] 139-139: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 155-155: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration
🔇 Additional comments (18)
pkg/basecontroller/factory/base_controller_test.go (7)

15-28: LGTM! Mock is sufficient for current test coverage.

The mockInformer provides a minimal implementation that satisfies the test requirements. The handlers are tracked but never invoked, which is acceptable since the current tests only verify cache synchronization via HasSynced.


54-60: Review the timing assumptions for periodic resync test.

The test expects sync to be called via periodic resync (100ms interval) without explicitly adding items to the queue. While this should work, the timing is tight: the controller needs to start, wait for cache sync (up to 1s), start workers, trigger periodic resync, and process the item—all within the 1500ms wait timeout.

Consider increasing the timeout slightly or using a shorter resync interval to make the test more resilient in slow CI environments.


242-251: LGTM! Clean accessor test.

The test correctly verifies the Name() method returns the controller name.


253-263: LGTM! Clean accessor test.

The test correctly verifies the SyncContext() method returns the sync context.


265-292: LGTM! Thorough test of Sync method.

The test correctly verifies that the Sync() method calls the sync function with the expected key and propagates errors correctly.


294-329: LGTM! Well-designed periodic resync test.

The test correctly verifies periodic resync functionality. The conservative check for at least 1 item (rather than exactly 8) makes the test resilient to timing variations while still confirming the periodic resync is working.


331-363: LGTM! Comprehensive test of DefaultQueueKeysFunc.

The test correctly verifies that DefaultQueueKeysFunc returns DefaultQueueKey for both nil and non-nil objects, matching the expected behavior from the function definition in factory.go.

pkg/cloudevents/clients/work/agent/codec/manifestbundle.go (2)

72-75: LGTM! Clean integration of log tracing in encode path.

The placement of the tracing call after setting the status hash is appropriate, and error handling correctly propagates failures.


157-160: LGTM! Clean integration of log tracing in decode path.

The tracing call is well-positioned after metadata population, and error handling is appropriate.

pkg/cloudevents/clients/work/source/client/manifestwork.go (3)

113-114: LGTM! Context tracing correctly added to Create path.

The placement after manifest encoding and before validation is appropriate.


166-167: LGTM! Context tracing correctly added to Delete path.

Consistent with other operations and well-placed before event publishing.


306-307: LGTM! Context tracing correctly added to Patch path.

The placement after resource version computation and before validation is appropriate.

pkg/cloudevents/clients/work/source/codec/manifestbundle_test.go (1)

374-542: Excellent test coverage for log tracing functionality.

The test suite comprehensively covers:

  • Encoding with tracing annotations (including prefix filtering)
  • Decoding with tracing extensions
  • Edge cases with missing tracing data

The assertions correctly verify that only annotations with the LogTracingPrefix are propagated.

pkg/logging/logging_test.go (1)

1-566: Comprehensive and well-structured test suite.

The tests provide excellent coverage of all logging tracing functions, including:

  • Nil handling
  • Error cases (invalid JSON)
  • Edge cases (missing extensions, no annotations)
  • Context value propagation

Note: The Gitleaks static analysis warnings at lines 139 and 155 are false positives—these are test values ("operation-123", "operation-456"), not actual API keys.

pkg/logging/logging.go (4)

25-38: LGTM! Well-implemented logger augmentation.

The function correctly:

  • Handles nil objects
  • Filters annotations by LogTracingPrefix
  • Returns an augmented logger with tracing values

70-89: LGTM! Robust error handling in CloudEvent logger augmentation.

The function appropriately:

  • Handles nil events
  • Logs errors when tracing map extraction fails (rather than failing silently)
  • Returns a valid logger in all cases

111-141: LGTM! Clean implementation of event-to-object tracing transfer.

The function correctly:

  • Handles nil inputs
  • Propagates errors from extension parsing
  • Filters by LogTracingPrefix
  • Preserves existing annotations

143-160: LGTM! Clean implementation of object-to-event tracing transfer.

The function correctly filters annotations by LogTracingPrefix and propagates them to the CloudEvent extension.

evt.SetExtension(types.ExtensionStatusHash, statusHash)

// Add log tracing extension
if err := logging.LogTracingFromObjectToEvent(work, &evt); err != nil {
Copy link
Member

@skeeey skeeey Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need add this in other resources codec (cluster/addon ...)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be done as follow up. But the other resources can be actually tracked by resource name.

const (
LogTracingPrefix = "logging.open-cluster-management.io/"
ExtensionLogTracing = "logtracing"
ContextTracingOPIDKey ContextTracingKey = "op-id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may use opid instead of op-id, @machi1990 is opid used in use in CS for now?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. We use an iota.
It should be okay from cs and we could adapt to the contract put here.

Also, let's also consider the LIST/GET endpoints which are restful APIs

This commit adds comprehensive log tracing support across the cloudevents
subsystem and base controller. Key changes include:

- Add logging package with tracing annotation utilities
- Transfer log tracing annotations between CloudEvents and ManifestWork objects
- Enhance base controller with improved logging context
- Add comprehensive test coverage for log tracing functionality
- Update base controller default queue key to be more descriptive

The log tracing feature enables better observability by propagating
contextual logging metadata through the CloudEvents flow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Jian Qiu <[email protected]>
@qiujian16 qiujian16 force-pushed the add-log-tracing-support branch from 556f433 to 7eb19e0 Compare December 2, 2025 14:17
Copy link
Member

@morvencao morvencao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants