You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/03/24 11:23:59 UTC

[camel] branch main created (now 10effd4)

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

acosentino pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


      at 10effd4  CAMEL-17848: health-check - reported kind should be what kind the health-check is.

This branch includes the following new commits:

     new 12b84942 CAMEL-17848: camel-jbang - Health check reporting overall status readiness vs liveness
     new 10effd4  CAMEL-17848: health-check - reported kind should be what kind the health-check is.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[camel] 02/02: CAMEL-17848: health-check - reported kind should be what kind the health-check is.

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 10effd44e309c51c94907b561562f6e16f13c9c0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 24 12:17:48 2022 +0100

    CAMEL-17848: health-check - reported kind should be what kind the health-check is.
---
 .../org/apache/camel/impl/health/AbstractHealthCheck.java    | 12 +++++++++---
 .../camel/support/ScheduledPollConsumerHealthCheck.java      | 11 +++++++++--
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java
index ec2b1ac..c29ef1d 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java
@@ -134,9 +134,15 @@ public abstract class AbstractHealthCheck implements HealthCheck, CamelContextAw
         builder.state(registry.getInitialState());
 
         // what kind of check is this
-        HealthCheck.Kind kind = (Kind) options.getOrDefault(CHECK_KIND, Kind.ALL);
-        builder.detail(CHECK_KIND, kind.name());
-
+        HealthCheck.Kind kind;
+        if (isLiveness() && isReadiness()) {
+            // if we can do both then use kind from what type we were invoked as
+            kind = (Kind) options.getOrDefault(CHECK_KIND, Kind.ALL);
+        } else {
+            // we can only be either live or ready so report that
+            kind = isLiveness() ? Kind.LIVENESS : Kind.READINESS;
+        }
+        builder.detail(CHECK_KIND, kind);
         // Extract relevant information from meta data.
         int invocationCount = (Integer) meta.getOrDefault(INVOCATION_COUNT, 0);
         int failureCount = (Integer) meta.getOrDefault(FAILURE_COUNT, 0);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumerHealthCheck.java b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumerHealthCheck.java
index e3a1f4b..089e04f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumerHealthCheck.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumerHealthCheck.java
@@ -67,8 +67,15 @@ public class ScheduledPollConsumerHealthCheck implements HealthCheck {
         builder.detail(FAILURE_ENDPOINT_URI, sanitizedUri);
 
         // what kind of check is this
-        HealthCheck.Kind kind = (Kind) options.getOrDefault(CHECK_KIND, Kind.ALL);
-        builder.detail(CHECK_KIND, kind.name());
+        HealthCheck.Kind kind;
+        if (isLiveness() && isReadiness()) {
+            // if we can do both then use kind from what type we were invoked as
+            kind = (Kind) options.getOrDefault(CHECK_KIND, Kind.ALL);
+        } else {
+            // we can only be either live or ready so report that
+            kind = isLiveness() ? Kind.LIVENESS : Kind.READINESS;
+        }
+        builder.detail(CHECK_KIND, kind);
 
         if (!isEnabled()) {
             builder.message("Disabled");

[camel] 01/02: CAMEL-17848: camel-jbang - Health check reporting overall status readiness vs liveness

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 12b84942014cc21eea1373c8c4b21174bfe505ee
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 24 12:07:13 2022 +0100

    CAMEL-17848: camel-jbang - Health check reporting overall status readiness vs liveness
---
 .../org/apache/camel/main/VertxHttpServer.java     | 69 +++++++++-------------
 1 file changed, 29 insertions(+), 40 deletions(-)

diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index e6450b8..adc3bf2 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -207,6 +207,7 @@ public final class VertxHttpServer {
 
                 boolean all = ctx.currentRoute() == health;
                 boolean liv = ctx.currentRoute() == live;
+                boolean rdy = ctx.currentRoute() == ready;
 
                 Collection<HealthCheck.Result> res;
                 if (all) {
@@ -221,13 +222,33 @@ public final class VertxHttpServer {
                 sb.append("{\n");
 
                 HealthCheckRegistry registry = HealthCheckRegistry.get(context);
-                String level = registry.getExposureLevel();
+                String level = ctx.request().getParam("exposureLevel");
+                if (level == null) {
+                    level = registry.getExposureLevel();
+                }
+
+                // are we UP
+                boolean up;
+                if (rdy) {
+                    // readiness requires that all are UP
+                    up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+                } else {
+                    // liveness will fail if there is any down
+                    up = res.stream().noneMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+                }
+
                 if ("oneline".equals(level)) {
-                    healthCheckOneline(sb, res);
+                    // only brief status
+                    healthCheckStatus(sb, up);
                 } else if ("full".equals(level)) {
-                    healthCheckFull(sb, res);
+                    // include all details
+                    List<HealthCheck.Result> list = new ArrayList<>(res);
+                    healthCheckDetails(sb, list, up);
                 } else {
-                    healthCheckDefault(sb, res);
+                    // include only DOWN details
+                    List<HealthCheck.Result> downs = res.stream().filter(r -> r.getState().equals(HealthCheck.State.DOWN))
+                            .collect(Collectors.toList());
+                    healthCheckDetails(sb, downs, up);
                 }
                 sb.append("}\n");
                 ctx.end(sb.toString());
@@ -240,8 +261,7 @@ public final class VertxHttpServer {
         phc.addHttpEndpoint("/q/health");
     }
 
-    private static void healthCheckOneline(StringBuilder sb, Collection<HealthCheck.Result> res) {
-        boolean up = res.stream().noneMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+    private static void healthCheckStatus(StringBuilder sb, boolean up) {
         if (up) {
             sb.append("    \"status\": \"UP\"\n");
         } else {
@@ -249,15 +269,9 @@ public final class VertxHttpServer {
         }
     }
 
-    private static void healthCheckFull(StringBuilder sb, Collection<HealthCheck.Result> res) {
-        // we just want a brief summary or either UP or DOWN
-        boolean up = res.stream().noneMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
-        if (up) {
-            sb.append("    \"status\": \"UP\"");
-        } else {
-            sb.append("    \"status\": \"DOWN\"");
-        }
-        List<HealthCheck.Result> checks = new ArrayList<>(res);
+    private static void healthCheckDetails(StringBuilder sb, List<HealthCheck.Result> checks, boolean up) {
+        healthCheckStatus(sb, up);
+
         if (!checks.isEmpty()) {
             sb.append(",\n");
             sb.append("    \"checks\": [\n");
@@ -277,31 +291,6 @@ public final class VertxHttpServer {
         }
     }
 
-    private static void healthCheckDefault(StringBuilder sb, Collection<HealthCheck.Result> res) {
-        // we just want a brief summary or either UP or DOWN
-        boolean up = res.stream().noneMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
-        if (up) {
-            sb.append("    \"status\": \"UP\"\n");
-        } else {
-            // when we are DOWN then grab the only downs
-            List<HealthCheck.Result> down
-                    = res.stream().filter(r -> r.getState().equals(HealthCheck.State.DOWN)).collect(Collectors.toList());
-            sb.append("    \"status\": \"DOWN\",\n");
-            sb.append("    \"checks\": [\n");
-            for (int i = 0; i < down.size(); i++) {
-                HealthCheck.Result d = down.get(i);
-                sb.append("        {\n");
-                reportHealthCheck(sb, d);
-                if (i < down.size() - 1) {
-                    sb.append("        },\n");
-                } else {
-                    sb.append("        }\n");
-                }
-            }
-            sb.append("    ]\n");
-        }
-    }
-
     private static void reportHealthCheck(StringBuilder sb, HealthCheck.Result d) {
         sb.append("            \"name\": \"").append(d.getCheck().getId()).append("\",\n");
         sb.append("            \"status\": \"").append(d.getState()).append("\",\n");