-
Notifications
You must be signed in to change notification settings - Fork 210
feat: add warning handler #1856
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: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1856 +/- ##
==========================================
+ Coverage 85.32% 85.36% +0.03%
==========================================
Files 143 144 +1
Lines 6739 6730 -9
==========================================
- Hits 5750 5745 -5
+ Misses 703 700 -3
+ Partials 286 285 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
848995a to
1ee4072
Compare
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 introduces a centralized warning handler to manage registry warnings and reduces code duplication. The change extracts warning handling logic from the Remote struct into a dedicated WarningHandler component with proper concurrency handling.
- Adds a new
WarningHandlertype with thread-safe warning deduplication - Removes warning handling code from the
Remotestruct to reduce bloat - Provides comprehensive test coverage for the new warning handler functionality
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/oras/internal/option/warning_handler.go | New warning handler implementation with sync.Map for thread-safe deduplication |
| cmd/oras/internal/option/warning_handler_test.go | Comprehensive test suite covering deduplication, concurrency, and multi-registry scenarios |
| cmd/oras/internal/option/remote.go | Removes old warning handling code and integrates new WarningHandler |
| cmd/oras/internal/option/binary_target.go | Removes manual warning map initialization that's no longer needed |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Terry Howe <[email protected]>
1ee4072 to
3395408
Compare
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
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| oneHandler = warningHandler{} | ||
| var buf bytes.Buffer | ||
| logger := logrus.New() | ||
| logger.SetOutput(&buf) | ||
| logger.SetLevel(logrus.WarnLevel) | ||
|
|
||
| handler := GetHandler(tt.registry, logger) |
Copilot
AI
Oct 20, 2025
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.
Resetting the global singleton in tests can cause issues with test isolation and parallel test execution. Consider refactoring the warning handler to accept an instance parameter or use dependency injection instead of relying on a global singleton.
| oneHandler = warningHandler{} | |
| var buf bytes.Buffer | |
| logger := logrus.New() | |
| logger.SetOutput(&buf) | |
| logger.SetLevel(logrus.WarnLevel) | |
| handler := GetHandler(tt.registry, logger) | |
| var buf bytes.Buffer | |
| logger := logrus.New() | |
| logger.SetOutput(&buf) | |
| logger.SetLevel(logrus.WarnLevel) | |
| // Use a local handler instance to avoid global state | |
| localHandler := warningHandler{} | |
| handler := localHandler.getHandler(tt.registry, logger) |
| func TestWarningHandler_GetHandler_DifferentRegistries(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| logger := logrus.New() | ||
| logger.SetOutput(&buf) | ||
| logger.SetLevel(logrus.WarnLevel) | ||
|
|
||
| handler1 := GetHandler("registry1.example.com", logger) | ||
| handler2 := GetHandler("registry2.example.com", logger) |
Copilot
AI
Oct 20, 2025
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.
This test doesn't reset the global singleton state, which could cause interference with other tests. The oneHandler should be reset at the beginning of each test that depends on its state.
| type warningHandler struct { | ||
| warned sync.Map | ||
| } |
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.
I found the name warningHandler and warned a bit hard to understand... I don't have a good suggestion though. Is it more like a warner pool or something?
What this PR does / why we need it:
Add a warning handler and some tests for it. Gets a little bloat out of options/remote.go