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 2021/10/29 11:17:03 UTC
[camel] 05/16: CAMEL-15133: Adding fine-grained consumer health
check to route checks
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch custom-health
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 79703ff98993ecda03fcc37b40850e7453fe7921
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 28 10:20:00 2021 +0200
CAMEL-15133: Adding fine-grained consumer health check to route checks
---
.../support/ScheduledPollConsumerHealthCheck.java | 39 ++++++++++++++++------
1 file changed, 29 insertions(+), 10 deletions(-)
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 5d3591c..ab10e63 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
@@ -1,3 +1,19 @@
+/*
+ * 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.support;
import java.util.Map;
@@ -7,44 +23,47 @@ import org.apache.camel.health.HealthCheckConfiguration;
import org.apache.camel.health.HealthCheckResultBuilder;
import org.apache.camel.util.URISupport;
+/**
+ * {@link HealthCheck} that uses the last polling state from {@link ScheduledPollConsumer}
+ * when reporting the health.
+ */
public class ScheduledPollConsumerHealthCheck implements HealthCheck {
- public static final String FAILURE_COUNT = "failure.count";
- public static final String ROUTE = "route.id";
+ public static final String ENDPOINT_URI = "endpoint.uri";
+ public static final String ERROR_COUNT = "failure.error.count";
- private final HealthCheckConfiguration configuration = new HealthCheckConfiguration();
private final ScheduledPollConsumer consumer;
private final String id;
+ private final String sanitizedUri; // used for error message which should mask sensitive details
public ScheduledPollConsumerHealthCheck(ScheduledPollConsumer consumer, String id) {
this.consumer = consumer;
this.id = id;
+ this.sanitizedUri = URISupport.sanitizeUri(consumer.getEndpoint().getEndpointBaseUri());
}
@Override
public HealthCheckConfiguration getConfiguration() {
- return configuration;
+ throw new UnsupportedOperationException("Configuration is not in use for this kind of health-check");
}
@Override
public Result call(Map<String, Object> options) {
final HealthCheckResultBuilder builder = HealthCheckResultBuilder.on(this);
- builder.detail(ROUTE, consumer.getRouteId());
+ builder.detail(ENDPOINT_URI, consumer.getEndpoint().getEndpointUri());
long ec = consumer.getErrorCounter();
Throwable cause = consumer.getLastError();
- boolean healthy = ec == 0 || ec < configuration.getFailureThreshold();
+ boolean healthy = ec == 0;
if (healthy) {
builder.up();
} else {
builder.down();
- builder.detail(FAILURE_COUNT, ec);
- String uri = consumer.getEndpoint().getEndpointBaseUri();
- uri = URISupport.sanitizeUri(uri);
+ builder.detail(ERROR_COUNT, ec);
String rid = consumer.getRouteId();
String msg = "Consumer failed polling %s times route: %s (%s)";
- builder.message(String.format(msg, ec, rid, uri));
+ builder.message(String.format(msg, ec, rid, sanitizedUri));
builder.error(cause);
}