Skip to content

Remove fmt.Println, convert to log #3718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sovietaced
Copy link

@Sovietaced Sovietaced commented May 30, 2025

Why are these changes needed?

I work on some code that integrates with kuberay and we noticed some printlns in the output. I have removed unnecessary printlns and moved useful ones to use the logger so the output will be uniform.

Related issue number

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

@Sovietaced Sovietaced marked this pull request as ready for review May 30, 2025 06:11
@kevin85421 kevin85421 requested a review from Copilot June 3, 2025 00:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors logging by removing direct fmt.Println/Printf calls and converting them into structured logging calls, while also updating several utility functions to accept a context parameter for better consistency. Key changes include:

  • Replacing fmt-based output in utilities with ctx-aware log.Info calls.
  • Updating function signatures (e.g. CheckName, CheckLabel, TrimJobName) and corresponding test cases to require an explicit context.
  • Propagating context through various controllers and helpers to improve logging and maintain consistency.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ray-operator/controllers/ray/utils/util_test.go Updated test to pass context when calling CheckName
ray-operator/controllers/ray/utils/util.go Modified CheckName to accept context and log infos
ray-operator/controllers/ray/suite_helpers_test.go Removed fmt.Println calls in favor of structured logging
ray-operator/controllers/ray/raycluster_controller_unit_test.go Converted CheckLabel calls to include context
ray-operator/controllers/ray/raycluster_controller.go Passed context to utility functions within reconcilers
ray-operator/controllers/ray/common/test_utils.go Updated shortString to receive context
ray-operator/controllers/ray/common/service_test.go Passed context into HeadServiceLabels in tests
ray-operator/controllers/ray/common/service.go Updated function signatures to include ctx, improved logging
ray-operator/controllers/ray/common/route_test.go Modified BuildRouteForHeadService call to pass context
ray-operator/controllers/ray/common/route.go Updated BuildRouteForHeadService to take context
ray-operator/controllers/ray/common/rbac_test.go Passed context to BuildRoleBinding within tests
ray-operator/controllers/ray/common/rbac.go Updated BuildRoleBinding function to accept context
ray-operator/controllers/ray/common/pod_test.go Updated test assertions to use context-aware utilities
ray-operator/controllers/ray/common/pod.go Passed context into CheckName and labelPod calls
ray-operator/controllers/ray/common/ingress.go Passed context argument to CheckLabel
ray-operator/controllers/ray/common/association_test.go Updated HeadServiceLabels usage to include context
ray-operator/controllers/ray/common/association.go Updated RayClusterHeadServiceListOptions to require context
Comments suppressed due to low confidence (1)

ray-operator/controllers/ray/common/pod.go:187

  • Verify that the context propagation and usage in utility functions like CheckName is consistent across similar code paths to ensure uniform logging across the codebase.
podTemplate.Spec.ServiceAccountName = utils.CheckName(ctx, utils.GetHeadGroupServiceAccountName(&instance))

maxLength := 50 // 63 - (max(8,6) + 5 ) // 6 to 8 char are consumed at the end with "-head-" or -worker- + 5 generated.

if len(s) > maxLength {
// shorten the name
offset := int(math.Abs(float64(maxLength) - float64(len(s))))
fmt.Printf("pod name is too long: len = %v, we will shorten it by offset = %v", len(s), offset)
log.Info("pod name is too long, we will shorten it by offset", "nameLength", len(s), "offset", offset)
Copy link
Preview

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider including additional context—in particular, the truncated segment or original name length—in the log message to aid in debugging in production.

Suggested change
log.Info("pod name is too long, we will shorten it by offset", "nameLength", len(s), "offset", offset)
log.Info("pod name is too long, we will shorten it by offset", "originalName", s, "truncatedSegment", s[:offset], "nameLength", len(s), "offset", offset)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant