Skip to content

lib/logrusr: consolidate logrus utilities#13034

Open
Brian-McM wants to merge 1 commit into
projectcalico:masterfrom
Brian-McM:bm-consolidate-logrus-utils
Open

lib/logrusr: consolidate logrus utilities#13034
Brian-McM wants to merge 1 commit into
projectcalico:masterfrom
Brian-McM:bm-consolidate-logrus-utils

Conversation

@Brian-McM

Copy link
Copy Markdown
Contributor

Summary

Move all generic logrus utility code out of libcalico-go/lib/logutils and into lib/logrusr (the adapter module added in #12968). Component-specific orchestration (felix/logutils, typha/pkg/logutils, confd/pkg/log) stays where it lives — only the primitives consolidate.

Moved to lib/logrusr:

  • Formatter / ConfigureFormatter and the Calico log line shape (timestamp, level, PID, component/file:line, message, sorted KVs).
  • Background-dispatch destinations (NewStreamDestination, NewSyslogDestination) with optional log dropping and Prometheus counters.
  • BackgroundHook and WithDebugFileRegexp.
  • RateLimitedLogger, NewRateLimitedLogger, OptInterval, OptBurst, OptLogger.
  • SafeParseLogLevel, IsSensitiveParam, RedactURL.
  • testing.TB hookup helpers (RedirectLogrusToTestingT/TB, ConfigureLoggingForTestingT/TB).

The old logformat sub-package collapses into lib/logrusr — its only external caller (hack/cmd/coalesce-imports) is updated.

Caller updates: 70+ files across apiserver, app-policy, calicoctl, cni-plugin, confd, felix, goldmane, guardian, hack, kube-controllers, libcalico-go, node, pod2daemon, release, test-tools, typha, webhooks, and whisker-backend.

libcalico-go/lib/logutils is deleted. cmd/deps.txt and per-component deps.txt files are regenerated.

Test plan

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 19, 2026 17:54
@Brian-McM Brian-McM requested review from a team as code owners June 19, 2026 17:54
@marvin-tigera marvin-tigera added this to the Calico v3.33.0 milestone Jun 19, 2026
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Jun 19, 2026
@Brian-McM Brian-McM force-pushed the bm-consolidate-logrus-utils branch from 7197a09 to 9006c9d Compare June 19, 2026 17:56
@Brian-McM Brian-McM added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact and removed release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Jun 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 consolidates generic Logrus utilities by moving them from libcalico-go/lib/logutils into the standalone adapter module lib/logrusr, while leaving component-specific logging orchestration in place (e.g., felix/logutils, typha/pkg/logutils, confd/pkg/log). It updates a wide set of callers and regenerates local dependency manifests accordingly.

Changes:

  • Migrate formatter/background destinations/hooks, rate-limited logger, redaction/sensitive helpers, and testing redirection helpers into lib/logrusr.
  • Update call sites across many components to import and use github.com/projectcalico/calico/lib/logrusr instead of libcalico-go/lib/logutils (and remove the old logformat subpackage usage).
  • Regenerate deps.txt files to reflect the new local module dependencies (lib/logrusr, lib/std/log).

Reviewed changes

Copilot reviewed 93 out of 94 changed files in this pull request and generated no comments.

Show a summary per file
File Description
whisker-backend/pkg/config/api.go Switch logging formatter configuration import to lib/logrusr.
webhooks/pkg/webhook/command.go Switch logging formatter configuration import to lib/logrusr.
typha/pkg/syncproto/sync_proto.go Use logrusr.NewRateLimitedLogger() for rate-limited logging.
typha/pkg/logutils/logutils.go Update Typha logging orchestration to use logrusr primitives.
typha/pkg/logutils/logutils_other.go Update non-Linux stubs to use logrusr types.
typha/pkg/logutils/logutils_linux.go Update Linux destinations to use logrusr constructors/types.
typha/pkg/config/env_var_loader.go Use logrusr.IsSensitiveParam for env var redaction.
typha/fv-tests/reconnection_test.go Redirect Logrus output using logrusr testing helper.
typha/deps.txt Regenerated to depend on local:lib/logrusr and local:lib/std/log.
test-tools/mocknode/cmd/mocknode/main.go Switch to logrusr (formatter, null writer, background hook, flush field).
test-tools/deps.txt Regenerated to depend on local:lib/logrusr and local:lib/std/log.
release/deps.txt Regenerated to depend on local:lib/logrusr and local:lib/std/log.
release/cmd/main.go Switch logging formatter configuration import to lib/logrusr.
pod2daemon/pkg/csi/run.go Switch logging formatter configuration import to lib/logrusr.
node/pkg/node/command.go Switch per-command formatter setup to logrusr.Formatter / ConfigureFormatter.
node/deps.txt Regenerated to depend on local:lib/logrusr and local:lib/std/log.
libcalico-go/lib/testutils/ginkgolog.go Update Ginkgo Logrus hookup to call logrusr.ConfigureFormatter.
libcalico-go/lib/backend/syncersv1/dedupebuffer/dedupe_buffer_test.go Update test logging formatter setup to logrusr.
lib/logrusr/suite_test.go Rename suite/package and inline Logrus-to-Ginkgo wiring without libcalico-go testutils dependency.
lib/logrusr/sensitive.go Package rename to logrusr for sensitive/redaction helpers.
lib/logrusr/ratelimited.go Package rename to logrusr for rate-limited logger implementation.
lib/logrusr/ratelimited_test.go Update tests to logrusr package naming/imports.
lib/logrusr/go.sum Updated module sums after consolidation and test deps.
lib/logrusr/go.mod Add required deps (incl. Prometheus and Ginkgo/Gomega for tests).
lib/logrusr/formatter.go Collapse former logformat code into logrusr package.
lib/logrusr/destination.go Collapse former destination/background hook code into logrusr package and use local formatter helpers.
lib/logrusr/destination_test.go Update tests to new package and file name expectations.
lib/logrusr/benchmarks_test.go Update benchmark package name to logrusr.
lib/logrusr/another_file_for_test.go Update test package name to logrusr_test.
kube-controllers/pkg/kubecontrollers/run.go Switch logging formatter configuration import to lib/logrusr.
kube-controllers/pkg/controllers/tier/tier_controller_fv_test.go Switch formatter type usage to logrusr.Formatter.
kube-controllers/pkg/controllers/serviceaccount/serviceaccount_controller_fv_test.go Switch formatter type usage to logrusr.Formatter.
kube-controllers/pkg/controllers/namespace/namespace_controller_fv_test.go Switch formatter type usage to logrusr.Formatter.
kube-controllers/pkg/controllers/migration/controller_fv_test.go Switch formatter type usage to logrusr.Formatter.
kube-controllers/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
hack/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
hack/cmd/deps/deps.go Switch logging formatter configuration import to lib/logrusr.
hack/cmd/coalesce-imports/coalesce-imports.go Replace logformat.ConfigureFormatter usage with logrusr.ConfigureFormatter.
guardian/tests/fv/fv_test.go Switch formatter + testing redirection to logrusr.
guardian/pkg/tunnel/suite_test.go Switch formatter + testing redirection to logrusr.
guardian/pkg/conn/forward_test.go Switch formatter + testing redirection to logrusr.
guardian/pkg/config/config.go Switch logging formatter configuration import to lib/logrusr.
guardian/cmd/guardian/command.go Use logrusr.RedactURL for logging sanitized config.
goldmane/pkg/stream/stream.go Switch RateLimitedLogger type to logrusr.
goldmane/pkg/stream/stream_manager.go Switch rate-limited logger construction to logrusr opts.
goldmane/pkg/storage/index_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/pkg/storage/diachronic_flow_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/pkg/internal/utils/logging.go Switch logging formatter configuration import to lib/logrusr.
goldmane/pkg/internal/utils/files_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/pkg/goldmane/goldmane.go Switch RateLimitedLogger type to logrusr.
goldmane/pkg/goldmane/goldmane_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/pkg/emitter/emitter.go Use logrusr.RedactURL for sanitized URL logging.
goldmane/pkg/emitter/emitter_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/pkg/daemon/daemon.go Use logrusr.RedactURL for sanitized config logging.
goldmane/fv/flow_collector_test.go Switch Logrus-to-testing redirection to logrusr.
goldmane/fv/daemon_test.go Switch formatter + Logrus-to-testing redirection to logrusr.
goldmane/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
felix/wireguard/wireguard.go Switch rate-limited logger to logrusr.
felix/vxlanfdb/vxlan_fdb_test.go Switch formatter/testing logging helpers to logrusr.
felix/nftables/table.go Switch imported rate-limited logger types/opts alias to lib/logrusr.
felix/nfnetlink/nflog_linux.go Switch rate-limited logger to logrusr.
felix/logutils/logutils.go Update Felix logging orchestration to use logrusr primitives.
felix/logutils/logutils_windows.go Update Windows destinations to use logrusr constructors/types.
felix/logutils/logutils_linux.go Update Linux destinations to use logrusr constructors/types.
felix/linkaddrs/link_addrs_test.go Switch formatter/testing logging helpers to logrusr.
felix/labelindex/named_port_index_test.go Switch testing logging helper to logrusr.
felix/iptables/table.go Switch imported rate-limited logger types/opts alias to lib/logrusr.
felix/fv/test-workload/test-workload.go Switch logging formatter configuration import to lib/logrusr.
felix/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
felix/dataplane/linux/int_dataplane.go Switch flush field constant reference to logrusr.FieldForceFlush.
felix/dataplane/linux/bpf_ep_mgr.go Switch imported rate-limited logger types/opts alias to lib/logrusr.
felix/dataplane/external/ext_dataplane_test.go Switch testing logging helpers to logrusr.
felix/daemon/daemon.go Switch flush field constant reference to logrusr.FieldForceFlush.
felix/config/env_var_loader.go Use logrusr.IsSensitiveParam for env var redaction.
felix/collector/types/tuple/tuple_suite_test.go Switch formatter configuration import to lib/logrusr.
felix/collector/types/counter/counter_suite_test.go Switch formatter configuration import to lib/logrusr.
felix/collector/flowlog/types.go Switch rate-limited logger to logrusr.
felix/collector/flowlog/flowlogs_suite_test.go Switch formatter configuration import to lib/logrusr.
felix/cmd/calico-felix-docgen/calico-felix-docgen.go Switch logging formatter configuration import to lib/logrusr.
confd/pkg/log/log.go Switch logging formatter configuration import to lib/logrusr.
confd/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
cni-plugin/pkg/plugin/plugin.go Switch logging formatter configuration import to lib/logrusr.
cni-plugin/pkg/ipamplugin/ipam_plugin.go Switch logging formatter configuration import to lib/logrusr.
cni-plugin/pkg/install/install.go Switch logging formatter configuration import to lib/logrusr.
cni-plugin/deps.txt Regenerated to include local:lib/logrusr and local:lib/std/log.
cmd/deps.txt Regenerated to remove old libcalico-go/lib/logutils references.
calicoctl/tests/fv/namespace_option_test.go Switch formatter configuration import to lib/logrusr.
calicoctl/tests/fv/multi_context_test.go Switch formatter configuration import to lib/logrusr.
calicoctl/tests/fv/migrate_ipam_test.go Switch formatter configuration import to lib/logrusr.
calicoctl/tests/fv/ipam_test.go Switch formatter configuration import to lib/logrusr.
calicoctl/calicoctl/commands/cluster/diags_test.go Switch formatter configuration import to lib/logrusr.
app-policy/checker/check.go Switch rate-limited logger to logrusr.
apiserver/cmd/apiserver/server/logging.go Switch to logrusr.SafeParseLogLevel.
Comments suppressed due to low confidence (1)

lib/logrusr/formatter.go:19

  • The package-level doc comment still refers to logformat and to a parent logutils package, but the package is now logrusr. This can confuse GoDoc readers (and some linters expect the comment to start with the actual package name).

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

CI triage — Calico

Recommendation: Dig deeper before merging

Likely caused by this PR

Test Why
Felix: Build / Felix: Static checks no DIAGS; Felix static checks failed. PR moves logutils into lib/logrusr and updates Felix callers — plausibly related; rerun or manual check.

workflow_id: 7e4a4171-2ebe-4b8a-b85f-3f220deb1dc0

@Brian-McM Brian-McM force-pushed the bm-consolidate-logrus-utils branch from 9006c9d to d138b0e Compare June 19, 2026 18:16
Move the logrus-specific utility code that used to live in
libcalico-go/lib/logutils into lib/logrusr. The migrated APIs include:

- Formatter / ConfigureFormatter and the legacy Calico log line shape.
- Background-dispatch destinations (stream, syslog) with optional log
  dropping and Prometheus counters.
- RateLimitedLogger and its options.
- BackgroundHook with optional debug-file regexp filtering.
- SafeParseLogLevel, IsSensitiveParam, RedactURL.
- testing.TB hookup helpers (RedirectLogrusToTestingT/TB,
  ConfigureLoggingForTestingT/TB).
- Summarizer / OpRecorder (moved from felix/logutils — generic
  logrus-shaped utility used by Felix dataplane managers).

The old logformat sub-package collapses into lib/logrusr; the only
external caller (hack/cmd/coalesce-imports) is updated to use
logrusr directly.

Delete the component-specific logutils packages now that the generic
primitives live in lib/logrusr:

- felix/logutils → felix/logging. Same Felix-specific Configure /
  Tracef / Dump / RegisterProfilingSignalHandlers helpers, just under
  a name that reflects what's left after the generic bits moved out.
- typha/pkg/logutils → typha/pkg/logging.
- confd/pkg/log → deleted. SetLevel inlines into confd/pkg/config (the
  only caller location); ConfigureFormatter("confd") moves to
  confd.go's main.

All 70+ callers across apiserver, app-policy, calicoctl, cni-plugin,
confd, felix, goldmane, guardian, hack, kube-controllers, libcalico-go,
node, pod2daemon, release, test-tools, typha, webhooks, and
whisker-backend are updated. libcalico-go/lib/logutils is deleted.
cmd/deps.txt and .semaphore/semaphore.yml are regenerated.
@Brian-McM Brian-McM force-pushed the bm-consolidate-logrus-utils branch from d138b0e to fbb595a Compare June 19, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants