Repository navigation
refactor(log): unify Go logging to zap with rotation, strip per-package levels - #16261
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughReplaces all standard-library ChangesStructured Logging Overhaul
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/admin_server.go`:
- Around line 171-172: The admin server is registering common.GinLogger() before
calling r.Setup(ginEngine) in admin_server.go, which creates an inconsistency
with the pattern used in server_main.go. Move the common.GinLogger()
registration from admin_server.go line 171 (where
ginEngine.Use(common.GinLogger()) is called) into the admin router's Setup
method in admin/router.go so that the logger middleware is registered inside
Setup along with the route registrations, matching the established pattern used
in the main server's internal/router/router.go. This ensures consistent
middleware handling across all router implementations.
In `@internal/agent/component/llm_credentials.go`:
- Around line 68-70: The common.Debug calls logging LLM credentials in the
llm_credentials.go file are emitting the full base_url value, which may contain
embedded secrets and poses a security risk. Locate both occurrences of the
zap.String("base_url", baseURL) field in the debug logs (around line 70 and
lines 126-130) and replace it with a sanitized alternative that either logs only
the presence or length of the base_url, or extracts and logs only the sanitized
host portion without any credentials or paths that could contain secrets.
In `@internal/agent/component/universe_a_wrappers.go`:
- Around line 440-443: The CodeExec wrapper invoke debug log at the common.Debug
call is exposing raw payloads via zap.Any() fields for params, inputs, and
merged parameters, which could leak sensitive secrets and execution details.
Replace these zap.Any() calls with safe metadata alternatives that only log
bounded information such as the count of items, presence indicators, or type
information instead of the actual payload content. Apply the same fix to the
similar debug logging around lines 488-492 that also uses zap.Any() for payload
fields.
In `@internal/common/logger.go`:
- Around line 294-310: The code creates duplicate "error" fields in 5xx log
entries by appending zap.String("error", last.Error()) to fields at line 297,
and then passing ginErr to the Error() function call at line 310, which
internally appends another zap.Error(ginErr) field. To fix this following Option
1, move the zap.String("error", last.Error()) append to only apply for non-5xx
responses (like the existing 4xx and 2xx/3xx paths with Warn and Info calls), so
that 5xx responses only use the structured error field from the Error()
function's error parameter rather than the string field, eliminating the
duplicate "error" field in the output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0e51f7c7-bcf1-490a-9dd5-42ec38ed5f96
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (28)
cmd/admin_server.gocmd/ingestor.gocmd/ragflow_cli.gocmd/server_main.godocker/service_conf.yaml.templatego.modinternal/agent/canvas/compile.gointernal/agent/canvas/compile_test.gointernal/agent/canvas/runner.gointernal/agent/canvas/scheduler.gointernal/agent/canvas/stream.gointernal/agent/component/agent.gointernal/agent/component/llm.gointernal/agent/component/llm_credentials.gointernal/agent/component/message.gointernal/agent/component/universe_a_wrappers.gointernal/agent/sandbox/self_managed.gointernal/agent/tool/code_exec.gointernal/common/logger.gointernal/dao/database.gointernal/handler/system.gointernal/harness/core/interrupt.gointernal/harness/graph/checkpoint/nats.gointernal/harness/graph/pregel/engine.gointernal/router/router.gointernal/server/config.gointernal/service/agent.gointernal/tokenizer/tokenizer_concurrent_test.go
Address CodeRabbit review comments on PR infiniflow#16260. Security / privacy fixes: - internal/common/logger.go (GinLogger): drop the raw query string from the logged path. Query params frequently carry OAuth codes, SAML responses, signed state, and API keys in callback URLs; there is no generic redaction strategy. Replace with has_query (bool) and query_len (int) fields so operators can still see that a query string was present and how long it was, without ever seeing its contents. - internal/agent/component/llm_credentials.go: replace zap.String("api_key", apiKey) with zap.Bool("api_key_present", apiKey != "") in both the tenant_llm OK and new-table OK debug log sites. API keys must never appear in log files. - internal/agent/tool/code_exec.go: bound the script/arguments and stdout/stderr fields to lengths and presence flags. Scripts and shell output routinely contain credentials passed as environment variables or printed by the script itself; logging the full bodies exposes them to anyone with read access to logs/server_main.log. Bug / perf fix: - cmd/server_main.go: remove the duplicate common.GinLogger() registration. router.Setup already registers it (router.go:126); registering it again at server_main.go:330 caused every request to emit two access-log lines. Replaced with a comment explaining why the registration lives in Setup. Doc fix: - internal/handler/system.go: correct the SetLogLevel doc comment to reflect the actual binding — only the level field is enforced; pkg_name is accepted but ignored, so saying "pkg_name and level are required" was misleading. The "pkg_name and level are required" error message string is preserved verbatim so existing clients that match on it keep working; only the comment is fixed. Verified: bash build.sh --go (all 4 binaries built) bash build.sh --test (all packages pass; zero failures) Co-Authored-By: Claude <[email protected]>
57767d0 to
9c23a31
Compare
Address the 3 remaining unresolved CodeRabbit review comments on PR infiniflow#16261. Security / privacy fixes: - internal/agent/component/llm_credentials.go: replace zap.String("base_url", baseURL) with zap.Bool("base_url_present", baseURL != "") in both the tenant_llm OK and new-table OK debug log sites. base_url can carry embedded credentials when the model provider's endpoint embeds them in the URL (e.g. https://user:password@host/v1), and the same kind of credential leak we already guarded against for api_key applies here. - internal/agent/component/universe_a_wrappers.go: bound the CodeExec wrapper debug payloads to counts and presence flags. The wrapper Invoke() log at line 440 was dumping raw params / inputs / merged maps; applyCodeExecBusinessOutputs at line 488 was dumping decoded, resolved_raw_result, content, and outputs. Scripts and their arguments routinely carry env vars, secrets, and DB connection strings; structured debug logs should never serialize them. Bug fix: - internal/common/logger.go (GinLogger): the 5xx branch logged the same error twice — once as zap.String("error", last.Error()) appended to fields, and once as the structured zap.Error field emitted by common.Error() from its err arg. Two "error" fields in one record confuse downstream aggregation (Splunk / Loki / Elasticsearch dedupe keys can collapse the wrong one). Skip the string form when status >= 500; the structured zap.Error stays. 4xx / 2xx-3xx paths still emit the string field because Warn / Info do not accept an err arg. Verified: bash build.sh --go (all 4 binaries built) bash build.sh --test (all packages pass; zero failures) Co-Authored-By: Claude <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16261 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Refactor the Go agent port's logging so every log line — gin access, agent canvas events, harness warnings, fatal boot errors — flows through a single common.Logger (zap) backed by a rotated file, with structured fields, level filtering, and configurable rotation.