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 2022/01/05 12:49:44 UTC
[camel-spring-boot] branch main updated: CAMEL-17436: Disabling health check for single route or consumer is not possible (#428)
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-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new f7f7ae6 CAMEL-17436: Disabling health check for single route or consumer is not possible (#428)
f7f7ae6 is described below
commit f7f7ae6a87ce3189e469833c04e0119f638271f3
Author: Michał Ostrowski <ka...@gmail.com>
AuthorDate: Wed Jan 5 13:49:37 2022 +0100
CAMEL-17436: Disabling health check for single route or consumer is not possible (#428)
Co-authored-by: Michał Ostrowski <mi...@apdu.pl>
---
.../health/CamelHealthCheckAutoConfiguration.java | 20 +++---
.../health/CamelHealthCheckConfigurationTest.java | 76 ++++++++++++++++++++++
.../spring/boot/actuate/health/DownRoute.java | 29 +++++++++
3 files changed, 115 insertions(+), 10 deletions(-)
diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckAutoConfiguration.java
index c5c6351..497c183 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckAutoConfiguration.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckAutoConfiguration.java
@@ -114,7 +114,7 @@ public class CamelHealthCheckAutoConfiguration {
CamelHealthCheckConfigurationProperties.HealthCheckConfigurationProperties hcc = config.getConfig().get(id);
String parent = hcc.getParent();
// lookup health check by id
- Object hc = hcr.getCheck(parent).orElse(null);
+ Object hc = hcr.getCheck(id).orElse(null);
if (hc == null) {
hc = hcr.resolveById(parent);
if (hc == null) {
@@ -122,15 +122,15 @@ public class CamelHealthCheckAutoConfiguration {
continue;
}
hcr.register(hc);
- if (hc instanceof HealthCheck) {
- ((HealthCheck) hc).getConfiguration().setParent(hcc.getParent());
- ((HealthCheck) hc).getConfiguration().setEnabled(hcc.getEnabled() != null ? hcc.getEnabled() : true);
- ((HealthCheck) hc).getConfiguration().setFailureThreshold(hcc.getFailureThreshold());
- ((HealthCheck) hc).getConfiguration().setInterval(hcc.getInterval());
- } else if (hc instanceof HealthCheckRepository) {
- ((HealthCheckRepository) hc).setEnabled(hcc.getEnabled() != null ? hcc.getEnabled() : true);
- ((HealthCheckRepository) hc).addConfiguration(id, hcc.toHealthCheckConfiguration());
- }
+ }
+
+ if (hc instanceof HealthCheck) {
+ ((HealthCheck) hc).getConfiguration().setParent(hcc.getParent());
+ ((HealthCheck) hc).getConfiguration().setEnabled(hcc.getEnabled() != null ? hcc.getEnabled() : true);
+ ((HealthCheck) hc).getConfiguration().setFailureThreshold(hcc.getFailureThreshold());
+ ((HealthCheck) hc).getConfiguration().setInterval(hcc.getInterval());
+ } else if (hc instanceof HealthCheckRepository) {
+ ((HealthCheckRepository) hc).addConfiguration(id, hcc.toHealthCheckConfiguration());
}
}
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckConfigurationTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckConfigurationTest.java
new file mode 100644
index 0000000..2543c38
--- /dev/null
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthCheckConfigurationTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.spring.boot.actuate.health;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.Status;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@CamelSpringBootTest
+@EnableAutoConfiguration
+@SpringBootApplication
+@SpringBootTest(
+ classes = {CamelAutoConfiguration.class, CamelHealthCheckAutoConfiguration.class, DownRoute.class, MyCamelRoute.class},
+ properties = {"camel.health.config[consumer\\:down-route].parent=consumers",
+ "camel.health.config[consumer\\:down-route].enabled=false"})
+class CamelHealthCheckConfigurationTest {
+
+ @Autowired
+ CamelHealthCheckIndicator indicator;
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Test
+ void shouldBeHealth() throws Exception {
+ // 'down-route' is DOWN, but health check for this consumer should be disabled by configuration
+ final Health health = indicator.health();
+ assertThat(health)
+ .as("Has health")
+ .isNotNull()
+ .as("Should be UP")
+ .matches(h -> h.getStatus() == Status.UP);
+ }
+
+ @Test
+ void shouldNotDisableAllConsumersHealthChecks() {
+ @SuppressWarnings("resource")
+ final HealthCheckRegistry registry = camelContext.getExtension(HealthCheckRegistry.class);
+
+ assertThat(registry.getCheck("consumer:down-route"))
+ .as("'down-route' health check is disabled")
+ .isPresent()
+ .get()
+ .matches(hc -> !hc.getConfiguration().isEnabled());
+
+ assertThat(registry.getCheck("consumer:route1"))
+ .as("other route health check is enabled")
+ .isPresent()
+ .get()
+ .matches(hc -> hc.getConfiguration().isEnabled());
+ }
+}
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/DownRoute.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/DownRoute.java
new file mode 100644
index 0000000..7d88fe3
--- /dev/null
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/DownRoute.java
@@ -0,0 +1,29 @@
+/*
+ * 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.spring.boot.actuate.health;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DownRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("scheduler://foo?initialDelay=60000").routeId("down-route").to("log:bar");
+ }
+}