This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 218dc2e CAMEL-15333: camel-health - Consumers have their own
health-check-repo. Make it possible to turn them off, and have similar
configuration like routes.
218dc2e is described below
commit 218dc2ebbd46540cb6a64f412f7518307c1ccc48
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 5 10:05:12 2021 +0100
CAMEL-15333: camel-health - Consumers have their own health-check-repo.
Make it possible to turn them off, and have similar configuration like routes.
---
.../camel/impl/health/ConsumerHealthCheck.java | 42 ++++++----------------
.../health/ConsumersHealthCheckRepository.java | 2 +-
.../apache/camel/impl/health/RouteHealthCheck.java | 18 ++++++++--
3 files changed, 28 insertions(+), 34 deletions(-)
diff --git
a/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumerHealthCheck.java
b/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumerHealthCheck.java
index 6f56c76..cd6ccf0 100644
---
a/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumerHealthCheck.java
+++
b/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumerHealthCheck.java
@@ -19,53 +19,41 @@ package org.apache.camel.impl.health;
import java.util.Map;
import org.apache.camel.Consumer;
-import org.apache.camel.ServiceStatus;
+import org.apache.camel.Route;
import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckAware;
import org.apache.camel.health.HealthCheckResultBuilder;
-import org.apache.camel.support.service.ServiceSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* {@link HealthCheck} for a given consumer.
*/
-public class ConsumerHealthCheck extends AbstractHealthCheck {
+public class ConsumerHealthCheck extends RouteHealthCheck {
private static final Logger LOGGER =
LoggerFactory.getLogger(ConsumerHealthCheck.class);
private final Consumer consumer;
- private final String routeId;
- public ConsumerHealthCheck(Consumer consumer, String id) {
- super("camel", id);
- this.consumer = consumer;
- this.routeId = id.replace("consumer:", "");
+ public ConsumerHealthCheck(Route route, String id) {
+ super(route, id);
+ this.consumer = route.getConsumer();
}
@Override
- public boolean isLiveness() {
- // this check is only for readiness
- return false;
- }
-
- @Override
- protected void doCall(HealthCheckResultBuilder builder, Map<String,
Object> options) {
- final ServiceStatus status =
getCamelContext().getRouteController().getRouteStatus(routeId);
- builder.detail("route.id", routeId);
- builder.detail("route.status", status.name());
- builder.detail("route.context.name", getCamelContext().getName());
-
- if (consumer instanceof HealthCheckAware) {
+ protected void doCallCheck(HealthCheckResultBuilder builder, Map<String,
Object> options) {
+ // only need to do consumer check if the route is UP
+ boolean up = builder.state().compareTo(State.UP) == 0;
+ if (up && consumer instanceof HealthCheckAware) {
// health check is optional
HealthCheck hc = ((HealthCheckAware) consumer).getHealthCheck();
if (hc != null) {
if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Calling HealthCheck on consumer route: {}",
routeId);
+ LOGGER.trace("Calling HealthCheck on consumer route: {}",
route.getRouteId());
}
Result result = hc.call();
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("HealthCheck consumer route: {} -> {}",
routeId, result.getState());
+ LOGGER.debug("HealthCheck consumer route: {} -> {}",
route.getRouteId(), result.getState());
}
builder.state(result.getState());
@@ -76,15 +64,7 @@ public class ConsumerHealthCheck extends AbstractHealthCheck
{
builder.error(result.getError().get());
}
builder.details(result.getDetails());
- return;
}
}
-
- // consumer has no fine-grained health-check so check whether is
started
- boolean started = true;
- if (consumer instanceof ServiceSupport) {
- started = ((ServiceSupport) consumer).isStarted();
- }
- builder.state(started ? State.UP : State.DOWN);
}
}
diff --git
a/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumersHealthCheckRepository.java
b/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumersHealthCheckRepository.java
index 6ec18f2..4504ada 100644
---
a/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumersHealthCheckRepository.java
+++
b/core/camel-health/src/main/java/org/apache/camel/impl/health/ConsumersHealthCheckRepository.java
@@ -125,7 +125,7 @@ public class ConsumersHealthCheckRepository implements
CamelContextAware, Health
return checks.computeIfAbsent(route.getConsumer(), r -> {
// must prefix id with consumer: to not clash with route
String id = "consumer:" + route.getRouteId();
- ConsumerHealthCheck chc = new
ConsumerHealthCheck(route.getConsumer(), id);
+ ConsumerHealthCheck chc = new ConsumerHealthCheck(route, id);
CamelContextAware.trySetCamelContext(chc, route.getCamelContext());
HealthCheckConfiguration hcc = matchConfiguration(id);
if (hcc != null) {
diff --git
a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
index 44cde6b..690e8ef 100644
---
a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
+++
b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
@@ -28,10 +28,14 @@ import org.apache.camel.health.HealthCheckResultBuilder;
*/
public class RouteHealthCheck extends AbstractHealthCheck {
- private final Route route;
+ final Route route;
public RouteHealthCheck(Route route) {
- super("camel", "route:" + route.getId());
+ this(route, "route:" + route.getId());
+ }
+
+ public RouteHealthCheck(Route route, String id) {
+ super("camel", id);
this.route = route;
}
@@ -76,5 +80,15 @@ public class RouteHealthCheck extends AbstractHealthCheck {
}
}
}
+
+ doCallCheck(builder, options);
}
+
+ /**
+ * Additional checks
+ */
+ protected void doCallCheck(HealthCheckResultBuilder builder, Map<String,
Object> options) {
+ // noop
+ }
+
}