gnodet commented on code in PR #24502:
URL: https://github.com/apache/camel/pull/24502#discussion_r3539254207
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTab.java:
##########
@@ -504,11 +504,16 @@ public void render(Frame frame, Rect area) {
for (long v : mergedTotal) {
rawMax = Math.max(rawMax, v);
}
- long maxTp = roundUpNice(rawMax);
+ long maxTp = MetricsCollector.niceMax(rawMax);
long curTp = mergedTotal[renderPoints - 1];
long curFailed = mergedFailed[renderPoints - 1];
long curOk = Math.max(0, curTp - curFailed);
+ // Format throughput values unscaled for display
+ String curTpFmt = MetricsCollector.formatThroughput(curTp);
+ String curOkFmt = MetricsCollector.formatThroughput(curOk);
+ String curFailFmt = MetricsCollector.formatThroughput(curFailed);
Review Comment:
Good catch — `curFailed` can exceed `curTp` because throughput total comes
from EWMA while failed is still delta-based. Fixed: `curFailed` is now clamped
to `curTp` before formatting so the title matches the chart bars.
```java
long curFailed = Math.min(mergedFailed[renderPoints - 1], curTp);
```
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTab.java:
##########
@@ -504,11 +504,16 @@ public void render(Frame frame, Rect area) {
for (long v : mergedTotal) {
rawMax = Math.max(rawMax, v);
}
- long maxTp = roundUpNice(rawMax);
+ long maxTp = MetricsCollector.niceMax(rawMax);
Review Comment:
Agreed — `roundUpNice()` is dead code now that we switched to
`MetricsCollector.niceMax()`. Deleted.
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MetricsCollector.java:
##########
@@ -262,8 +275,8 @@ private void recordEndpointSample(
long[] oldest = samples.get(0);
long[] newest = samples.get(samples.size() - 1);
long deltaMs = newest[0] - oldest[0];
- long inRate = deltaMs > 0 ? (newest[1] - oldest[1]) * 1000 /
deltaMs : 0;
- long outRate = deltaMs > 0 ? (newest[2] - oldest[2]) * 1000 /
deltaMs : 0;
+ long inRate = deltaMs > 0 ? (newest[1] - oldest[1]) * 1000 *
THROUGHPUT_SCALE / deltaMs : 0;
+ long outRate = deltaMs > 0 ? (newest[2] - oldest[2]) * 1000 *
THROUGHPUT_SCALE / deltaMs : 0;
Review Comment:
Good find. Fixed by adding a `scale` parameter to `recordEndpointSample()`.
Endpoint callers pass `THROUGHPUT_SCALE` (100×) to preserve sub-1.0 rates,
while `updateCbHistory()` passes `1` so circuit breaker history stays unscaled
and the existing `"ok:%-4d"` / `"fail:%-4d msg/s"` integer formatting in
`CircuitBreakerTab` remains correct.
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MetricsCollector.java:
##########
@@ -403,4 +416,44 @@ private void removeByPrefix(String prefix, Map<String,
?>... maps) {
map.keySet().removeIf(k -> k.startsWith(prefix));
}
}
+
+ // --- Shared throughput formatting utilities ---
+
+ /**
+ * Round a scaled throughput value up to a nice chart-axis maximum.
Returns values that are multiples of 1, 2, or 5
+ * at the appropriate magnitude, ensuring the Y-axis labels are
human-readable.
+ */
+ static long niceMax(long rawMax) {
+ if (rawMax <= 0) {
+ return THROUGHPUT_SCALE;
+ }
+ int[] steps = { 1, 2, 5 };
+ long multiplier = THROUGHPUT_SCALE;
+ while (true) {
+ for (int s : steps) {
+ long candidate = s * multiplier;
+ if (candidate >= rawMax) {
+ return candidate;
+ }
+ }
+ multiplier *= 10;
+ }
+ }
Review Comment:
Good catch. Added overflow detection: the loop now checks `multiplier > 0`
and verifies `next / 10 == multiplier` before advancing. Also checks for
negative `candidate` from `s * multiplier` overflow. Falls back to returning
`rawMax` in all overflow cases. Added two unit tests exercising
`Long.MAX_VALUE` and `Long.MAX_VALUE / 2`.
--
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]