iloveeyjafjalla opened a new pull request, #11390:
URL: https://github.com/apache/rocketmq/pull/11390
### Which Issue(s) This PR Fixes
- Fixes #11389
### Brief Description
`ConsumerLagCalculator#getConsumerLagStats(group, topic, isPop)` uses
`Long.MAX_VALUE` as the "no timestamp" sentinel and
normalizes it at the end of the regular path, but the early return for a
missing topic returned the sentinel as is:
```java
if (group == null || topic == null) {
return new Pair<>(total, earliestUnconsumedTimestamp); // still
Long.MAX_VALUE
}
```
Since `CalculateLagResult#getLagLatency()` computes
`System.currentTimeMillis() - earliestUnconsumedTimestamp`, the recorded
value became `now - Long.MAX_VALUE ≈ -9.223372035e18` ms for
`rocketmq_consumer_lag_latency` — and the same early return in
`getInFlightMsgStats` feeds `rocketmq_consumer_queueing_latency`. This is
reachable with the default configuration: for a POP
group, `calculate()` queries the retry series with `info.retryTopic`, which
`processAllGroup` passes as `null` when the retry
topic config does not exist yet (the broker creates `%RETRY%<group>` lazily
on the first nack).
The change normalizes the sentinel to `0` in both early returns, so an
unknown topic reports no lag and no latency exactly
like the regular path does.
### How Did You Test This Change?
New test `ConsumerLagCalculatorTest#testUnknownTopicHasNoLagAndNoLatency`
(broker module): it constructs the calculator and
asserts that `getConsumerLagStats("group", null, true)` and
`getInFlightMsgStats("group", null, true)` return
`(0, 0)`, and that a `CalculateLagResult` built from that timestamp yields
`getLagLatency() == 0`.
Results on Temurin JDK 8 (same JDK as CI), base `a7edeecfb` plus this patch:
- before the fix: `java.lang.AssertionError: expected:<0> but
was:<9223372036854775807>`
- after the fix: `ConsumerLagCalculatorTest` 1 test and
`LiteConsumerLagCalculatorTest` 9 tests — 0 failures
- `mvn -B -ntp -pl broker package` with checkstyle + spotbugs enabled:
`BUILD SUCCESS`, spotbugs `BugInstance size is 0`
- Note for the reviewer:
`BrokerMetricsManagerTest#testCreateMetricsManagerLogType` fails in this
working copy with
`NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;`
**both with and without this patch** (verified by
stashing the change), i.e. it is a local classpath artifact (a locally
installed dependency built with a newer JDK), not a
regression of this change.
This change was prepared with AI assistance (analysis, patch and test
drafting); the diff and every result above were
reproduced locally by running the module's tests against the base commit and
the patched tree.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]