gnodet commented on code in PR #24425:
URL: https://github.com/apache/camel/pull/24425#discussion_r3524538309


##########
components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/integration/messagehistory/ManagedMessageHistoryAutoConfigIT.java:
##########
@@ -98,30 +98,34 @@ public void testMessageHistory() throws Exception {
 
         MockEndpoint.assertIsSatisfied(context);
 
-        await().atMost(Duration.ofMillis(1000L)).until(handler::hasLogs);
-
-        List<LogRecord> logs = new ArrayList<>(handler.getLogs());
-        assertFalse(logs.isEmpty(), "No metrics were exported");
-        int dataCount = 0;
-        for (LogRecord log : logs) {
-            if (log.getParameters() != null && log.getParameters().length > 0) 
{
-                MetricData metricData = (MetricData) log.getParameters()[0];
-                // Skip non-Camel metrics (e.g. otel.sdk.* internal metrics 
added in OTel 1.60+)
-                if (!metricData.getName().startsWith("camel.")) {
-                    continue;
+        // Use Awaitility to retry assertions until the OTel periodic reader 
has exported
+        // Camel metrics. On slow CI architectures the first export may be 
delayed well
+        // beyond the 300ms export interval. Assert on the last exported Camel 
metric data
+        // because earlier exports during message processing may contain 
incomplete data.
+        await().atMost(Duration.ofSeconds(20)).untilAsserted(() -> {
+            List<LogRecord> logs = new ArrayList<>(handler.getLogs());
+            assertFalse(logs.isEmpty(), "No metrics were exported");
+
+            MetricData lastCamelMetric = null;

Review Comment:
   Addressed both points in c26c8fe:
   - Added `logger.removeHandler(handler)` in a `finally` block to prevent 
handler accumulation.
   - Removed the redundant `new ArrayList<>()` wrapper (and the now-unused 
`ArrayList` import) since `getLogs()` already returns a defensive copy.



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