From e5408e0c4bb018b6960e79379276e94a3a088dd1 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Tue, 10 Dec 2024 14:50:52 +0100 Subject: [PATCH] feat(extension): onboard Observability Services Closes #6790 --- catalog/pom.xml | 13 ++ .../others/observability-services.yml | 13 ++ docs/modules/ROOT/nav.adoc | 1 + .../extensions/observability-services.adoc | 109 +++++++++++++ .../observability-services/deployment/pom.xml | 99 ++++++++++++ .../ObservabilityServicesProcessor.java | 30 ++++ .../MicroProfileHealthEnabledTest.java | 72 +++++++++ .../MicrometerMetricsConfigDefaultsTest.java | 111 +++++++++++++ .../deployment/OpenTelemetryEnabledTest.java | 62 ++++++++ extensions/observability-services/pom.xml | 39 +++++ .../observability-services/runtime/pom.xml | 117 ++++++++++++++ .../runtime/src/main/doc/usage.adoc | 56 +++++++ .../resources/META-INF/quarkus-extension.yaml | 33 ++++ .../src/main/resources/application.properties | 20 +++ extensions/pom.xml | 1 + .../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 + poms/bom/pom.xml | 15 ++ .../src/main/generated/flattened-full-pom.xml | 15 ++ .../main/generated/flattened-reduced-pom.xml | 10 ++ .../flattened-reduced-verbose-pom.xml | 10 ++ tooling/scripts/test-categories.yaml | 1 + 26 files changed, 1135 insertions(+) create mode 100644 docs/modules/ROOT/examples/others/observability-services.yml create mode 100644 docs/modules/ROOT/pages/reference/extensions/observability-services.adoc create mode 100644 extensions/observability-services/deployment/pom.xml create mode 100644 extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java 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 extensions/observability-services/pom.xml create mode 100644 extensions/observability-services/runtime/pom.xml create mode 100644 extensions/observability-services/runtime/src/main/doc/usage.adoc create mode 100644 extensions/observability-services/runtime/src/main/resources/META-INF/quarkus-extension.yaml create mode 100644 extensions/observability-services/runtime/src/main/resources/application.properties 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/catalog/pom.xml b/catalog/pom.xml index 1444df467725..05f45d1418df 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -2866,6 +2866,19 @@ + + org.apache.camel.quarkus + camel-quarkus-observability-services + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-ognl diff --git a/docs/modules/ROOT/examples/others/observability-services.yml b/docs/modules/ROOT/examples/others/observability-services.yml new file mode 100644 index 000000000000..293a3fd7c877 --- /dev/null +++ b/docs/modules/ROOT/examples/others/observability-services.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-observability-services +cqArtifactIdBase: observability-services +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.18.0 +cqNativeSince: 3.18.0 +cqCamelPartName: observability-services +cqCamelPartTitle: Observability Services +cqCamelPartDescription: Camel Observability Services +cqExtensionPageTitle: Observability Services diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 2cf27cf89382..29b868cc0431 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -227,6 +227,7 @@ *** xref:reference/extensions/nitrite.adoc[Nitrite] *** xref:reference/extensions/oaipmh.adoc[OAI-PMH] *** xref:reference/extensions/ognl.adoc[OGNL] +*** xref:reference/extensions/observability-services.adoc[Observability Services] *** xref:reference/extensions/olingo4.adoc[Olingo4] *** xref:reference/extensions/openapi-java.adoc[OpenAPI Java] *** xref:reference/extensions/opensearch.adoc[OpenSearch] diff --git a/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc b/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc new file mode 100644 index 000000000000..061c73255ce4 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/observability-services.adoc @@ -0,0 +1,109 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-observability-services"] += Observability Services +:linkattrs: +:cq-artifact-id: camel-quarkus-observability-services +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Camel Observability Services +:cq-deprecated: false +:cq-jvm-since: 3.18.0 +:cq-native-since: 3.18.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.18.0## [.badge-key]##Native since##[.badge-supported]##3.18.0## +endif::[] + +Camel Observability Services + +[id="extensions-observability-services-whats-inside"] +== What's inside + +* xref:{cq-camel-components}:others:observability-services.adoc[Observability Services] + +Please refer to the above link for usage and configuration details. + +[id="extensions-observability-services-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-observability-services[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- + + org.apache.camel.quarkus + camel-quarkus-observability-services + +---- +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 new file mode 100644 index 000000000000..308de647f334 --- /dev/null +++ b/extensions/observability-services/deployment/pom.xml @@ -0,0 +1,99 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-observability-services-parent + 3.18.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-observability-services-deployment + Camel Quarkus :: Observability Services :: Deployment + + + + org.apache.camel.quarkus + camel-quarkus-core-deployment + + + org.apache.camel.quarkus + camel-quarkus-observability-services + + + org.apache.camel.quarkus + camel-quarkus-micrometer-deployment + + + io.quarkus + quarkus-micrometer-registry-prometheus-deployment + + + org.apache.camel.quarkus + camel-quarkus-microprofile-health-deployment + + + org.apache.camel.quarkus + camel-quarkus-opentelemetry-deployment + + + org.apache.camel.quarkus + camel-quarkus-management-deployment + + + + io.quarkus + quarkus-junit5-internal + test + + + io.quarkus + quarkus-security-deployment + test + + + io.quarkus + quarkus-vertx-http + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + diff --git a/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java b/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java new file mode 100644 index 000000000000..b599823fd12b --- /dev/null +++ b/extensions/observability-services/deployment/src/main/java/org/apache/camel/quarkus/component/observabilityservices/deployment/ObservabilityServicesProcessor.java @@ -0,0 +1,30 @@ +/* + * 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.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +class ObservabilityServicesProcessor { + + private static final String FEATURE = "camel-observability-services"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } +} 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/pom.xml b/extensions/observability-services/pom.xml new file mode 100644 index 000000000000..01f15c6a603b --- /dev/null +++ b/extensions/observability-services/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-extensions + 3.18.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-observability-services-parent + Camel Quarkus :: Observability Services + pom + + + deployment + runtime + + diff --git a/extensions/observability-services/runtime/pom.xml b/extensions/observability-services/runtime/pom.xml new file mode 100644 index 000000000000..c4d65748b4a5 --- /dev/null +++ b/extensions/observability-services/runtime/pom.xml @@ -0,0 +1,117 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-observability-services-parent + 3.18.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-observability-services + Camel Quarkus :: Observability Services :: Runtime + Camel Observability Services + + + 3.18.0 + 3.18.0 + + + + + org.apache.camel.quarkus + camel-quarkus-core + + + org.apache.camel.quarkus + camel-quarkus-micrometer + + + io.quarkus + quarkus-micrometer-registry-prometheus + + + org.apache.camel.quarkus + camel-quarkus-microprofile-health + + + org.apache.camel.quarkus + camel-quarkus-opentelemetry + + + org.apache.camel.quarkus + camel-quarkus-management + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + + + + full + + + !quickly + + + + + + org.apache.camel.quarkus + camel-quarkus-maven-plugin + + + update-extension-doc-page + + update-extension-doc-page + + process-classes + + + + + + + + diff --git a/extensions/observability-services/runtime/src/main/doc/usage.adoc b/extensions/observability-services/runtime/src/main/doc/usage.adoc new file mode 100644 index 000000000000..2718ae7d0e0f --- /dev/null +++ b/extensions/observability-services/runtime/src/main/doc/usage.adoc @@ -0,0 +1,56 @@ +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. + +== 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 + +=== 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. + +== 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). + +== 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/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/observability-services/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 000000000000..d6b2f1d2193b --- /dev/null +++ b/extensions/observability-services/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,33 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel Observability Services" +description: "Camel Observability Services" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + sponsor: "Apache Software Foundation" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/observability-services.html" + categories: + - "integration" + status: + - "stable" diff --git a/extensions/observability-services/runtime/src/main/resources/application.properties b/extensions/observability-services/runtime/src/main/resources/application.properties new file mode 100644 index 000000000000..37437c7b2cd9 --- /dev/null +++ b/extensions/observability-services/runtime/src/main/resources/application.properties @@ -0,0 +1,20 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +quarkus.micrometer.export.prometheus.path=/observe/metrics +quarkus.smallrye-health.root-path=/observe/health +# Default is disabled: the user must enable it to push traces to the given server +quarkus.otel.sdk.disabled=true \ No newline at end of file diff --git a/extensions/pom.xml b/extensions/pom.xml index a16d2042e831..b5651788e6ac 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -192,6 +192,7 @@ netty-http nitrite oaipmh + observability-services ognl olingo4 openapi-java diff --git a/integration-tests/observability-services/pom.xml b/integration-tests/observability-services/pom.xml new file mode 100644 index 000000000000..2dca8a7ebdc8 --- /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-observability-services-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..9a1fc59c01be 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -171,6 +171,7 @@ netty nitrite oaipmh + observability-services ognl olingo4 openapi-java diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index f3598ed52a54..86a390648b7a 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -2061,6 +2061,11 @@ + + org.apache.camel + camel-observability-services + ${camel.version} + org.apache.camel camel-ognl @@ -5078,6 +5083,16 @@ camel-quarkus-oaipmh-deployment ${camel-quarkus.version} + + org.apache.camel.quarkus + camel-quarkus-observability-services + ${camel-quarkus.version} + + + org.apache.camel.quarkus + camel-quarkus-observability-services-deployment + ${camel-quarkus.version} + org.apache.camel.quarkus camel-quarkus-ognl diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index 5c6712057d42..3717e69fe8f5 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -1997,6 +1997,11 @@ + + org.apache.camel + camel-observability-services + 4.10.0-SNAPSHOT + org.apache.camel camel-ognl @@ -5002,6 +5007,16 @@ camel-quarkus-oaipmh-deployment 3.18.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-observability-services + 3.18.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-observability-services-deployment + 3.18.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-ognl diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index 8765f5797161..bf2ff3a61f4d 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -4997,6 +4997,16 @@ camel-quarkus-oaipmh-deployment 3.18.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-observability-services + 3.18.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-observability-services-deployment + 3.18.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-ognl diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 76de1ed26a9b..67abe93f4302 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -4997,6 +4997,16 @@ camel-quarkus-oaipmh-deployment 3.18.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-observability-services + 3.18.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-observability-services-deployment + 3.18.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-ognl diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 6293e9be7696..eaa756974c51 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -84,6 +84,7 @@ group-04: - mongodb-grouped - mybatis - sjms-artemis-client + - observability-services group-05: - avro - base64