From f232b3ee5857599fcf6289f8b5c6f01f8be25da5 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Tue, 10 Dec 2024 10:49:13 +0100 Subject: [PATCH] feat(extensions): observability services unit and integration tests --- .../extensions/observability-services.adoc | 64 ++++++++ .../observability-services/deployment/pom.xml | 18 ++- .../ObservabilityServicesProcessor.java | 2 +- .../MicroProfileHealthEnabledTest.java | 72 +++++++++ .../MicrometerMetricsConfigDefaultsTest.java | 111 +++++++++++++ .../deployment/OpenTelemetryEnabledTest.java | 62 ++++++++ .../runtime/src/main/doc/usage.adoc | 11 +- extensions/pom.xml | 3 +- .../observability-services/pom.xml | 149 ++++++++++++++++++ ...servabilityServicesHealthRouteBuilder.java | 40 +++++ .../src/main/resources/application.properties | 24 +++ .../it/ObservabilityServicesDefaultTest.java | 70 ++++++++ .../it/ObservabilityServicesIT.java | 24 +++ integration-tests/pom.xml | 1 + 14 files changed, 639 insertions(+), 12 deletions(-) rename extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/{observability/services => observabilityservices}/deployment/ObservabilityServicesProcessor.java (93%) create mode 100644 extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicroProfileHealthEnabledTest.java create mode 100644 extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicrometerMetricsConfigDefaultsTest.java create mode 100644 extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/OpenTelemetryEnabledTest.java create mode 100644 integration-tests/observability-services/pom.xml create mode 100644 integration-tests/observability-services/src/main/java/org/apache/camel/quarkus/component/observabilityservices/it/health/ObservabilityServicesHealthRouteBuilder.java create mode 100644 integration-tests/observability-services/src/main/resources/application.properties create mode 100644 integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesDefaultTest.java create mode 100644 integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesIT.java diff --git a/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc b/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc index a0e0546c63de..061c73255ce4 100644 --- a/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc @@ -43,3 +43,67 @@ Or add the coordinates to your existing project: ifeval::[{doc-show-user-guide-link} == true] Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. endif::[] + +[id="extensions-observability-services-usage"] +== Usage +This extension is used to provide a set of opinionated components and configuration which simplify operations such as observability on cloud environments. Although the component is mainly targeted for cloud, it can be used in any other environment, giving to the Camel application the capability to expose a set of observability features by default. + +All you need to do is to add the dependency to the classpath. There's no need to add any further configuration. Each individual component will be configured using each own default settings except the endpoint which will be exposed in */observe/* by default. + +If you need to customize each of the different components provided within this service, then, you can specify in the *application.properties* each of the configuration as it would be done normally when you provide the individual component. + +[id="extensions-observability-services-usage-components"] +== Components + +The presence of this dependency will provide the following extensions: + +* Camel Quarkus Microprofile +* Camel Quarkus Management +* Camel Quarkus Micrometer +* Camel Quarkus OpenTelemetry +* Quarkus Micrometer Registry Prometheus + +[id="extensions-observability-services-usage-list-of-known-endpoints"] +=== List of known endpoints + +The presence of this dependency will expose the following endpoints: + +|==== +|Endpoint | Description + +| `/observe/health` | startup probe endpoint +| `/observe/health/live` | liveness probe endpoint +| `/observe/health/ready` | readiness probe endpoint +| `/observe/metrics` | metrics exposed as in Micrometer Prometheus Registry + +|==== + +NOTE: you can configure the endpoints as you'd do normally within each extension configuration. + +[id="extensions-observability-services-usage-opentelemetry-configuration"] +== OpenTelemetry configuration + +The presence of this component will provide the required instrumentation to easily enable the collection of Opentelemetry metrics. The Camel Quarkus Opentelemetry extension instrument your application with a service which periodically pushes OTEL traces to the collector. This is disabled by default in order to prevent the application to push traces when no telemetry server is available. + +In order to turn it on, you need to specify the following configuration explicitly: + +``` +quarkus.otel.sdk.disabled=false +``` + +Beside that, you can change any further parameter, like, for instance, the server where to push the traces (default, `http://localhost:4317`) + +``` +quarkus.otel.exporter.otlp.traces.endpoint=http://my-otel-collector.svc:4317 +``` + +NOTE: Quarkus runtime defaults to gRPC protocol (port 4317). + +[id="extensions-observability-services-usage-jmx-configuration"] +== JMX configuration + +The presence of this component implies the presence of `camel-management` component. This is in charge to include information about Camel application status in JMX format. + +NOTE: the presence of this components automatically enable the collection of the JMX metrics. This should be negligible from performance point of view, however, you may want to disable that running the application with `-Dorg.apache.camel.jmx.disabled=true` JVM option. + + diff --git a/extensions/observability-services/deployment/pom.xml b/extensions/observability-services/deployment/pom.xml index 013f2608f6dc..308de647f334 100644 --- a/extensions/observability-services/deployment/pom.xml +++ b/extensions/observability-services/deployment/pom.xml @@ -56,13 +56,25 @@ org.apache.camel.quarkus camel-quarkus-opentelemetry-deployment + + org.apache.camel.quarkus + camel-quarkus-management-deployment + + io.quarkus - quarkus-opentelemetry-deployment + quarkus-junit5-internal + test - org.apache.camel.quarkus - camel-quarkus-management-deployment + io.quarkus + quarkus-security-deployment + test + + + io.quarkus + quarkus-vertx-http + test diff --git a/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observability/services/deployment/ObservabilityServicesProcessor.java b/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java similarity index 93% rename from extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observability/services/deployment/ObservabilityServicesProcessor.java rename to extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java index 74f498f1d29f..b599823fd12b 100644 --- a/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observability/services/deployment/ObservabilityServicesProcessor.java +++ b/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.observability.services.deployment; +package org.apache.camel.quarkus.component.observabilityservices.deployment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; diff --git a/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicroProfileHealthEnabledTest.java b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicroProfileHealthEnabledTest.java new file mode 100644 index 000000000000..e8c1b50d43e1 --- /dev/null +++ b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicroProfileHealthEnabledTest.java @@ -0,0 +1,72 @@ +/* + * 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.quarkus.component.observabilityservices.deployment; + +import io.quarkus.test.QuarkusUnitTest; +import jakarta.inject.Inject; +import org.apache.camel.CamelContext; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.impl.health.ConsumersHealthCheckRepository; +import org.apache.camel.impl.health.ContextHealthCheck; +import org.apache.camel.impl.health.RoutesHealthCheckRepository; +import org.apache.camel.microprofile.health.CamelMicroProfileHealthCheckRegistry; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MicroProfileHealthEnabledTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + CamelContext context; + + @Test + public void healthCheckRegistryNotNull() { + HealthCheckRegistry registry = HealthCheckRegistry.get(context); + assertNotNull(registry); + assertTrue(registry instanceof CamelMicroProfileHealthCheckRegistry); + assertEquals("camel-microprofile-health", registry.getId()); + } + + @Test + public void contextHealthCheckNotNull() { + ContextHealthCheck contextHealthCheck = context.getRegistry().lookupByNameAndType("context", ContextHealthCheck.class); + assertNotNull(contextHealthCheck); + } + + @Test + public void routesHealthCheckNotNull() { + RoutesHealthCheckRepository routesRepository = context.getRegistry().lookupByNameAndType("routes", + RoutesHealthCheckRepository.class); + assertNotNull(routesRepository); + } + + @Test + public void consumersHealthCheckNotNull() { + ConsumersHealthCheckRepository consumersRepository = context.getRegistry().lookupByNameAndType("consumers", + ConsumersHealthCheckRepository.class); + assertNotNull(consumersRepository); + } +} diff --git a/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicrometerMetricsConfigDefaultsTest.java b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicrometerMetricsConfigDefaultsTest.java new file mode 100644 index 000000000000..048ea8110bad --- /dev/null +++ b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/MicrometerMetricsConfigDefaultsTest.java @@ -0,0 +1,111 @@ +/* + * 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.quarkus.component.observabilityservices.deployment; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.test.QuarkusUnitTest; +import jakarta.inject.Inject; +import org.apache.camel.CamelContext; +import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier; +import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy; +import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier; +import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy; +import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyConfiguration; +import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory; +import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyNamingStrategy; +import org.apache.camel.component.micrometer.spi.InstrumentedThreadPoolFactory; +import org.apache.camel.impl.engine.DefaultMessageHistoryFactory; +import org.apache.camel.spi.EventNotifier; +import org.apache.camel.spi.MessageHistoryFactory; +import org.apache.camel.spi.RoutePolicyFactory; +import org.apache.camel.spi.ThreadPoolFactory; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MicrometerMetricsConfigDefaultsTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + CamelContext context; + + @Test + public void testMicrometerMetricsConfiguration() { + List routePolicyFactories = context.getRoutePolicyFactories(); + assertEquals(1, routePolicyFactories.size()); + RoutePolicyFactory routePolicyFactory = routePolicyFactories.get(0); + assertInstanceOf(MicrometerRoutePolicyFactory.class, routePolicyFactory); + MicrometerRoutePolicyFactory micrometerRoutePolicyFactory = (MicrometerRoutePolicyFactory) routePolicyFactory; + assertEquals(MicrometerRoutePolicyNamingStrategy.DEFAULT, micrometerRoutePolicyFactory.getNamingStrategy()); + + MicrometerRoutePolicyConfiguration policyConfiguration = micrometerRoutePolicyFactory.getPolicyConfiguration(); + assertTrue(policyConfiguration.isContextEnabled()); + assertTrue(policyConfiguration.isRouteEnabled()); + assertNull(policyConfiguration.getExcludePattern()); + + MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory(); + assertNotNull(messageHistoryFactory); + assertInstanceOf(DefaultMessageHistoryFactory.class, messageHistoryFactory); + + List eventNotifiers = context.getManagementStrategy() + .getEventNotifiers() + .stream() + .filter(eventNotifier -> !eventNotifier.getClass().getName().contains("BaseMainSupport")) + .toList(); + assertEquals(3, eventNotifiers.size()); + + Optional optionalExchangeEventNotifier = context.getManagementStrategy() + .getEventNotifiers() + .stream() + .filter(eventNotifier -> eventNotifier.getClass().equals(MicrometerExchangeEventNotifier.class)) + .findFirst(); + assertTrue(optionalExchangeEventNotifier.isPresent()); + + MicrometerExchangeEventNotifier micrometerExchangeEventNotifier = (MicrometerExchangeEventNotifier) optionalExchangeEventNotifier + .get(); + assertEquals(MicrometerExchangeEventNotifierNamingStrategy.DEFAULT, + micrometerExchangeEventNotifier.getNamingStrategy()); + + Optional optionalRouteEventNotifier = context.getManagementStrategy() + .getEventNotifiers() + .stream() + .filter(eventNotifier -> eventNotifier.getClass().equals(MicrometerRouteEventNotifier.class)) + .findFirst(); + assertTrue(optionalRouteEventNotifier.isPresent()); + + MicrometerRouteEventNotifier micrometerRouteEventNotifier = (MicrometerRouteEventNotifier) optionalRouteEventNotifier + .get(); + assertEquals(MicrometerRouteEventNotifierNamingStrategy.DEFAULT, micrometerRouteEventNotifier.getNamingStrategy()); + + ThreadPoolFactory threadPoolFactory = context.getExecutorServiceManager().getThreadPoolFactory(); + assertNotNull(threadPoolFactory); + assertFalse(threadPoolFactory instanceof InstrumentedThreadPoolFactory); + } +} diff --git a/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/OpenTelemetryEnabledTest.java b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/OpenTelemetryEnabledTest.java new file mode 100644 index 000000000000..b4c3f0106249 --- /dev/null +++ b/extensions/observability-services/deployment/src/test/java/org/apache/camel/quarkus/component/observabilityservices/deployment/OpenTelemetryEnabledTest.java @@ -0,0 +1,62 @@ +/* + * 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.quarkus.component.observabilityservices.deployment; + +import java.util.Set; + +import io.quarkus.test.QuarkusUnitTest; +import jakarta.inject.Inject; +import org.apache.camel.CamelContext; +import org.apache.camel.opentelemetry.CamelQuarkusOpenTelemetryTracer; +import org.apache.camel.opentelemetry.OpenTelemetryTracer; +import org.apache.camel.opentelemetry.OpenTelemetryTracingStrategy; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class OpenTelemetryEnabledTest { + + private static final String EXCLUDE_PATTERNS = "platform-http:*,platform-http:/prefix/.*"; + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .overrideConfigKey("quarkus.otel.sdk.disabled", "false") + .overrideConfigKey("quarkus.camel.opentelemetry.encoding", "true") + .overrideConfigKey("quarkus.camel.opentelemetry.exclude-patterns", EXCLUDE_PATTERNS) + .overrideConfigKey("quarkus.camel.opentelemetry.trace-processors", "true") + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + CamelContext context; + + @Test + public void camelOpenTelemetryTracerRegistryBeanNotNull() { + Set tracers = context.getRegistry().findByType(OpenTelemetryTracer.class); + assertEquals(1, tracers.size()); + + OpenTelemetryTracer tracer = tracers.iterator().next(); + assertInstanceOf(CamelQuarkusOpenTelemetryTracer.class, tracer); + assertInstanceOf(OpenTelemetryTracingStrategy.class, tracer.getTracingStrategy()); + assertTrue(tracer.isEncoding()); + assertEquals(EXCLUDE_PATTERNS, tracer.getExcludePatterns()); + } +} diff --git a/extensions/observability-services/runtime/src/main/doc/usage.adoc b/extensions/observability-services/runtime/src/main/doc/usage.adoc index 02920f472773..2718ae7d0e0f 100644 --- a/extensions/observability-services/runtime/src/main/doc/usage.adoc +++ b/extensions/observability-services/runtime/src/main/doc/usage.adoc @@ -1,7 +1,5 @@ This extension is used to provide a set of opinionated components and configuration which simplify operations such as observability on cloud environments. Although the component is mainly targeted for cloud, it can be used in any other environment, giving to the Camel application the capability to expose a set of observability features by default. -== Usage - All you need to do is to add the dependency to the classpath. There's no need to add any further configuration. Each individual component will be configured using each own default settings except the endpoint which will be exposed in */observe/* by default. If you need to customize each of the different components provided within this service, then, you can specify in the *application.properties* each of the configuration as it would be done normally when you provide the individual component. @@ -10,10 +8,11 @@ If you need to customize each of the different components provided within this s The presence of this dependency will provide the following extensions: -* Camel Microprofile Health Quarkus extension -* Camel Management Quarkus extension -* Camel Micrometer Prometheus Quarkus extension -* Camel Opentelemetry Quarkus extension +* Camel Quarkus Microprofile +* Camel Quarkus Management +* Camel Quarkus Micrometer +* Camel Quarkus OpenTelemetry +* Quarkus Micrometer Registry Prometheus === List of known endpoints diff --git a/extensions/pom.xml b/extensions/pom.xml index eee89bd9c27b..451136b5533a 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -191,6 +191,7 @@ netty netty-http nitrite + observability-services oaipmh ognl olingo4 @@ -264,8 +265,6 @@ zendesk zip-deflater zipfile - - observability-services diff --git a/integration-tests/observability-services/pom.xml b/integration-tests/observability-services/pom.xml new file mode 100644 index 000000000000..875454c9c0e1 --- /dev/null +++ b/integration-tests/observability-services/pom.xml @@ -0,0 +1,149 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-build-parent-it + 3.18.0-SNAPSHOT + ../../poms/build-parent-it/pom.xml + + + camel-quarkus-integration-test-observability-services + Camel Quarkus :: Integration Tests :: Observability Services + Integration tests for Camel Quarkus Observability Services extension + + + + org.apache.camel.quarkus + camel-quarkus-direct + + + org.apache.camel.quarkus + camel-quarkus-log + + + org.apache.camel.quarkus + camel-quarkus-observability-services + + + io.quarkus + quarkus-resteasy + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + org.awaitility + awaitility + test + + + + + + native + + + native + + + + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + virtualDependencies + + + !noVirtualDependencies + + + + + + org.apache.camel.quarkus + camel-quarkus-direct-deployment + ${project.version} + pom + test + + + * + * + + + + + org.apache.camel.quarkus + camel-quarkus-log-deployment + ${project.version} + pom + test + + + * + * + + + + + org.apache.camel.quarkus + camel-quarkus-microprofile-health-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + diff --git a/integration-tests/observability-services/src/main/java/org/apache/camel/quarkus/component/observabilityservices/it/health/ObservabilityServicesHealthRouteBuilder.java b/integration-tests/observability-services/src/main/java/org/apache/camel/quarkus/component/observabilityservices/it/health/ObservabilityServicesHealthRouteBuilder.java new file mode 100644 index 000000000000..0156316ab388 --- /dev/null +++ b/integration-tests/observability-services/src/main/java/org/apache/camel/quarkus/component/observabilityservices/it/health/ObservabilityServicesHealthRouteBuilder.java @@ -0,0 +1,40 @@ +/* + * 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.quarkus.component.observabilityservices.it.health; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.SupervisingRouteController; + +public class ObservabilityServicesHealthRouteBuilder extends RouteBuilder { + @Override + public void configure() { + from("direct:start").routeId("healthyRoute") + .setBody(constant("Hello Camel Quarkus")); + + from("direct:disabled").routeId("disabledHealthRoute") + .log("This route will not show up in health checks as it is disabled in application.properties"); + + if (getContext().getRouteController() instanceof SupervisingRouteController) { + from("direct:supervising").routeId("supervisingRoute") + .to("log:end"); + + // Force a failure for SupervisingRouteController to try and recover (duplicate consumer on the same endpoint) + from("direct:supervising?timeout=100").routeId("brokenRoute") + .to("log:end"); + } + } +} diff --git a/integration-tests/observability-services/src/main/resources/application.properties b/integration-tests/observability-services/src/main/resources/application.properties new file mode 100644 index 000000000000..526e9a9a8d29 --- /dev/null +++ b/integration-tests/observability-services/src/main/resources/application.properties @@ -0,0 +1,24 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# +# Camel +# +camel.context.name = quarkus-camel-example + +# Prevent unwanted routes appearing in the health check output +camel.health.exclude-pattern = disabledHealthRoute diff --git a/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesDefaultTest.java b/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesDefaultTest.java new file mode 100644 index 000000000000..cd1589aefc25 --- /dev/null +++ b/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesDefaultTest.java @@ -0,0 +1,70 @@ +/* + * 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.quarkus.component.observabilityservices.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@QuarkusTest +class ObservabilityServicesDefaultTest { + + @Test + public void testHealthUpStatus() { + RestAssured.when().get("/observe/health").then() + .contentType(ContentType.JSON) + .header("Content-Type", containsString("charset=UTF-8")) + .body("status", is("UP"), + "checks.status.findAll().unique()", contains("UP"), + "checks.find { it.name == 'camel-routes' }", notNullValue(), + "checks.find { it.name == 'camel-consumers' }", notNullValue(), + "checks.find { it.name == 'context' }", notNullValue(), + "checks.find { it.name == 'context' }.data.'context.name'", notNullValue()); + } + + @Test + public void testLivenessUpStatus() { + RestAssured.when().get("/observe/health/live").then() + .contentType(ContentType.JSON) + .header("Content-Type", containsString("charset=UTF-8")) + .body("status", is("UP"), + "checks.status.findAll().unique()", contains("UP")); + } + + @Test + public void testReadinessUpStatus() { + RestAssured.when().get("/observe/health/ready").then() + .contentType(ContentType.JSON) + .header("Content-Type", containsString("charset=UTF-8")) + .body("status", is("UP"), + "checks.status.findAll().unique()", contains("UP")); + } + + @Test + public void testMetricsStatus() { + RestAssured.when().get("/observe/metrics").then() + .header("Content-Type", containsString("application/openmetrics-text")) + .statusCode(HttpStatus.SC_OK); + } +} diff --git a/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesIT.java b/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesIT.java new file mode 100644 index 000000000000..c1a786b92526 --- /dev/null +++ b/integration-tests/observability-services/src/test/java/org/apache/camel/quarkus/component/observabilityservices/it/ObservabilityServicesIT.java @@ -0,0 +1,24 @@ +/* + * 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.quarkus.component.observabilityservices.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class ObservabilityServicesIT extends ObservabilityServicesDefaultTest { + +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index d8fbb10003d0..c8e59d05b53e 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -170,6 +170,7 @@ nats netty nitrite + observability-services oaipmh ognl olingo4