davsclaus commented on code in PR #24356:
URL: https://github.com/apache/camel/pull/24356#discussion_r3505351269


##########
core/camel-management/src/main/java/org/apache/camel/management/mbean/LoadThroughput.java:
##########
@@ -40,14 +47,10 @@ public void update(long currentReading) {
             long time = watch.takenAndRestart();
             if (time > 0) {
                 long delta = currentReading - last;
-                if (delta > 0) {
-                    // need to calculate with fractions
-                    thp = (1000d / time) * delta;
-                } else {
-                    thp = 0;
-                }
-            } else {
-                thp = 0;
+                // instantaneous rate in exchanges/second for this interval
+                double instantRate = (1000d / time) * delta;

Review Comment:
   Done — added `Math.max(0, ...)` clamping on the instantaneous rate. Also 
added `watch.stop()` in `reset()` so the next `update()` re-enters the 
initialization branch cleanly, avoiding post-reset spikes.



##########
core/camel-management/src/test/java/org/apache/camel/management/LoadThroughputTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import org.apache.camel.management.mbean.LoadThroughput;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisabledOnOs(OS.AIX)
+public class LoadThroughputTest {
+
+    @Test
+    public void testInitialValueIsZero() {
+        LoadThroughput t = new LoadThroughput();
+        assertEquals(0.0, t.getThroughput());
+    }
+
+    @Test
+    public void testConvergesToSteadyRate() throws Exception {
+        LoadThroughput t = new LoadThroughput();
+
+        // simulate 1 exchange per second for 120 seconds (well past 1-minute 
EWMA window)
+        long total = 0;
+        t.update(total);
+        Thread.sleep(10);
+        for (int i = 0; i < 120; i++) {
+            total++;

Review Comment:
   Done — rewrote all tests using Awaitility's `pollInterval` + `untilAsserted` 
pattern. Since `LoadThroughput` relies on real elapsed time via `StopWatch`, 
the Awaitility polling drives the updates at 10ms intervals while the 
assertions verify convergence.



##########
core/camel-management/src/test/java/org/apache/camel/management/LoadThroughputTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import org.apache.camel.management.mbean.LoadThroughput;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisabledOnOs(OS.AIX)
+public class LoadThroughputTest {
+
+    @Test
+    public void testInitialValueIsZero() {
+        LoadThroughput t = new LoadThroughput();
+        assertEquals(0.0, t.getThroughput());
+    }
+
+    @Test
+    public void testConvergesToSteadyRate() throws Exception {
+        LoadThroughput t = new LoadThroughput();
+
+        // simulate 1 exchange per second for 120 seconds (well past 1-minute 
EWMA window)
+        long total = 0;
+        t.update(total);
+        Thread.sleep(10);
+        for (int i = 0; i < 120; i++) {
+            total++;
+            Thread.sleep(10);
+            t.update(total);
+        }
+
+        // should converge close to the steady rate
+        assertTrue(t.getThroughput() > 0, "Throughput should be positive for 
steady input");
+    }
+
+    @Test
+    public void testSmoothing() throws Exception {
+        LoadThroughput t = new LoadThroughput();
+

Review Comment:
   Done — tightened the convergence assertion to check throughput > 5.0 
(verifying actual EWMA convergence toward the steady-state rate rather than 
just > 0). The smoothing test now also checks the value is bounded within a 
reasonable range.



##########
core/camel-management/src/test/java/org/apache/camel/management/LoadThroughputTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import org.apache.camel.management.mbean.LoadThroughput;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisabledOnOs(OS.AIX)
+public class LoadThroughputTest {

Review Comment:
   Good catch — removed. This is a pure Java math test with no JMX interaction, 
so the AIX exclusion was cargo-culted from other management tests.



##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTab.java:
##########
@@ -637,6 +644,34 @@ private void renderInfoPanel(Frame frame, Rect area) {
         frame.renderWidget(Paragraph.builder().text(Text.from(lines)).build(), 
inner);
     }
 
+    /**
+     * Snap to a nice Y-axis ceiling using a 1-2-5 sequence (scaled by 
THROUGHPUT_SCALE). For example with scale=100:
+     * 0.20 → 1, 1.5 → 2, 3 → 5, 7 → 10, 15 → 20, 35 → 50, 80 → 100, etc.
+     */
+    private static long niceMax(long rawMax) {
+        long s = MetricsCollector.THROUGHPUT_SCALE;

Review Comment:
   Done — extracted both `niceMax` and `formatThroughput` to `MetricsCollector` 
as package-private static utility methods. Used the more robust `EndpointsTab` 
version (1-2-5 loop that scales indefinitely) as the single implementation. 
Both tabs now delegate to `MetricsCollector.niceMax()` and 
`MetricsCollector.formatThroughput()`.



-- 
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]

Reply via email to