This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24978 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2bbc599782f78ea5f9ed5a0cfa7d77d6bd90af32 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Sep 23 22:18:45 2026 +0200 CAMEL-24978: camel-core - Backlog tracer advice fixes The aggregate backlog tracer advice now checks shouldTrace so aggregated exchanges are not traced when the tracer is in standby and not needed. The endpoint service details are set on the last trace event (was set on the first), the unused aggregate on completion is removed, and the inflight repository parameter of addRouteInflightRepositoryAdvice is used. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/impl/engine/CamelInternalProcessor.java | 55 +++------------- .../BacklogTracerAggregateStandbyTest.java | 74 ++++++++++++++++++++++ 2 files changed, 84 insertions(+), 45 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java index 8c5a14a13eb1..fb4088bad17f 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java @@ -194,7 +194,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In @Override public void addRouteInflightRepositoryAdvice(InflightRepository inflightRepository, String routeId) { - addAdvice(new CamelInternalProcessor.RouteInflightRepositoryAdvice(camelContext.getInflightRepository(), routeId)); + addAdvice(new CamelInternalProcessor.RouteInflightRepositoryAdvice(inflightRepository, routeId)); } @Override @@ -723,9 +723,9 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In input.getShortName(), input.getLabel(), level, exchangeId, correlationExchangeId, breadcrumbId, rest, template, data); if (exchange.getFromEndpoint() instanceof EndpointServiceLocation esl) { - first.setEndpointServiceUrl(esl.getServiceUrl()); - first.setEndpointServiceProtocol(esl.getServiceProtocol()); - first.setEndpointServiceMetadata(esl.getServiceMetadata()); + last.setEndpointServiceUrl(esl.getServiceUrl()); + last.setEndpointServiceProtocol(esl.getServiceProtocol()); + last.setEndpointServiceMetadata(esl.getServiceMetadata()); } backlogTracer.traceEvent(last); doneProcessing(exchange, last); @@ -796,6 +796,9 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In @Override public DefaultBacklogTracerEventMessage before(Exchange exchange) throws Exception { + if (!backlogTracer.shouldTrace(processorDefinition, exchange)) { + return null; + } String exchangeId = exchange.getExchangeId(); String correlationExchangeId = exchange.getProperty(ExchangePropertyKey.CORRELATION_ID, String.class); String breadcrumbId = exchange.getIn().getHeader(Exchange.BREADCRUMB_ID, String.class); @@ -850,9 +853,9 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In processorDefinition.getShortName(), processorDefinition.getLabel(), level, exchangeId, correlationExchangeId, breadcrumbId, false, false, data); if (exchange.getFromEndpoint() instanceof EndpointServiceLocation esl) { - first.setEndpointServiceUrl(esl.getServiceUrl()); - first.setEndpointServiceProtocol(esl.getServiceProtocol()); - first.setEndpointServiceMetadata(esl.getServiceMetadata()); + last.setEndpointServiceUrl(esl.getServiceUrl()); + last.setEndpointServiceProtocol(esl.getServiceProtocol()); + last.setEndpointServiceMetadata(esl.getServiceMetadata()); } backlogTracer.traceEvent(last); doneProcessing(exchange, last); @@ -985,44 +988,6 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In return null; } - private SynchronizationAdapter createAggregateOnCompletion( - String source, DefaultBacklogTracerEventMessage pseudoFirst) { - return new SynchronizationAdapter() { - @Override - public void onDone(Exchange exchange) { - // create pseudo last for the aggregate - String routeId = routeDefinition != null ? routeDefinition.getRouteId() : null; - String fromRouteId = exchange.getFromRouteId(); - String exchangeId = exchange.getExchangeId(); - String correlationExchangeId = exchange.getProperty(ExchangePropertyKey.CORRELATION_ID, String.class); - String breadcrumbId = exchange.getIn().getHeader(Exchange.BREADCRUMB_ID, String.class); - boolean includeExchangeProperties = backlogTracer.isIncludeExchangeProperties(); - boolean includeExchangeVariables = backlogTracer.isIncludeExchangeVariables(); - long created = exchange.getClock().getCreated(); - int level = pseudoFirst.getToNodeLevel(); - String toNode = pseudoFirst.getToNode(); - String toNodeShortName = pseudoFirst.getToNodeShortName(); - String toNodeLabel = pseudoFirst.getToNodeLabel(); - JsonObject data = MessageHelper.dumpAsJSonObject(exchange.getIn(), includeExchangeProperties, - includeExchangeVariables, true, - true, backlogTracer.isBodyIncludeStreams(), backlogTracer.isBodyIncludeFiles(), - backlogTracer.getBodyMaxChars()); - DefaultBacklogTracerEventMessage pseudoLast = new DefaultBacklogTracerEventMessage( - camelContext, - false, true, backlogTracer.incrementTraceCounter(), created, source, fromRouteId, routeId, toNode, - null, null, - null, toNodeShortName, toNodeLabel, - level, exchangeId, correlationExchangeId, breadcrumbId, rest, template, data); - backlogTracer.traceEvent(pseudoLast); - doneProcessing(exchange, pseudoLast); - doneProcessing(exchange, pseudoFirst); - // to not be confused then lets store duration on first/last as (first = 0, last = total time to process) - pseudoLast.setElapsed(pseudoFirst.getElapsed()); - pseudoFirst.setElapsed(0); - } - }; - } - @Override public void after(Exchange exchange, DefaultBacklogTracerEventMessage data) throws Exception { if (data != null) { diff --git a/core/camel-management/src/test/java/org/apache/camel/management/BacklogTracerAggregateStandbyTest.java b/core/camel-management/src/test/java/org/apache/camel/management/BacklogTracerAggregateStandbyTest.java new file mode 100644 index 000000000000..12c17ddbf01a --- /dev/null +++ b/core/camel-management/src/test/java/org/apache/camel/management/BacklogTracerAggregateStandbyTest.java @@ -0,0 +1,74 @@ +/* + * 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.CamelContext; +import org.apache.camel.builder.AggregationStrategies; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.debugger.BacklogTracer; +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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@DisabledOnOs(OS.AIX) +public class BacklogTracerAggregateStandbyTest extends ManagementTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + // tracing is in standby (not enabled) and message history is not enabled + context.setBacklogTracingStandby(true); + context.setMessageHistory(false); + return context; + } + + @Test + public void testAggregateNotTracedInStandby() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("A,B,C"); + + template.sendBody("direct:start", "A"); + template.sendBody("direct:start", "B"); + template.sendBody("direct:start", "C"); + + assertMockEndpointsSatisfied(); + + BacklogTracer tracer = context.getCamelContextExtension().getContextPlugin(BacklogTracer.class); + assertNotNull(tracer); + assertFalse(tracer.isEnabled()); + assertEquals(0, tracer.getTraceCounter()); + assertEquals(0, tracer.dumpAllTracedMessages().size()); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start").routeId("myRoute") + .aggregate(constant(true)).completionSize(3).aggregationStrategy(AggregationStrategies.string(",")) + .id("aggregate") + .to("mock:result").id("result") + .end(); + } + }; + } + +}
