You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/12/16 16:38:31 UTC

(camel) 06/07: CAMEL-20242: camel-core: RouteController health check to be DOWN during starting routes. Supervising route controller option to be DOWN during restarting phase.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch rc
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2cb76b73aeec025b1472d5b5c291f8c6091c7629
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 16 16:56:04 2023 +0100

    CAMEL-20242: camel-core: RouteController health check to be DOWN during starting routes. Supervising route controller option to be DOWN during restarting phase.
---
 .../camel/core/xml/AbstractCamelContextFactoryBean.java |  8 ++++++--
 .../camel/core/xml/CamelRouteControllerDefinition.java  | 17 +++++++++++++++++
 .../camel/impl/health/RouteControllerHealthCheck.java   |  6 ++++--
 .../modules/ROOT/pages/route-controller.adoc            |  2 ++
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index 9e4f9db6442..316ccf72302 100644
--- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -880,11 +880,15 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
             src.setBackOffMultiplier(backOffMultiplier);
         }
         Boolean unhealthyOnExhausted = CamelContextHelper.parseBoolean(getContext(), rc.getUnhealthyOnExhausted());
-        if (unhealthyOnExhausted != null && unhealthyOnExhausted) {
+        if (src != null && unhealthyOnExhausted != null && unhealthyOnExhausted) {
             src.setUnhealthyOnExhausted(unhealthyOnExhausted);
         }
+        Boolean unhealthyOnRestarting = CamelContextHelper.parseBoolean(getContext(), rc.getUnhealthyOnRestarting());
+        if (src != null && unhealthyOnRestarting != null && unhealthyOnRestarting) {
+            src.setUnhealthyOnRestarting(unhealthyOnRestarting);
+        }
         LoggingLevel loggingLevel = CamelContextHelper.parse(getContext(), LoggingLevel.class, rc.getLoggingLevel());
-        if (loggingLevel != null) {
+        if (src != null && loggingLevel != null) {
             src.setLoggingLevel(loggingLevel);
         }
     }
diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelRouteControllerDefinition.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelRouteControllerDefinition.java
index 3e3ec752627..fa09fc2ccbf 100644
--- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelRouteControllerDefinition.java
+++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelRouteControllerDefinition.java
@@ -60,6 +60,9 @@ public class CamelRouteControllerDefinition extends IdentifiedType {
     @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
     private String unhealthyOnExhausted;
     @XmlAttribute
+    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
+    private String unhealthyOnRestarting;
+    @XmlAttribute
     @Metadata(javaType = "org.apache.camel.LoggingLevel", defaultValue = "DEBUG", enums = "TRACE,DEBUG,INFO,WARN,ERROR,OFF")
     private String loggingLevel;
 
@@ -209,6 +212,20 @@ public class CamelRouteControllerDefinition extends IdentifiedType {
         this.unhealthyOnExhausted = unhealthyOnExhausted;
     }
 
+    public String getUnhealthyOnRestarting() {
+        return unhealthyOnRestarting;
+    }
+
+    /**
+     * Whether to mark the route as unhealthy (down) when the route failed to initially start, and is being controlled
+     * for restarting (backoff).
+     *
+     * Setting this to true allows health checks to know about this and can report the Camel application as DOWN.
+     */
+    public void setUnhealthyOnRestarting(String unhealthyOnRestarting) {
+        this.unhealthyOnRestarting = unhealthyOnRestarting;
+    }
+
     public String getLoggingLevel() {
         return loggingLevel;
     }
diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteControllerHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteControllerHealthCheck.java
index 00639f256b6..5f23eb6e6a1 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteControllerHealthCheck.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteControllerHealthCheck.java
@@ -76,7 +76,8 @@ public class RouteControllerHealthCheck extends AbstractHealthCheck {
         }
     }
 
-    private void builderDetails(HealthCheckResultBuilder builder, SupervisingRouteController src, Route route, boolean exhausted) {
+    private void builderDetails(
+            HealthCheckResultBuilder builder, SupervisingRouteController src, Route route, boolean exhausted) {
         String routeId = route.getRouteId();
         Throwable cause = src.getRestartException(routeId);
         if (cause != null) {
@@ -114,7 +115,8 @@ public class RouteControllerHealthCheck extends AbstractHealthCheck {
                     String msg;
                     if (exhausted) {
                         msg = String.format("Restarting route: %s is exhausted after %s attempts due %s."
-                                            + " No more attempts will be made and the route is no longer supervised by this route controller and remains as stopped.", routeId, attempts,
+                                            + " No more attempts will be made and the route is no longer supervised by this route controller and remains as stopped.",
+                                routeId, attempts,
                                 cause.getMessage());
                     } else {
                         msg = String.format("Failed restarting route: %s attempt: %s due: %s", routeId, attempts,
diff --git a/docs/user-manual/modules/ROOT/pages/route-controller.adoc b/docs/user-manual/modules/ROOT/pages/route-controller.adoc
index 095a042b1ee..0d3dd197f1c 100644
--- a/docs/user-manual/modules/ROOT/pages/route-controller.adoc
+++ b/docs/user-manual/modules/ROOT/pages/route-controller.adoc
@@ -143,6 +143,8 @@ You can configure the `SupervisingRouteController` using the following options:
 | IncludeRoutes | | Pattern for filtering routes to be included as supervised. The pattern is matching on route id, and endpoint uri for the route. Multiple patterns can be separated by comma. For example to include all kafka routes, you can say kafka:. And to include routes with specific route ids myRoute,myOtherRoute. The pattern supports wildcards and uses the matcher from org.apache.camel.support.PatternHelper#matchPattern.
 | ExcludeRoutes | | Pattern for filtering routes to be excluded as supervised. The pattern is matching on route id, and endpoint uri for the route. Multiple patterns can be separated by comma. For example to exclude all JMS routes, you can say jms:. And to exclude routes with specific route ids mySpecialRoute,myOtherSpecialRoute. The pattern supports wildcards and uses the matcher from org.apache.camel.support.PatternHelper#matchPattern.
 | ThreadPoolSize | `1` | The number of threads used by the route controller scheduled thread pool that are used for restarting routes. The pool uses 1 thread by default, but you can increase this to allow the controller to concurrently attempt to restart multiple routes in case more than one route has problems starting.
+| UnhealthyOnExhausted | `false` | Whether to mark the route as unhealthy (down) when all restarting attempts (backoff) have failed and the route is not successfully started and the route manager is giving up. Setting this to true allows health checks to know about this and can report the Camel application as DOWN.
+| routeControllerUnhealthyOnRestarting | `false` | Whether to mark the route as unhealthy (down) when the route failed to initially start, and is being controlled for restarting (backoff). Setting this to true allows health checks to know about this and can report the Camel application as DOWN.
 |=======================================================================
 
 === Filtering routes to fail fast