This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 7a58c2b CAMEL-16076: camel-core - Supervised route controller - better activity logging 7a58c2b is described below commit 7a58c2b0f9612c205ddbafbe30a8487f46021d14 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Jan 29 15:16:46 2021 +0100 CAMEL-16076: camel-core - Supervised route controller - better activity logging --- .../engine/DefaultSupervisingRouteController.java | 80 +++++++++++++++++++--- .../org/apache/camel/util/backoff/BackOff.java | 20 ++++-- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java index 90df309..ece2f9b 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java @@ -17,6 +17,7 @@ package org.apache.camel.impl.engine; import java.time.Duration; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -41,6 +42,7 @@ import org.apache.camel.NonManagedService; import org.apache.camel.Route; import org.apache.camel.RuntimeCamelException; import org.apache.camel.ServiceStatus; +import org.apache.camel.StartupSummaryLevel; import org.apache.camel.spi.HasId; import org.apache.camel.spi.RouteController; import org.apache.camel.spi.RouteError; @@ -50,6 +52,7 @@ import org.apache.camel.spi.SupervisingRouteController; import org.apache.camel.support.PatternHelper; import org.apache.camel.support.RoutePolicySupport; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; import org.apache.camel.util.backoff.BackOff; import org.apache.camel.util.backoff.BackOffTimer; import org.apache.camel.util.function.ThrowingConsumer; @@ -196,7 +199,9 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im // prevent routes from automatic being started by default CamelContext context = getCamelContext(); context.setAutoStartup(false); + // use route policy to supervise the routes context.addRoutePolicyFactory(new ManagedRoutePolicyFactory()); + // use startup listener to hook into camel context to let this begin supervising routes after context is started context.addStartupListener(this.listener); } @@ -204,8 +209,8 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im protected void doStart() throws Exception { this.backOff = new BackOff( Duration.ofMillis(backOffDelay), - backOffMaxDelay > 0 ? Duration.ofMillis(backOffMaxDelay) : Duration.ofMillis(Long.MAX_VALUE), - backOffMaxElapsedTime > 0 ? Duration.ofMillis(backOffMaxElapsedTime) : Duration.ofMillis(Long.MAX_VALUE), + backOffMaxDelay > 0 ? Duration.ofMillis(backOffMaxDelay) : null, + backOffMaxElapsedTime > 0 ? Duration.ofMillis(backOffMaxElapsedTime) : null, backOffMaxAttempts > 0 ? backOffMaxAttempts : Long.MAX_VALUE, backOffMultiplier); @@ -463,11 +468,66 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im } } - LOG.info("Total managed routes: {} of which {} successfully started (restarting: {}, exhausted: {})", - routes.size(), - routes.stream().filter(r -> r.getStatus() == ServiceStatus.Started).count(), - routeManager.routes.size(), - routeManager.exhausted.size()); + if (getCamelContext().getStartupSummaryLevel() != StartupSummaryLevel.Off + && getCamelContext().getStartupSummaryLevel() != StartupSummaryLevel.Oneline) { + // log after first round of attempts + logRouteStartupSummary(); + } + } + + private void logRouteStartupSummary() { + int started = 0; + int total = 0; + int restarting = 0; + int exhausted = 0; + List<String> lines = new ArrayList<>(); + for (RouteHolder route : routes) { + String id = route.getId(); + String status = getRouteStatus(id).name(); + if (ServiceStatus.Started.name().equals(status)) { + // only include started routes as we pickup restarting/exhausted in the following + total++; + started++; + // use basic endpoint uri to not log verbose details or potential sensitive data + String uri = route.get().getEndpoint().getEndpointBaseUri(); + uri = URISupport.sanitizeUri(uri); + lines.add(String.format("\t%s %s (%s)", status, id, uri)); + } + } + for (RouteHolder route : routeManager.routes.keySet()) { + total++; + restarting++; + String id = route.getId(); + String status = "Restarting"; + // use basic endpoint uri to not log verbose details or potential sensitive data + String uri = route.get().getEndpoint().getEndpointBaseUri(); + uri = URISupport.sanitizeUri(uri); + BackOff backOff = getBackOff(id); + lines.add(String.format("\t%s %s (%s) with %s", status, id, uri, backOff)); + } + for (RouteHolder route : routeManager.exhausted.keySet()) { + total++; + exhausted++; + String id = route.getId(); + String status = "Exhausted"; + // use basic endpoint uri to not log verbose details or potential sensitive data + String uri = route.get().getEndpoint().getEndpointBaseUri(); + uri = URISupport.sanitizeUri(uri); + lines.add(String.format("\t%s %s (%s)", status, id, uri)); + } + + if (restarting == 0 && exhausted == 0) { + LOG.info("Routes startup summary (total:{} started:{})", total, started); + } else { + LOG.info("Routes startup summary (total:{} started:{} restarting:{} exhausted:{})", total, started, restarting, + exhausted); + } + if (getCamelContext().getStartupSummaryLevel() == StartupSummaryLevel.Default + || getCamelContext().getStartupSummaryLevel() == StartupSummaryLevel.Verbose) { + for (String line : lines) { + LOG.info(line); + } + } } private boolean isSupervised(Route route) { @@ -499,7 +559,7 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im r -> { BackOff backOff = getBackOff(r.getId()); - logger.info("Start supervising route: {} with back-off: {}", r.getId(), backOff); + logger.debug("Supervising route: {} with back-off: {}", r.getId(), backOff); BackOffTimer.Task task = timer.schedule(backOff, context -> { final BackOffTimer.Task state = getBackOffContext(r.getId()).orElse(null); @@ -563,7 +623,7 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im exceptions.remove(route.getId()); BackOffTimer.Task task = routes.remove(route); if (task != null) { - LOG.info("Cancelling restart task for route: {}", route.getId()); + LOG.debug("Cancelling restart task for route: {}", route.getId()); task.cancel(); } @@ -667,7 +727,7 @@ public class DefaultSupervisingRouteController extends DefaultRouteController im private class ManagedRoutePolicy extends RoutePolicySupport implements NonManagedService { - // we dont want this policy to be registed in JMX + // we dont want this policy to be registered in JMX private void startRoute(RouteHolder holder) { try { diff --git a/core/camel-util/src/main/java/org/apache/camel/util/backoff/BackOff.java b/core/camel-util/src/main/java/org/apache/camel/util/backoff/BackOff.java index 5b1a323..7037a2f 100644 --- a/core/camel-util/src/main/java/org/apache/camel/util/backoff/BackOff.java +++ b/core/camel-util/src/main/java/org/apache/camel/util/backoff/BackOff.java @@ -111,13 +111,19 @@ public final class BackOff { @Override public String toString() { - return "BackOff[" - + "delay=" + delay.toMillis() - + ", maxDelay=" + (maxDelay != MAX_DURATION ? maxDelay.toMillis() : "") - + ", maxElapsedTime=" + (maxElapsedTime != MAX_DURATION ? maxElapsedTime.toMillis() : "") - + ", maxAttempts=" + maxAttempts - + ", multiplier=" + multiplier - + ']'; + StringBuilder sb = new StringBuilder(); + sb.append("BackOff["); + sb.append("delay=").append(delay.toMillis()); + if (maxDelay != MAX_DURATION) { + sb.append(", maxDelay=").append(maxDelay.toMillis()); + } + if (maxElapsedTime != MAX_DURATION) { + sb.append(", maxElapsedTime=").append(maxElapsedTime.toMillis()); + } + sb.append(", maxAttempts=").append(maxAttempts); + sb.append(", multiplier=").append(multiplier); + sb.append("]"); + return sb.toString(); } // *****************************************