Skip to content

[ISSUE #9677] Resolve metrics static variable conflicts in BrokerContainer mode#9678

Merged
ltamber merged 5 commits intoapache:developfrom
RongtongJin:develop-0909
Sep 11, 2025
Merged

[ISSUE #9677] Resolve metrics static variable conflicts in BrokerContainer mode#9678
ltamber merged 5 commits intoapache:developfrom
RongtongJin:develop-0909

Conversation

@RongtongJin
Copy link
Copy Markdown
Contributor

@RongtongJin RongtongJin commented Sep 9, 2025

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

  • ✅ Convert all static metrics variables to private instance variables
  • ✅ Add getter methods for external access to metrics
  • ✅ Convert newAttributesBuilder() from static to instance method
  • ✅ Add setAttributesBuilderSupplier() for testing support
  • ✅ Maintain backward compatibility for all existing functionality

2. TimerMessageStore Compilation Fixes

  • ✅ Replace static method calls with instance method calls
  • ✅ Add instanceof DefaultMessageStore type safety checks
  • ✅ Use proper metrics manager instance access pattern
  • ✅ Follow the same refactoring pattern as BrokerMetricsManager

How Did You Test This Change?

…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-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 61.04651% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.07%. Comparing base (40622ce) to head (081bda0).
⚠️ Report is 175 commits behind head on develop.

Files with missing lines Patch % Lines
...etmq/store/metrics/DefaultStoreMetricsManager.java 28.78% 46 Missing and 1 partial ⚠️
.../rocketmq/broker/metrics/BrokerMetricsManager.java 93.61% 3 Missing ⚠️
...he/rocketmq/broker/processor/PopReviveService.java 0.00% 3 Missing ⚠️
.../transaction/queue/TransactionalMessageBridge.java 0.00% 3 Missing ⚠️
...broker/processor/AbstractSendMessageProcessor.java 0.00% 2 Missing ⚠️
...ocketmq/broker/processor/AdminBrokerProcessor.java 75.00% 2 Missing ⚠️
...ocketmq/broker/processor/SendMessageProcessor.java 66.66% 2 Missing ⚠️
...org/apache/rocketmq/store/DefaultMessageStore.java 50.00% 2 Missing ⚠️
...apache/rocketmq/store/timer/TimerMessageStore.java 75.00% 0 Missing and 2 partials ⚠️
...he/rocketmq/proxy/metrics/ProxyMetricsManager.java 0.00% 1 Missing ⚠️
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.
📢 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.

Copy link
Copy Markdown
Contributor

@fuyou001 fuyou001 left a comment

Choose a reason for hiding this comment

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

LGTM

@ltamber ltamber merged commit 7967edf into apache:develop Sep 11, 2025
11 checks passed
@RongtongJin RongtongJin added the ha label Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Metrics static variables cause conflicts and resource leaks in BrokerContainer mode

4 participants