[ISSUE #10788] Tolerate invalid metric collector address - #10789
Conversation
There was a problem hiding this comment.
Pull request overview
Hardens Proxy gRPC client metric settings generation so an invalid optional metricCollectorAddress no longer breaks settings merge when metricCollectorMode=on, aligning behavior with Issue #10788.
Changes:
- Add validation/parsing for
metricCollectorAddressand disable client metric collection when the address is blank/malformed/invalid. - Log warnings when metric collection is disabled due to invalid address input.
- Add unit tests covering valid and invalid collector addresses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/common/GrpcClientSettingsManager.java | Adds safe parsing/validation for metric collector address and disables metrics on invalid input. |
| proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/common/GrpcClientSettingsManagerTest.java | Adds tests validating correct behavior for valid/invalid metric collector addresses. |
Suppressed comments (1)
proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/common/GrpcClientSettingsManagerTest.java:104
- The new parsing logic in GrpcClientSettingsManager handles multiple invalid forms (blank, missing host/port, non-numeric port, out-of-range port), but this test only covers the missing-port case. Expanding it to cover the other invalid branches will better prevent regressions for the hardening introduced in this PR (and also restore the previous config instead of forcing defaults).
ConfigurationManager.getProxyConfig().setMetricCollectorMode(MetricCollectorMode.ON.getModeString());
ConfigurationManager.getProxyConfig().setMetricCollectorAddress("localhost");
try {
Settings settings = this.grpcClientSettingsManager.mergeMetric(Settings.getDefaultInstance());
assertEquals(false, settings.getMetric().getOn());
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Test | ||
| public void testMergeMetricWithValidCollectorAddress() { | ||
| ConfigurationManager.getProxyConfig().setMetricCollectorMode(MetricCollectorMode.ON.getModeString()); | ||
| ConfigurationManager.getProxyConfig().setMetricCollectorAddress("127.0.0.1:9090"); | ||
| try { | ||
| Settings settings = this.grpcClientSettingsManager.mergeMetric(Settings.getDefaultInstance()); | ||
|
|
||
| assertEquals(true, settings.getMetric().getOn()); | ||
| assertEquals("127.0.0.1", settings.getMetric().getEndpoints().getAddresses(0).getHost()); | ||
| assertEquals(9090, settings.getMetric().getEndpoints().getAddresses(0).getPort()); | ||
| } finally { | ||
| ConfigurationManager.getProxyConfig().setMetricCollectorMode(MetricCollectorMode.OFF.getModeString()); | ||
| ConfigurationManager.getProxyConfig().setMetricCollectorAddress(""); | ||
| } | ||
| } |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Extracts metric collector address parsing into a dedicated method with comprehensive validation (blank check, format check, port range check), gracefully disabling metric collection on invalid input instead of throwing.
Findings
- [Info]
GrpcClientSettingsManager.java:155—split(":", -1)correctly handles trailing colons (e.g."host:"→["host", ""]), which is good defensive practice. - [Info]
GrpcClientSettingsManager.java:163— Port range validation (1–65535) is correct and prevents invalid endpoint construction. - [Info] Tests cover both valid and invalid address scenarios, which is good.
Suggestions
- Minor: consider logging the original config value at
DEBUGlevel rather thanWARNfor the blank case, since a blank default is a common initial state. Not blocking.
LGTM — clean defensive improvement with good test coverage.
Automated review by github-manager-bot
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10789 +/- ##
=============================================
- Coverage 48.60% 48.51% -0.10%
+ Complexity 13690 13659 -31
=============================================
Files 1381 1381
Lines 101464 101483 +19
Branches 13187 13191 +4
=============================================
- Hits 49318 49233 -85
- Misses 46158 46236 +78
- Partials 5988 6014 +26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
LGTM. Code changes look good.
Automated review by github-manager-bot
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Defensive fix with proper validation and test coverage. LGTM.
Automated review by github-manager-bot
f7dddf8 to
d62d31c
Compare
|
Rebased onto current |
What is changed
metricCollectorAddressbefore building gRPC client metric settings inmetricCollectorMode=on.Fixes #10788
Closes #10683
Verification