CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a336ee9c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a336ee9c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a336ee9c Branch: refs/heads/master Commit: a336ee9cc39f22fccfeca27f6219672ffe564a95 Parents: 3a4087c Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Mar 29 09:18:55 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Mar 29 14:41:54 2016 +0200 ---------------------------------------------------------------------- components/camel-zipkin/pom.xml | 23 ++++++ .../zipkin/ZipkinClientRequestAdapter.java | 2 +- .../zipkin/ZipkinClientResponseAdaptor.java | 2 +- .../camel/zipkin/ZipkinEventNotifier.java | 20 ++++- .../org/apache/camel/zipkin/ZipkinHelper.java | 3 + .../zipkin/ZipkinLoggingSpanCollector.java | 5 +- .../zipkin/ZipkinServerRequestAdapter.java | 2 +- .../zipkin/ZipkinServerResponseAdapter.java | 2 +- .../camel/zipkin/ZipkinRouteConcurrentTest.java | 72 ++++++++++++++++++ .../camel/zipkin/ZipkinRouteScribeTest.java | 73 ------------------ .../apache/camel/zipkin/ZipkinRouteTest.java | 72 ------------------ .../camel/zipkin/ZipkinSimpleRouteTest.java | 66 ++++++++++++++++ .../scribe/ZipkinRouteConcurrentScribe.java | 79 ++++++++++++++++++++ .../zipkin/scribe/ZipkinSimpleRouteScribe.java | 73 ++++++++++++++++++ .../src/test/resources/log4j.properties | 4 +- 15 files changed, 343 insertions(+), 155 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/pom.xml b/components/camel-zipkin/pom.xml index 567626a..bd82334 100644 --- a/components/camel-zipkin/pom.xml +++ b/components/camel-zipkin/pom.xml @@ -67,4 +67,27 @@ </dependencies> + <profiles> + <profile> + <id>scribe-test</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <childDelegation>false</childDelegation> + <useFile>true</useFile> + <forkCount>1</forkCount> + <reuseForks>true</reuseForks> + <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds> + <includes> + <include>**/*ScribeTest.java</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + </project> http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java index 5254578..08e1679 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java @@ -65,6 +65,6 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter { @Override public Collection<KeyValueAnnotation> requestAnnotations() { String msgId = exchange.getIn().getMessageId(); - return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId)); + return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId)); } } http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java index daddeff..296c021 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java @@ -37,7 +37,7 @@ public class ZipkinClientResponseAdaptor implements ClientResponseAdapter { @Override public Collection<KeyValueAnnotation> responseAnnotations() { if (exchange.getException() != null) { - return Collections.singletonList(KeyValueAnnotation.create("CamelZipkinFailed", exchange.getException().getMessage())); + return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage())); } else { return Collections.emptyList(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java index 30b8ca1..97c57c2 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java @@ -25,6 +25,7 @@ import com.github.kristofa.brave.ClientSpanThreadBinder; import com.github.kristofa.brave.Sampler; import com.github.kristofa.brave.SpanCollector; import com.twitter.zipkin.gen.Span; +import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.management.event.ExchangeCompletedEvent; @@ -37,6 +38,21 @@ import org.apache.camel.util.EndpointHelper; import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression; +/** + * To use zipkin with Camel then setup this {@link org.apache.camel.spi.EventNotifier} in your Camel application. + * <p/> + * Events (span) are captured for incoming and outgoing messages being sent to/from Camel. + * This means you need to configure which which Camel endpoints that maps to zipkin service names. + * The mapping can be configured using + * <ul> + * <li>route id - A Camel route id</li> + * <li>endpoint url - A Camel endpoint url</li> + * </ul> + * For both kinds you can use wildcards and regular expressions to match, which is using the rules from + * {@link EndpointHelper#matchPattern(String, String)} and {@link EndpointHelper#matchEndpoint(CamelContext, String, String)} + * <p/> + * At least one mapping must be configured, you can use <tt>*</tt> to match all incoming and outgoing messages. + */ public class ZipkinEventNotifier extends EventNotifierSupport { private float rate = 1.0f; @@ -79,8 +95,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport { this.serviceMappings = serviceMappings; } - public void addServiceMapping(String routeId, String serviceName) { - serviceMappings.put(routeId, serviceName); + public void addServiceMapping(String pattern, String serviceName) { + serviceMappings.put(pattern, serviceName); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java index d5c8c57..2fe33e4 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java @@ -19,6 +19,9 @@ package org.apache.camel.zipkin; import com.github.kristofa.brave.IdConversion; import com.github.kristofa.brave.SpanId; +/** + * Helper class. + */ public final class ZipkinHelper { private ZipkinHelper() { http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java index 71d551a..f77156c 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java @@ -16,8 +16,6 @@ */ package org.apache.camel.zipkin; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.LinkedHashSet; import java.util.Set; @@ -28,6 +26,9 @@ import com.twitter.zipkin.gen.Span; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * To collect zipkin span's using a logger. + */ public class ZipkinLoggingSpanCollector implements SpanCollector { private final Set<BinaryAnnotation> defaultAnnotations = new LinkedHashSet<BinaryAnnotation>(); http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java index c6ec850..fa67ddb 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java @@ -63,7 +63,7 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter { @Override public Collection<KeyValueAnnotation> requestAnnotations() { String msgId = exchange.getIn().getMessageId(); - return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId)); + return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId)); } } http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java index 8cb5b67..2ba8594 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java @@ -37,7 +37,7 @@ public class ZipkinServerResponseAdapter implements ServerResponseAdapter { @Override public Collection<KeyValueAnnotation> responseAnnotations() { if (exchange.getException() != null) { - return Collections.singletonList(KeyValueAnnotation.create("failure", exchange.getException().getMessage())); + return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage())); } else { return Collections.emptyList(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java new file mode 100644 index 0000000..6db0a0e --- /dev/null +++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.zipkin; + +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.NotifyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class ZipkinRouteConcurrentTest extends CamelTestSupport { + + private ZipkinEventNotifier zipkin; + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + + zipkin = new ZipkinEventNotifier(); + zipkin.addServiceMapping("seda:foo", "foo"); + zipkin.addServiceMapping("seda:bar", "bar"); + zipkin.setSpanCollector(new ZipkinLoggingSpanCollector()); + context.getManagementStrategy().addEventNotifier(zipkin); + + return context; + } + + @Test + public void testZipkinRoute() throws Exception { + NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create(); + + for (int i = 0; i < 5; i++) { + template.sendBody("seda:foo", "Hello World"); + } + + assertTrue(notify.matches(30, TimeUnit.SECONDS)); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("seda:foo?concurrentConsumers=5").routeId("foo") + .log("routing at ${routeId}") + .delay(simple("${random(1000,2000)}")) + .to("seda:bar"); + + from("seda:bar?concurrentConsumers=5").routeId("bar") + .log("routing at ${routeId}") + .delay(simple("${random(0,500)}")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java deleted file mode 100644 index 94d2ca4..0000000 --- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.zipkin; - -import java.util.concurrent.TimeUnit; - -import com.github.kristofa.brave.scribe.ScribeSpanCollector; -import org.apache.camel.CamelContext; -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.NotifyBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class ZipkinRouteScribeTest extends CamelTestSupport { - - private ZipkinEventNotifier zipkin; - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - - zipkin = new ZipkinEventNotifier(); - zipkin.addServiceMapping("seda:foo", "foo"); - zipkin.addServiceMapping("seda:bar", "bar"); - zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410)); - context.getManagementStrategy().addEventNotifier(zipkin); - - return context; - } - - @Test - public void testZipkinRoute() throws Exception { - NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create(); - - for (int i = 0; i < 5; i++) { - template.sendBody("seda:foo", "Hello World"); - } - - assertTrue(notify.matches(60, TimeUnit.SECONDS)); - } - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("seda:foo").routeId("foo") - .log("routing at ${routeId}") - .delay(simple("${random(1000,2000)}")) - .to("seda:bar"); - - from("seda:bar").routeId("bar") - .log("routing at ${routeId}") - .delay(simple("${random(0,500)}")); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java deleted file mode 100644 index 15a4a41..0000000 --- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.zipkin; - -import java.util.concurrent.TimeUnit; - -import org.apache.camel.CamelContext; -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.NotifyBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class ZipkinRouteTest extends CamelTestSupport { - - private ZipkinEventNotifier zipkin; - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - - zipkin = new ZipkinEventNotifier(); - zipkin.addServiceMapping("seda:foo", "foo"); - zipkin.addServiceMapping("seda:bar", "bar"); - zipkin.setSpanCollector(new ZipkinLoggingSpanCollector()); - context.getManagementStrategy().addEventNotifier(zipkin); - - return context; - } - - @Test - public void testZipkinRoute() throws Exception { - NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create(); - - for (int i = 0; i < 5; i++) { - template.sendBody("seda:foo", "Hello World"); - } - - assertTrue(notify.matches(30, TimeUnit.SECONDS)); - } - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("seda:foo?concurrentConsumers=5").routeId("foo") - .log("routing at ${routeId}") - .delay(simple("${random(1000,2000)}")) - .to("seda:bar"); - - from("seda:bar?concurrentConsumers=5").routeId("bar") - .log("routing at ${routeId}") - .delay(simple("${random(0,500)}")); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java new file mode 100644 index 0000000..0c719cc --- /dev/null +++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java @@ -0,0 +1,66 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.zipkin; + +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.NotifyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class ZipkinSimpleRouteTest extends CamelTestSupport { + + private ZipkinEventNotifier zipkin; + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + + zipkin = new ZipkinEventNotifier(); + zipkin.addServiceMapping("seda:dude", "dude"); + zipkin.setSpanCollector(new ZipkinLoggingSpanCollector()); + context.getManagementStrategy().addEventNotifier(zipkin); + + return context; + } + + @Test + public void testZipkinRoute() throws Exception { + NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create(); + + for (int i = 0; i < 5; i++) { + template.sendBody("seda:dude", "Hello World"); + } + + assertTrue(notify.matches(30, TimeUnit.SECONDS)); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("seda:dude").routeId("dude") + .log("routing at ${routeId}") + .delay(simple("${random(1000,2000)}")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java new file mode 100644 index 0000000..d371547 --- /dev/null +++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java @@ -0,0 +1,79 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.zipkin.scribe; + +import java.util.concurrent.TimeUnit; + +import com.github.kristofa.brave.scribe.ScribeSpanCollector; +import org.apache.camel.CamelContext; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.NotifyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.zipkin.ZipkinEventNotifier; +import org.junit.Test; + +/** + * Integration test requires running Zipkin/Scribe running + * + * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin + */ +public class ZipkinRouteConcurrentScribe extends CamelTestSupport { + + private ZipkinEventNotifier zipkin; + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + + zipkin = new ZipkinEventNotifier(); + zipkin.addServiceMapping("seda:foo", "foo"); + zipkin.addServiceMapping("seda:bar", "bar"); + zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410)); + context.getManagementStrategy().addEventNotifier(zipkin); + + return context; + } + + @Test + public void testZipkinRoute() throws Exception { + NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create(); + + for (int i = 0; i < 5; i++) { + template.sendBody("seda:foo", "Hello World"); + } + + assertTrue(notify.matches(60, TimeUnit.SECONDS)); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("seda:foo").routeId("foo") + .log("routing at ${routeId}") + .delay(simple("${random(1000,2000)}")) + .to("seda:bar"); + + from("seda:bar").routeId("bar") + .log("routing at ${routeId}") + .delay(simple("${random(0,500)}")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java new file mode 100644 index 0000000..3d91927 --- /dev/null +++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java @@ -0,0 +1,73 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.zipkin.scribe; + +import java.util.concurrent.TimeUnit; + +import com.github.kristofa.brave.scribe.ScribeSpanCollector; +import org.apache.camel.CamelContext; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.NotifyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.zipkin.ZipkinEventNotifier; +import org.junit.Test; + +/** + * Integration test requires running Zipkin/Scribe running + * + * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin + */ +public class ZipkinSimpleRouteScribe extends CamelTestSupport { + + private ZipkinEventNotifier zipkin; + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + + zipkin = new ZipkinEventNotifier(); + zipkin.addServiceMapping("seda:dude", "dude"); + zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410)); + context.getManagementStrategy().addEventNotifier(zipkin); + + return context; + } + + @Test + public void testZipkinRoute() throws Exception { + NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create(); + + for (int i = 0; i < 5; i++) { + template.sendBody("seda:dude", "Hello World"); + } + + assertTrue(notify.matches(30, TimeUnit.SECONDS)); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("seda:dude").routeId("dude") + .log("routing at ${routeId}") + .delay(simple("${random(1000,2000)}")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties index 69b028b..5d05c44 100644 --- a/components/camel-zipkin/src/test/resources/log4j.properties +++ b/components/camel-zipkin/src/test/resources/log4j.properties @@ -18,11 +18,11 @@ # # The logging properties used # -log4j.rootLogger=INFO, out +log4j.rootLogger=INFO, file #log4j.logger.org.apache.camel=DEBUG #log4j.logger.org.apache.camel.zipkin=DEBUG -log4j.logger.com.github.kristofa.brave=DEBUG +#log4j.logger.com.github.kristofa.brave=DEBUG # CONSOLE appender not used by default log4j.appender.out=org.apache.log4j.ConsoleAppender