-
Notifications
You must be signed in to change notification settings - Fork 248
Fix raw byte array formatting in logs for json.RawMessage fields #3674
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
There was a problem hiding this 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 improves log readability by replacing the default raw byte array formatting with a proper JSON string representation for logs containing json.RawMessage fields. The key changes include:
- Introducing a new toJSONString helper function in both log/logger.go and cns/logger/cnslogger.go.
- Updating structured logging methods to use toJSONString for formatting.
- Falling back to the original %+v formatting if JSON marshaling fails.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
log/logger.go | Added toJSONString helper and updated Request, Response, and ResponseEx formatting. |
cns/logger/cnslogger.go | Added toJSONString helper and updated Request, Response, and ResponseEx logging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deduplicate and add tests
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
I've addressed this feedback in commit 3da0544:
Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still a lint issue
log/logger.go:210: File is not `gci`-ed with --skip-generated -s standard -s default (gci)
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
I fixed the lint issue in log/logger.go by running gci with the --skip-generated -s standard -s default flags. The issue was caused by an extra whitespace at line 210. Fixed in commit 3a8f2ed. |
/azp run Azure Container Networking PR |
Azure Pipelines successfully started running 1 pipeline(s). |
This pull request is stale because it has been open for 2 weeks with no activity. Remove stale label or comment or this will be closed in 7 days |
Problem
When CNS logs structures containing
json.RawMessage
fields (such asOrchestratorContext
), it uses Go's%+v
format specifier which outputs raw bytes as integer arrays. This makes the logs very difficult to read and understand, as shown in this example:These bytes actually represent the JSON string:
Solution
This PR introduces a new
toJSONString
helper function in both the base logger (log/logger.go
) and CNS logger (cns/logger/cnslogger.go
) that properly formats objects containingjson.RawMessage
fields.The approach:
json.Marshal
instead of%+v
to convert objects to strings for loggingjson.RawMessage
fields are properly formatted as JSON%+v
formatting if JSON marshaling failsExample
Before:
After:
Fixes #3673.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.fwupd.org
/usr/bin/fwupdmgr refresh
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.