[ISSUE #9677] Resolve metrics static variable conflicts in BrokerContainer mode#9678
Merged
ltamber merged 5 commits intoapache:developfrom Sep 11, 2025
Merged
[ISSUE #9677] Resolve metrics static variable conflicts in BrokerContainer mode#9678ltamber merged 5 commits intoapache:developfrom
ltamber merged 5 commits intoapache:developfrom
Conversation
…factoring - Excluded DefaultMappedFile, METRICS_REFACTORING_GUIDE.md, TimerMetrics, and RocksDB files per requirements - Successfully applied changes to most broker and store modules - Compilation errors in TimerMessageStore.java will be fixed in next commit
Convert static metrics variables to instance-level to fix resource leaks and data conflicts in BrokerContainer scenarios with multiple broker instances. ## Problem Statement In BrokerContainer mode, multiple broker instances share static metrics variables from BrokerMetricsManager and DefaultStoreMetricsManager, causing: - Metrics data conflicts between different broker instances - Resource leaks during frequent addBroker/removeBroker operations - Incorrect metrics aggregation across multiple brokers ## Solution - Convert static metrics variables to instance-level variables - Add proper getter methods for external access - Ensure each broker instance maintains isolated metrics - Apply instanceof checks for type safety in TimerMessageStore ## Files Modified - broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java - store/src/main/java/org/apache/rocketmq/store/timer/TimerMessageStore.java - METRICS_REFACTORING_GUIDE.md (documentation) ## Key Benefits ✅ Eliminates metrics conflicts between broker instances ✅ Prevents resource leaks in dynamic broker scenarios ✅ Maintains proper metrics isolation per broker ✅ Supports BrokerContainer mode with multiple brokers ✅ Backward compatible with existing functionality Resolves metrics static variable issues in multi-broker container environments.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #9678 +/- ##
=============================================
- Coverage 48.14% 48.07% -0.08%
- Complexity 12081 12097 +16
=============================================
Files 1313 1313
Lines 92837 92970 +133
Branches 11864 11873 +9
=============================================
- Hits 44695 44693 -2
- Misses 42642 42760 +118
- Partials 5500 5517 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ltamber
approved these changes
Sep 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Fixes #9677
This PR resolves critical metrics conflicts and resource leaks in BrokerContainer mode by converting static metrics variables to instance-level variables, ensuring proper isolation between multiple broker instances.
Brief Description
1. BrokerMetricsManager Refactoring
newAttributesBuilder()from static to instance methodsetAttributesBuilderSupplier()for testing support2. TimerMessageStore Compilation Fixes
instanceof DefaultMessageStoretype safety checksHow Did You Test This Change?