From 4d87ae198b64b9cc7312800b4867881a3679a33f Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Fri, 9 Dec 2016 17:54:17 +0100 Subject: [PATCH] Add exporter for Brave and Reporter service (#1) --- .gitignore | 1 + brave-exporter/pom.xml | 83 +++ .../brave/osgi/exporter/BraveExporter.java | 66 ++ .../urlconnect/SenderUrlConnectExporter.java | 71 ++ .../src/main/resources/features.xml | 5 +- brave-itests/.classpath | 31 - brave-itests/pom.xml | 1 - .../io/zipkin/brave/itests/BraveTest.java | 2 +- pom.xml | 636 +++++++++--------- 9 files changed, 533 insertions(+), 363 deletions(-) create mode 100644 brave-exporter/pom.xml create mode 100644 brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/BraveExporter.java create mode 100644 brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/urlconnect/SenderUrlConnectExporter.java delete mode 100644 brave-itests/.classpath diff --git a/.gitignore b/.gitignore index 40b20c3..249346c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +.classpath .project .settings target diff --git a/brave-exporter/pom.xml b/brave-exporter/pom.xml new file mode 100644 index 0000000..e1b38b5 --- /dev/null +++ b/brave-exporter/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + io.zipkin.brave.karaf + brave-karaf-parent + 1.0.0-SNAPSHOT + + + brave-exporter + + + ${project.basedir}/.. + + + + + org.osgi + osgi.core + 6.0.0 + + + org.osgi + osgi.cmpn + 6.0.0 + + + io.zipkin.brave + brave-core + + + io.zipkin.reporter + zipkin-reporter + + + io.zipkin.reporter + zipkin-sender-urlconnection + + + + + + + biz.aQute.bnd + bnd-maven-plugin + 3.3.0 + + + + bnd-process + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + \ No newline at end of file diff --git a/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/BraveExporter.java b/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/BraveExporter.java new file mode 100644 index 0000000..04b9536 --- /dev/null +++ b/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/BraveExporter.java @@ -0,0 +1,66 @@ +/** + * 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; + +import java.util.Hashtable; +import java.util.Map; + +import com.github.kristofa.brave.Brave; +import com.github.kristofa.brave.Sampler; +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.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import zipkin.Span; +import zipkin.reporter.Reporter; + +@Component // +( // + immediate = true, // + name = "io.zipkin.brave" // +) +@Designate(ocd = BraveExporter.Config.class) +public class BraveExporter { + @Reference + Reporter reporter; + + private ServiceRegistration reg; + + @ObjectClassDefinition(name = "Brave") + @interface Config { + String name() default "default"; + boolean traceId128Bit() default false; + float rate() default 1; + } + + @Activate + public void activate(Config config, BundleContext context, Map properties) { + Brave brave = new Brave.Builder(config.name()) + .reporter(reporter) // + .traceId128Bit(config.traceId128Bit()) // + .traceSampler(Sampler.create(config.rate())) + .build(); + reg = context.registerService(Brave.class, brave, new Hashtable(properties)); + } + + @Deactivate + public void deactive() { + reg.unregister(); + } + +} diff --git a/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/urlconnect/SenderUrlConnectExporter.java b/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/urlconnect/SenderUrlConnectExporter.java new file mode 100644 index 0000000..94f85b9 --- /dev/null +++ b/brave-exporter/src/main/java/io/zipkin/brave/osgi/exporter/urlconnect/SenderUrlConnectExporter.java @@ -0,0 +1,71 @@ +/** + * 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.urlconnect; + +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.Reporter; +import zipkin.reporter.urlconnection.URLConnectionSender; + +@Component // +( // + immediate = true, // + name = "io.zipkin.reporter.urlconnect", // + configurationPolicy = ConfigurationPolicy.REQUIRE +) +@Designate(ocd = SenderUrlConnectExporter.Config.class) +public class SenderUrlConnectExporter { + + @SuppressWarnings("rawtypes") + private ServiceRegistration reg; + private AsyncReporter reporter; + + @ObjectClassDefinition(name = "Zipkin Reporter URLConnect") + @interface Config { + String endpoint() default "http://localhost:9411/api/v1/spans"; + boolean compressionEnabled() default true; + int connectTimeout() default 10 * 1000; + int messageMaxBytes() default 5 * 1024 * 1024; + } + + @Activate + public void activate(Config config, BundleContext context, Map properties) { + URLConnectionSender sender = URLConnectionSender.builder() + .endpoint(config.endpoint()) // + .compressionEnabled(config.compressionEnabled()) // + .connectTimeout(config.connectTimeout()) + .messageMaxBytes(config.messageMaxBytes()) + .build(); + reporter = AsyncReporter.builder(sender).build(); + reg = context.registerService(Reporter.class, reporter, new Hashtable(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 2b70909..d2fe602 100644 --- a/brave-features/src/main/resources/features.xml +++ b/brave-features/src/main/resources/features.xml @@ -18,13 +18,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> - mvn:org.apache.cxf.karaf/apache-cxf/3.1.8/xml/features - + scr mvn:io.zipkin.java/zipkin/${zipkin.version} mvn:io.zipkin.reporter/zipkin-reporter/${zipkin.reporter.version} mvn:io.zipkin.reporter/zipkin-sender-urlconnection/${zipkin.reporter.version} mvn:io.zipkin.brave/brave-core/${brave.version} + mvn:io.zipkin.brave.karaf/brave-exporter/${project.version} @@ -35,6 +35,7 @@ brave-core + mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr339-api-2.0.1/2.6.0 mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject/1_2 mvn:io.zipkin.brave/brave-http/${brave.version} mvn:io.zipkin.brave/brave-jaxrs2/${brave.version} diff --git a/brave-itests/.classpath b/brave-itests/.classpath deleted file mode 100644 index b2acffc..0000000 --- a/brave-itests/.classpath +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/brave-itests/pom.xml b/brave-itests/pom.xml index 2836630..46a39e6 100644 --- a/brave-itests/pom.xml +++ b/brave-itests/pom.xml @@ -39,7 +39,6 @@ io.zipkin.brave brave-core - ${brave.version} 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 898817b..abdd14f 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 @@ -43,7 +43,7 @@ @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) public class BraveTest { - List spans = new ArrayList<>(); + List spans = new ArrayList(); @Configuration public static Option[] configuration() throws Exception { diff --git a/pom.xml b/pom.xml index 89d7f78..e032207 100644 --- a/pom.xml +++ b/pom.xml @@ -14,332 +14,312 @@ the License. --> - - 4.0.0 - - io.zipkin.brave.karaf - brave-karaf-parent - 1.0.0-SNAPSHOT - pom - - - brave-features - brave-itests - - - - UTF-8 - UTF-8 - - - 1.6 - java16 - - ${project.basedir} - - 2.11 - - 3.16.0 - 1.16.0 - 0.6.7 - - 1.7.21 - - - Brave Karaf Parent - Brave Karaf Parent - https://github.com/openzipkin/brave-karaf - 2016 - - - OpenZipkin - http://zipkin.io/ - - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - https://github.com/openzipkin/brave-karaf - scm:git:https://github.com/openzipkin/brave-karaf - scm:git:https://github.com/openzipkin/brave-karaf - 0.0.1 - - - - - - - - bintray - https://api.bintray.com/maven/openzipkin/maven/brave-karaf/;publish=1 - - - jfrog-snapshots - http://oss.jfrog.org/artifactory/oss-snapshot-local - - - - - Github - https://github.com/openzipkin/brave-karaf/issues - - - - - - io.zipkin.java - zipkin - ${zipkin.version} - - - io.zipkin.reporter - zipkin-reporter - ${zipkin.reporter.version} - - - junit - junit - 4.12 - - - org.awaitility - awaitility - 2.0.0 - - - - - - - io.zipkin.java - zipkin - - - - - com.google.auto.value - auto-value - 1.3 - provided - - - - junit - junit - test - - - org.assertj - assertj-core - 3.5.2 - test - - - io.zipkin.java - zipkin - ${zipkin.version} - test-jar - - - ch.qos.logback - logback-classic - 1.1.7 - test - - - - - - - - - - io.takari - maven - 0.3.3 - - - - - - - true - maven-compiler-plugin - 3.5.1 - - - 1.8 - 1.8 - javac-with-errorprone - true - true - - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - 2.8 - - - com.google.errorprone - error_prone_core - 2.0.9 - - - - - - net.orfjackal.retrolambda - retrolambda-maven-plugin - 2.3.0 - - - - process-main - - - ${main.java.version} - false - - - - - - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.15 - - - org.codehaus.mojo.signature - ${main.signature.artifact} - 1.0 - - - - - - check - - - - - - - - maven-install-plugin - 2.5.2 - - true - - - - - com.mycila - license-maven-plugin - ${license-maven-plugin.version} - -
${main.basedir}/src/etc/header.txt
- - .travis.yml - .gitignore - .mvn/** - mvnw* - etc/header.txt - **/.idea/** - LICENSE - **/*.md - src/test/resources/** - src/main/resources/** - - true -
- - - com.mycila - license-maven-plugin-git - ${license-maven-plugin.version} - - - - - - check - - compile - - -
- - - maven-release-plugin - 2.5.3 - - false - release - true - @{project.version} - - - - - io.zipkin.centralsync-maven-plugin - centralsync-maven-plugin - 0.1.0 - - zipkin-aws - - -
-
- - - - release - - - - - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - - maven-javadoc-plugin - 2.10.4 - - false - zipkin.aws.internal,zipkin.aws.internal.* - - - -Xdoclint:none - - - - attach-javadocs - - jar - - package - - - - - - - + + 4.0.0 + + io.zipkin.brave.karaf + brave-karaf-parent + 1.0.0-SNAPSHOT + pom + + + brave-features + brave-itests + brave-exporter + + + + UTF-8 + UTF-8 + + + 1.6 + java16 + + ${project.basedir} + + 2.11 + + 3.16.0 + 1.16.0 + 0.6.9 + + 1.7.21 + + + Brave Karaf Parent + Brave Karaf Parent + https://github.com/openzipkin/brave-karaf + 2016 + + + OpenZipkin + http://zipkin.io/ + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + https://github.com/openzipkin/brave-karaf + scm:git:https://github.com/openzipkin/brave-karaf + scm:git:https://github.com/openzipkin/brave-karaf + 0.0.1 + + + + + + + + bintray + https://api.bintray.com/maven/openzipkin/maven/brave-karaf/;publish=1 + + + jfrog-snapshots + http://oss.jfrog.org/artifactory/oss-snapshot-local + + + + + Github + https://github.com/openzipkin/brave-karaf/issues + + + + + + io.zipkin.java + zipkin + ${zipkin.version} + + + io.zipkin.reporter + zipkin-reporter + ${zipkin.reporter.version} + + + io.zipkin.reporter + zipkin-sender-urlconnection + ${zipkin.reporter.version} + + + + io.zipkin.brave + brave-core + ${brave.version} + + + junit + junit + 4.12 + + + org.awaitility + awaitility + 2.0.0 + + + + + + + io.zipkin.java + zipkin + + + + + com.google.auto.value + auto-value + 1.3 + provided + + + + junit + junit + test + + + org.assertj + assertj-core + 3.5.2 + test + + + io.zipkin.java + zipkin + ${zipkin.version} + test-jar + + + ch.qos.logback + logback-classic + 1.1.7 + test + + + + + + + + + + io.takari + maven + 0.3.3 + + + + + + + true + maven-compiler-plugin + 3.5.1 + + 1.6 + 1.6 + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.15 + + + org.codehaus.mojo.signature + ${main.signature.artifact} + 1.0 + + + + + + check + + + + + + + + maven-install-plugin + 2.5.2 + + true + + + + + com.mycila + license-maven-plugin + ${license-maven-plugin.version} + +
${main.basedir}/src/etc/header.txt
+ + .travis.yml + .gitignore + .mvn/** + mvnw* + etc/header.txt + **/.idea/** + LICENSE + **/*.md + src/test/resources/** + src/main/resources/** + + true +
+ + + com.mycila + license-maven-plugin-git + ${license-maven-plugin.version} + + + + + + check + + compile + + +
+ + + maven-release-plugin + 2.5.3 + + false + release + true + @{project.version} + + + + + io.zipkin.centralsync-maven-plugin + centralsync-maven-plugin + 0.1.0 + + zipkin-aws + + +
+
+ + + + release + + + + + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + + maven-javadoc-plugin + 2.10.4 + + false + zipkin.aws.internal,zipkin.aws.internal.* + + + -Xdoclint:none + + + + attach-javadocs + + jar + + package + + + + + + +