You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zipkin.apache.org by ab...@apache.org on 2019/01/31 10:25:28 UTC
[incubator-zipkin-brave-karaf] 06/43: Add kafka exporter and
improve itest
This is an automated email from the ASF dual-hosted git repository.
abesto pushed a commit to branch jenkinsfile-tweaks
in repository https://gitbox.apache.org/repos/asf/incubator-zipkin-brave-karaf.git
commit 03b5790d8bd566fe261261a6061d0024d541e53d
Author: Christian Schneider <ch...@die-schneider.net>
AuthorDate: Mon Dec 12 16:07:29 2016 +0100
Add kafka exporter and improve itest
---
brave-exporter-kafka08/pom.xml | 83 ++++++++++++++++++++++
.../osgi/exporter/kafka/KafkaReporterExporter.java | 77 ++++++++++++++++++++
brave-features/src/main/resources/features.xml | 3 +-
brave-itests/pom.xml | 24 +++++++
.../java/io/zipkin/brave/itests/BraveTest.java | 51 ++++++++++++-
brave-itests/src/test/resources/exam.properties | 11 +++
brave-itests/src/test/resources/logback.xml | 15 ++++
pom.xml | 6 ++
8 files changed, 267 insertions(+), 3 deletions(-)
diff --git a/brave-exporter-kafka08/pom.xml b/brave-exporter-kafka08/pom.xml
new file mode 100644
index 0000000..8dc9b93
--- /dev/null
+++ b/brave-exporter-kafka08/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2016 The OpenZipkin Authors
+
+ Licensed 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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>io.zipkin.brave.karaf</groupId>
+ <artifactId>brave-karaf-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>brave-exporter-kafka08</artifactId>
+
+ <properties>
+ <main.basedir>${project.basedir}/..</main.basedir>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <version>6.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ <version>6.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.brave</groupId>
+ <artifactId>brave-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.reporter</groupId>
+ <artifactId>zipkin-reporter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.reporter</groupId>
+ <artifactId>zipkin-sender-kafka08</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <version>3.3.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <configuration>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java b/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
new file mode 100644
index 0000000..46dc6a4
--- /dev/null
+++ b/brave-exporter-kafka08/src/main/java/io/zipkin/brave/osgi/exporter/kafka/KafkaReporterExporter.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright 2016 The OpenZipkin Authors
+ *
+ * Licensed 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 io.zipkin.brave.osgi.exporter.kafka;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import zipkin.Span;
+import zipkin.reporter.AsyncReporter;
+import zipkin.reporter.Encoding;
+import zipkin.reporter.Reporter;
+import zipkin.reporter.kafka08.KafkaSender;
+
+@Component //
+( //
+ immediate = true, //
+ name = "io.zipkin.reporter.kafka08", //
+ configurationPolicy = ConfigurationPolicy.REQUIRE
+)
+@Designate(ocd = KafkaReporterExporter.Config.class)
+public class KafkaReporterExporter {
+
+ @SuppressWarnings("rawtypes")
+ private ServiceRegistration<Reporter> reg;
+ private AsyncReporter<Span> reporter;
+
+ @ObjectClassDefinition(name = "Zipkin Reporter Kafka08")
+ @interface Config {
+ String bootstrapServers() default "localhost:9092";
+ Encoding encoding() default Encoding.THRIFT;
+ int messageMaxBytes() default 1000000;
+ String topic() default "zipkin";
+ String overrides();
+ }
+
+ @Activate
+ public void activate(Config config, BundleContext context, Map<String,String> properties) {
+ config.overrides();
+ Map<String, String> overrides = new HashMap<String, String>();
+ KafkaSender sender = KafkaSender.builder() //
+ .bootstrapServers(config.bootstrapServers()) //
+ .encoding(config.encoding()) //
+ .messageMaxBytes(config.messageMaxBytes()) //
+ .overrides(overrides) //
+ .topic(config.topic()) //
+ .build();
+ reporter = AsyncReporter.builder(sender).build();
+ reg = context.registerService(Reporter.class, reporter, new Hashtable<String, String>(properties));
+ }
+
+ @Deactivate
+ public void deactive() {
+ reg.unregister();
+ reporter.close();
+ }
+
+}
diff --git a/brave-features/src/main/resources/features.xml b/brave-features/src/main/resources/features.xml
index d2fe602..16c4c9c 100644
--- a/brave-features/src/main/resources/features.xml
+++ b/brave-features/src/main/resources/features.xml
@@ -27,10 +27,11 @@
<bundle>mvn:io.zipkin.brave.karaf/brave-exporter/${project.version}</bundle>
</feature>
- <feature name="brave-kafka">
+ <feature name="brave-kafka08">
<feature>brave-core</feature>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.kafka-clients/0.8.2.2_1</bundle>
<bundle>mvn:io.zipkin.reporter/zipkin-sender-kafka08/${zipkin.reporter.version}</bundle>
+ <bundle>mvn:io.zipkin.brave.karaf/brave-exporter-kafka08/${project.version}</bundle>
</feature>
<feature name="brave-jaxrs2">
diff --git a/brave-itests/pom.xml b/brave-itests/pom.xml
index 46a39e6..ce934df 100644
--- a/brave-itests/pom.xml
+++ b/brave-itests/pom.xml
@@ -40,6 +40,24 @@
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.zipkin.brave.karaf</groupId>
+ <artifactId>brave-exporter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.brave.karaf</groupId>
+ <artifactId>brave-exporter-kafka08</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.reporter</groupId>
+ <artifactId>zipkin-sender-urlconnection</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.zipkin.reporter</groupId>
+ <artifactId>zipkin-sender-kafka08</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
@@ -56,6 +74,12 @@
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-cm</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-invoker-junit</artifactId>
<version>${pax.exam.version}</version>
<scope>test</scope>
diff --git a/brave-itests/src/test/java/io/zipkin/brave/itests/BraveTest.java b/brave-itests/src/test/java/io/zipkin/brave/itests/BraveTest.java
index abdd14f..1e32ba8 100644
--- a/brave-itests/src/test/java/io/zipkin/brave/itests/BraveTest.java
+++ b/brave-itests/src/test/java/io/zipkin/brave/itests/BraveTest.java
@@ -16,6 +16,7 @@ package io.zipkin.brave.itests;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
@@ -23,8 +24,11 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRunti
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import javax.inject.Inject;
+
import com.github.kristofa.brave.Brave;
import org.junit.Assert;
import org.junit.Test;
@@ -37,14 +41,33 @@ import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import zipkin.Span;
import zipkin.reporter.Reporter;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class BraveTest {
+ private static final String FILTER_KAFKA08 = "(component.name=io.zipkin.reporter.kafka08)";
+
+ private static final String FILTER_URLCONNECT = "(component.name=io.zipkin.reporter.urlconnect)";
+
List<Span> spans = new ArrayList<Span>();
+ @Inject
+ @Filter(FILTER_URLCONNECT)
+ Reporter<Span> reporter;
+
+ @Inject
+ @Filter(FILTER_KAFKA08)
+ Reporter<Span> reporterKafka;
+
+ @Inject
+ BundleContext context;
+
@Configuration
public static Option[] configuration() throws Exception {
MavenArtifactUrlReference karaf = maven().groupId("org.apache.karaf").artifactId("apache-karaf")
@@ -57,12 +80,15 @@ public class BraveTest {
configureConsole().ignoreLocalConsole(), //
logLevel(LogLevel.INFO), //
keepRuntimeFolder(), //
- features(brave, "brave-core")
+ features(brave, "brave-core", "brave-kafka08"),
+ // Create an empty config to trigger creation of component
+ newConfiguration("io.zipkin.reporter.urlconnect").asOption(),
+ newConfiguration("io.zipkin.reporter.kafka08").asOption()
};
}
@Test
- public void shouldHaveBundleContext() {
+ public void inlineBraveSetup() {
Reporter<Span> local = new Reporter<Span>() {
@Override
@@ -75,5 +101,26 @@ public class BraveTest {
brave.localTracer().finishSpan();
Assert.assertThat(1, equalTo(spans.size()));
}
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void checkReporterUrlConnect() throws InvalidSyntaxException {
+ ServiceReference<Reporter> ref = getSingleService(FILTER_URLCONNECT);
+ Assert.assertEquals(10000, ref.getProperty("connectTimeout"));
+ }
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void checkReporterKafka() throws InvalidSyntaxException {
+ ServiceReference<Reporter> ref = getSingleService(FILTER_KAFKA08);
+ Assert.assertEquals("zipkin", ref.getProperty("topic"));
+ }
+
+ @SuppressWarnings("rawtypes")
+ private ServiceReference<Reporter> getSingleService(String filter) throws InvalidSyntaxException {
+ Collection<ServiceReference<Reporter>> refs = context.getServiceReferences(Reporter.class, filter);
+ Assert.assertEquals(1, refs.size());
+ return refs.iterator().next();
+ }
+
}
diff --git a/brave-itests/src/test/resources/exam.properties b/brave-itests/src/test/resources/exam.properties
index 4936b4a..14f97f7 100644
--- a/brave-itests/src/test/resources/exam.properties
+++ b/brave-itests/src/test/resources/exam.properties
@@ -1,2 +1,13 @@
+# Copyright 2016 The OpenZipkin Authors
+#
+# Licensed 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.
pax.exam.logging = none
pax.exam.service.timeout = 5000
diff --git a/brave-itests/src/test/resources/logback.xml b/brave-itests/src/test/resources/logback.xml
index 7f3f081..56da3f3 100644
--- a/brave-itests/src/test/resources/logback.xml
+++ b/brave-itests/src/test/resources/logback.xml
@@ -1,4 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2016 The OpenZipkin Authors
+
+ Licensed 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.
+
+-->
<configuration>
<!-- log to System.out on console -->
diff --git a/pom.xml b/pom.xml
index e032207..ff559c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,7 @@
<module>brave-features</module>
<module>brave-itests</module>
<module>brave-exporter</module>
+ <module>brave-exporter-kafka08</module>
</modules>
<properties>
@@ -109,6 +110,11 @@
<artifactId>zipkin-sender-urlconnection</artifactId>
<version>${zipkin.reporter.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.zipkin.reporter</groupId>
+ <artifactId>zipkin-sender-kafka08</artifactId>
+ <version>${zipkin.reporter.version}</version>
+ </dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>