Skip to content

refactor: use remote.NewWarningLogger for registry warnings - #2317

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
orshih6:contribot/issue-2314
Nov 5, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
orshih6:contribot/issue-2314

Conversation

@orshih6

@orshih6 orshih6 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

option.Remote had its own handleWarning that logged registry Warning headers and de-duplicated them per registry. oras-go v3 now provides remote.NewWarningLogger, which does the same thing, but it takes a *slog.Logger and the CLI logs through logrus.

Changes:

  • New internal/logutil package with a slog.Handler that forwards records to a logrus.FieldLogger, and a NewSlogLogger helper. It maps slog levels to logrus levels (Enabled respects the level of a *logrus.Logger/*logrus.Entry). Record attributes and WithAttrs become logrus fields; groups become key prefixes (group.key).
  • handleWarning is replaced by warningHandler, which returns remote.NewWarningLogger(registry, logutil.NewSlogLogger(logger)). All four call sites use it: NewRegistry, NewRepository and the two containers-config paths.
  • NewWarningLogger only de-duplicates within the function it returns. So the returned function is cached per registry on Remote, replacing the old map[string]*sync.Map. This keeps the current behaviour: each distinct warning is logged once per registry, even when several clients are created. BinaryTarget still shares that map between From and To.

One small difference: the cached handler keeps the logger passed for the first client created for a registry. Before, each call wrapped the logger it was given. In practice every call passes the same command logger.

Testing:

  • internal/logutil tests use the logrus test hook to check level mapping, Enabled, fields from attrs/With/groups, and the registry attribute.
  • TestRemote_warningHandler creates a repository and a registry client for the same registry, plus one for a different registry. It checks that each distinct warning is logged once per registry at warn level with the right registry field, and that the two registries are logged separately.
  • TestRemote_containersConfigWarningDedup covers the containers-config path: a rewritten alias shares dedup with a direct client for the target registry.
  • I checked that the tests fail if the per-registry cache is bypassed.
  • go vet and go test pass for ./internal/logutil/ and ./cmd/oras/internal/option/.

🤖 Generated with Claude Code

Fixes #2314


This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.54930% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.51%. Comparing base (4fdee3b) to head (8277060).

Files with missing lines Patch % Lines
internal/logutil/slog.go 89.83% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2317      +/-   ##
==========================================
+ Coverage   73.33%   73.51%   +0.18%     
==========================================
  Files         156      157       +1     
  Lines        6526     6582      +56     
==========================================
+ Hits         4786     4839      +53     
- Misses       1452     1454       +2     
- Partials      288      289       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe
TerryHowe merged commit f5dbbde into oras-project:main Nov 5, 2026
10 checks passed
@TerryHowe TerryHowe mentioned this pull request Nov 17, 2026
4 tasks done
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.

cleanup: replace custom handleWarning() with remote.NewWarningLogger()

2 participants