This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push: new 87d8b10 Add an opentracing capability #289 new c9d6212 Merge pull request #353 from lburgazzoli/github-289 87d8b10 is described below commit 87d8b10a0659e116efb5c08e48ab27e791403f0c Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Thu Jun 4 12:00:18 2020 +0200 Add an opentracing capability #289 --- camel-k-main/camel-k-runtime-tracing/pom.xml | 99 ++++++++++++++++++++++ .../camel/k/tracing/TracingContextCustomizer.java | 57 +++++++++++++ .../k/tracing/TracingContextCustomizerTest.java | 52 ++++++++++++ .../src/test/resources/log4j2-test.xml} | 30 +++---- camel-k-main/pom.xml | 1 + camel-k-runtime-bom/pom.xml | 5 ++ .../org/apache/camel/k/support/RuntimeSupport.java | 5 ++ pom.xml | 6 ++ .../src/it/generate-catalog-main/verify.groovy | 9 +- .../src/it/generate-catalog-quarkus/verify.groovy | 9 +- .../camel/k/tooling/maven/GenerateCatalogMojo.java | 32 +++++-- 11 files changed, 273 insertions(+), 32 deletions(-) diff --git a/camel-k-main/camel-k-runtime-tracing/pom.xml b/camel-k-main/camel-k-runtime-tracing/pom.xml new file mode 100644 index 0000000..34b21c8 --- /dev/null +++ b/camel-k-main/camel-k-runtime-tracing/pom.xml @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-main</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-k-runtime-tracing</artifactId> + + <dependencies> + + <!-- ****************************** --> + <!-- --> + <!-- RUNTIME --> + <!-- --> + <!-- ****************************** --> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core-engine</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-opentracing</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-runtime-core</artifactId> + </dependency> + + <dependency> + <groupId>io.jaegertracing</groupId> + <artifactId>jaeger-client</artifactId> + <version>${jaeger.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-apt</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-annotations</artifactId> + <scope>provided</scope> + </dependency> + + <!-- ****************************** --> + <!-- --> + <!-- TESTS --> + <!-- --> + <!-- ****************************** --> + + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-test</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.jboss.jandex</groupId> + <artifactId>jandex-maven-plugin</artifactId> + <executions> + <execution> + <id>make-index</id> + <goals> + <goal>jandex</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/camel-k-main/camel-k-runtime-tracing/src/main/java/org/apache/camel/k/tracing/TracingContextCustomizer.java b/camel-k-main/camel-k-runtime-tracing/src/main/java/org/apache/camel/k/tracing/TracingContextCustomizer.java new file mode 100644 index 0000000..4dbe627 --- /dev/null +++ b/camel-k-main/camel-k-runtime-tracing/src/main/java/org/apache/camel/k/tracing/TracingContextCustomizer.java @@ -0,0 +1,57 @@ +/* + * 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.k.tracing; + +import io.jaegertracing.Configuration; +import org.apache.camel.CamelContext; +import org.apache.camel.k.ContextCustomizer; +import org.apache.camel.k.annotation.Customizer; +import org.apache.camel.opentracing.OpenTracingTracer; + +@Customizer("tracing") +public class TracingContextCustomizer implements ContextCustomizer { + private Configuration.ReporterConfiguration reporter = new Configuration.ReporterConfiguration(); + private Configuration.SamplerConfiguration sampler = new Configuration.SamplerConfiguration(); + + public Configuration.ReporterConfiguration getReporter() { + return reporter; + } + + public void setReporter(Configuration.ReporterConfiguration reporter) { + this.reporter = reporter; + } + + public Configuration.SamplerConfiguration getSampler() { + return sampler; + } + + public void setSampler(Configuration.SamplerConfiguration sampler) { + this.sampler = sampler; + } + + @Override + public void apply(CamelContext camelContext) { + OpenTracingTracer openTracingTracer = new OpenTracingTracer(); + openTracingTracer.setTracer(new Configuration(camelContext.getName()) + .withReporter(reporter) + .withSampler(sampler) + .getTracer() + ); + + openTracingTracer.init(camelContext); + } +} diff --git a/camel-k-main/camel-k-runtime-tracing/src/test/java/org/apache/camel/k/tracing/TracingContextCustomizerTest.java b/camel-k-main/camel-k-runtime-tracing/src/test/java/org/apache/camel/k/tracing/TracingContextCustomizerTest.java new file mode 100644 index 0000000..a67f6ff --- /dev/null +++ b/camel-k-main/camel-k-runtime-tracing/src/test/java/org/apache/camel/k/tracing/TracingContextCustomizerTest.java @@ -0,0 +1,52 @@ +/* + * 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.k.tracing; + +import java.util.Random; + +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.k.Runtime; +import org.apache.camel.k.support.RuntimeSupport; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TracingContextCustomizerTest { + @Test + public void testTracingConfiguration() { + final String endpoint = "http://jaeger:14268/api/traces"; + final String type = "const"; + final int param = new Random().nextInt(10); + + Runtime runtime = Runtime.on(new DefaultCamelContext()); + runtime.setProperties( + "camel.k.customizer.tracing.enabled", "true", + "camel.k.customizer.tracing.reporter.sender.endpoint", endpoint, + "camel.k.customizer.tracing.sampler.type", type, + "camel.k.customizer.tracing.sampler.param", Integer.toString(param)); + + assertThat(RuntimeSupport.configureContextCustomizers(runtime)) + .hasOnlyOneElementSatisfying(customizer -> { + assertThat(customizer) + .isInstanceOfSatisfying(TracingContextCustomizer.class, tracing -> { + assertThat(tracing.getReporter().getSenderConfiguration().getEndpoint()).isEqualTo(endpoint); + assertThat(tracing.getSampler().getType()).isEqualTo(type); + assertThat(tracing.getSampler().getParam().intValue()).isEqualTo(param); + }); + }); + } +} diff --git a/camel-k-main/pom.xml b/camel-k-main/camel-k-runtime-tracing/src/test/resources/log4j2-test.xml similarity index 57% copy from camel-k-main/pom.xml copy to camel-k-main/camel-k-runtime-tracing/src/test/resources/log4j2-test.xml index bd0184e..5023b85 100644 --- a/camel-k-main/pom.xml +++ b/camel-k-main/camel-k-runtime-tracing/src/test/resources/log4j2-test.xml @@ -17,20 +17,20 @@ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-parent</artifactId> - <version>1.3.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <packaging>pom</packaging> +<Configuration status="INFO"> + <Appenders> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c - %msg%n"/> + </Console> + <Null name="NONE"/> + </Appenders> - <artifactId>camel-k-main</artifactId> + <Loggers> + <Logger name="io.vertx" level="INFO"/> + <Root level="INFO"> + <!-- <AppenderRef ref="STDOUT"/> --> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> - <modules> - <module>camel-k-runtime-main</module> - <module>camel-k-runtime-health</module> - </modules> - -</project> +</Configuration> \ No newline at end of file diff --git a/camel-k-main/pom.xml b/camel-k-main/pom.xml index bd0184e..a031bcd 100644 --- a/camel-k-main/pom.xml +++ b/camel-k-main/pom.xml @@ -31,6 +31,7 @@ <modules> <module>camel-k-runtime-main</module> <module>camel-k-runtime-health</module> + <module>camel-k-runtime-tracing</module> </modules> </project> diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml index c3c4dd5..a8a99d9 100644 --- a/camel-k-runtime-bom/pom.xml +++ b/camel-k-runtime-bom/pom.xml @@ -151,6 +151,11 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-runtime-tracing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> <artifactId>camel-k-runtime-http</artifactId> <version>${project.version}</version> </dependency> diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java index 369dbff..f34134a 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java @@ -37,6 +37,7 @@ import org.apache.camel.k.Constants; import org.apache.camel.k.ContextCustomizer; import org.apache.camel.k.Source; import org.apache.camel.k.SourceLoader; +import org.apache.camel.spi.HasCamelContext; import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +55,10 @@ public final class RuntimeSupport { // // ********************************* + public static List<ContextCustomizer> configureContextCustomizers(HasCamelContext hasCamelContext) { + return configureContextCustomizers(hasCamelContext.getCamelContext()); + } + public static List<ContextCustomizer> configureContextCustomizers(CamelContext context) { List<ContextCustomizer> appliedCustomizers = new ArrayList<>(); Map<String, ContextCustomizer> customizers = lookupCustomizers(context); diff --git a/pom.xml b/pom.xml index e805885..579f8c8 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,7 @@ <javapoet.version>1.11.1</javapoet.version> <rest-assured.version>4.3.0</rest-assured.version> <hamcrest.version>2.2</hamcrest.version> + <jaeger.version>1.2.0</jaeger.version> <gmavenplus-plugin.version>1.9.0</gmavenplus-plugin.version> <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> @@ -355,6 +356,11 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-runtime-tracing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> <artifactId>camel-k-runtime-http</artifactId> <version>${project.version}</version> </dependency> diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy index 73b6d01..442d980 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy @@ -28,15 +28,14 @@ new File(basedir, "catalog.yaml").withReader { assert catalog.spec.runtime.capabilities['cron'].dependencies[0].artifactId == 'camel-k-runtime-cron' assert catalog.spec.runtime.capabilities['health'].dependencies[0].groupId == 'org.apache.camel.k' assert catalog.spec.runtime.capabilities['health'].dependencies[0].artifactId == 'camel-k-runtime-health' - assert catalog.spec.runtime.capabilities['rest'].dependencies[0].groupId == 'org.apache.camel' - assert catalog.spec.runtime.capabilities['rest'].dependencies[0].artifactId == 'camel-rest' - assert catalog.spec.runtime.capabilities['rest'].dependencies[1].groupId == 'org.apache.camel.k' - assert catalog.spec.runtime.capabilities['rest'].dependencies[1].artifactId == 'camel-k-runtime-http' + assert catalog.spec.runtime.capabilities['rest'].dependencies.any { it.groupId == 'org.apache.camel' && it.artifactId == 'camel-rest' } + assert catalog.spec.runtime.capabilities['rest'].dependencies.any { it.groupId == 'org.apache.camel.k' && it.artifactId == 'camel-k-runtime-http' } assert catalog.spec.runtime.capabilities['platform-http'].dependencies[0].groupId == 'org.apache.camel.k' assert catalog.spec.runtime.capabilities['platform-http'].dependencies[0].artifactId == 'camel-k-runtime-http' assert catalog.spec.runtime.capabilities['circuit-breaker'].dependencies[0].groupId == 'org.apache.camel' assert catalog.spec.runtime.capabilities['circuit-breaker'].dependencies[0].artifactId == 'camel-microprofile-fault-tolerance' - + assert catalog.spec.runtime.capabilities['tracing'].dependencies[0].groupId == 'org.apache.camel.k' + assert catalog.spec.runtime.capabilities['tracing'].dependencies[0].artifactId == 'camel-k-runtime-tracing' assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy index 1b271f2..7a80bcc 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy @@ -24,18 +24,19 @@ new File(basedir, "catalog.yaml").withReader { assert catalog.spec.runtime.metadata['quarkus.version'] == quarkusVersion assert catalog.spec.runtime.metadata['camel-quarkus.version'] == camelQuarkusVersion + assert catalog.spec.runtime.capabilities['cron'].dependencies[0].groupId == 'org.apache.camel.k' assert catalog.spec.runtime.capabilities['cron'].dependencies[0].artifactId == 'camel-k-quarkus-cron' assert catalog.spec.runtime.capabilities['health'].dependencies[0].groupId == 'org.apache.camel.quarkus' assert catalog.spec.runtime.capabilities['health'].dependencies[0].artifactId == 'camel-quarkus-microprofile-health' - assert catalog.spec.runtime.capabilities['rest'].dependencies[0].groupId == 'org.apache.camel.quarkus' - assert catalog.spec.runtime.capabilities['rest'].dependencies[0].artifactId == 'camel-quarkus-rest' - assert catalog.spec.runtime.capabilities['rest'].dependencies[1].groupId == 'org.apache.camel.quarkus' - assert catalog.spec.runtime.capabilities['rest'].dependencies[1].artifactId == 'camel-quarkus-platform-http' + assert catalog.spec.runtime.capabilities['rest'].dependencies.any { it.groupId == 'org.apache.camel.quarkus' && it.artifactId == 'camel-quarkus-rest' } + assert catalog.spec.runtime.capabilities['rest'].dependencies.any { it.groupId == 'org.apache.camel.quarkus' && it.artifactId == 'camel-quarkus-platform-http' } assert catalog.spec.runtime.capabilities['platform-http'].dependencies[0].groupId == 'org.apache.camel.quarkus' assert catalog.spec.runtime.capabilities['platform-http'].dependencies[0].artifactId == 'camel-quarkus-platform-http' assert catalog.spec.runtime.capabilities['circuit-breaker'].dependencies[0].groupId == 'org.apache.camel.quarkus' assert catalog.spec.runtime.capabilities['circuit-breaker'].dependencies[0].artifactId == 'camel-quarkus-microprofile-fault-tolerance' + assert catalog.spec.runtime.capabilities['tracing'].dependencies[0].groupId == 'org.apache.camel.quarkus' + assert catalog.spec.runtime.capabilities['tracing'].dependencies[0].artifactId == 'camel-quarkus-opentracing' assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java index 541fb41..7a37ec8 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java @@ -125,13 +125,16 @@ public class GenerateCatalogMojo extends AbstractMojo { runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-main"); runtimeSpec.putCapability( "cron", - CamelCapability.forArtifact("org.apache.camel.k", "camel-k-runtime-cron")); + CamelCapability.forArtifact( + "org.apache.camel.k", "camel-k-runtime-cron")); runtimeSpec.putCapability( "health", - CamelCapability.forArtifact("org.apache.camel.k", "camel-k-runtime-health")); + CamelCapability.forArtifact( + "org.apache.camel.k", "camel-k-runtime-health")); runtimeSpec.putCapability( "platform-http", - CamelCapability.forArtifact("org.apache.camel.k", "camel-k-runtime-http")); + CamelCapability.forArtifact( + "org.apache.camel.k", "camel-k-runtime-http")); runtimeSpec.putCapability( "rest", new CamelCapability.Builder() @@ -140,7 +143,12 @@ public class GenerateCatalogMojo extends AbstractMojo { .build()); runtimeSpec.putCapability( "circuit-breaker", - CamelCapability.forArtifact("org.apache.camel", "camel-microprofile-fault-tolerance")); + CamelCapability.forArtifact( + "org.apache.camel", "camel-microprofile-fault-tolerance")); + runtimeSpec.putCapability( + "tracing", + CamelCapability.forArtifact( + "org.apache.camel.k", "camel-k-runtime-tracing")); break; case "quarkus": catalog.setRuntimeProvider(new QuarkusRuntimeProvider()); @@ -148,13 +156,16 @@ public class GenerateCatalogMojo extends AbstractMojo { runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-quarkus"); runtimeSpec.putCapability( "cron", - CamelCapability.forArtifact("org.apache.camel.k", "camel-k-quarkus-cron")); + CamelCapability.forArtifact( + "org.apache.camel.k", "camel-k-quarkus-cron")); runtimeSpec.putCapability( "health", - CamelCapability.forArtifact("org.apache.camel.quarkus", "camel-quarkus-microprofile-health")); + CamelCapability.forArtifact( + "org.apache.camel.quarkus", "camel-quarkus-microprofile-health")); runtimeSpec.putCapability( "platform-http", - CamelCapability.forArtifact("org.apache.camel.quarkus", "camel-quarkus-platform-http")); + CamelCapability.forArtifact( + "org.apache.camel.quarkus", "camel-quarkus-platform-http")); runtimeSpec.putCapability( "rest", new CamelCapability.Builder() @@ -163,7 +174,12 @@ public class GenerateCatalogMojo extends AbstractMojo { .build()); runtimeSpec.putCapability( "circuit-breaker", - CamelCapability.forArtifact("org.apache.camel.quarkus", "camel-quarkus-microprofile-fault-tolerance")); + CamelCapability.forArtifact( + "org.apache.camel.quarkus", "camel-quarkus-microprofile-fault-tolerance")); + runtimeSpec.putCapability( + "tracing", + CamelCapability.forArtifact( + "org.apache.camel.quarkus", "camel-quarkus-opentracing")); break; default: throw new IllegalArgumentException("catalog.runtime parameter value [" + runtime + "] is not supported!");