Skip to content

Commit e9bc119

Browse files
authored
[DON'T MERGE] Distributed tracing (#83)
* Initial commit from Ricardo * Refactored app - externalized config - updated springbok - demoed gson dependency * Refactored app, added basic automation, skeleton readme
1 parent 3d1b669 commit e9bc119

18 files changed

+1025
-0
lines changed

Diff for: distributed-tracing/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.idea/
2+
*.iml
3+
target/
4+
.project
5+
.classpath
6+
.factorypath
7+
.settings/**/*.*
8+
.vscode/**/*.*
9+
.settings/**/*.*
10+
11+
!.mvn/wrapper/maven-wrapper.jar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.5";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

Diff for: distributed-tracing/.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

Diff for: distributed-tracing/LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Ricardo Ferreira, Viktor Gamov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: distributed-tracing/Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
export INTERCEPTORSPATH:=tracing-interceptors
4+
export INTERCEPTORS_VERSION:=master-SNAPSHOT
5+
6+
all: clean prep build downloadInterceptors
7+
8+
clean:
9+
rm -fr $(INTERCEPTORSPATH)/*.jar
10+
11+
prep:
12+
if [[ ! -d $(INTERCEPTORSPATH) ]]; then mkdir $(INTERCEPTORSPATH); fi
13+
14+
build:
15+
./mvnw -f app/pom.xml clean install
16+
17+
downloadInterceptors:
18+
cd $(INTERCEPTORSPATH)
19+
./mvnw dependency:get -DremoteRepositories=https://jitpack.io \
20+
-DgroupId=com.github.riferrei \
21+
-DartifactId=kafka-tracing-support \
22+
-Dversion=$(INTERCEPTORS_VERSION) \
23+
-Dtransitive=false \
24+
-Ddest=./$(INTERCEPTORSPATH) \
25+

Diff for: distributed-tracing/README.adoc

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
= Distributed Tracing for Stream Processing
2+
Viktor Gamov <viktor@confluent.io>, © 2019 Confluent, Inc.
3+
2019-09-13
4+
:revdate: 2019-09-13 14:53:28 -0600
5+
:linkattrs:
6+
:ast: &ast;
7+
:y: &#10003;
8+
:n: &#10008;
9+
:y: icon:check-sign[role="green"]
10+
:n: icon:check-minus[role="red"]
11+
:c: icon:file-text-alt[role="blue"]
12+
:toc: auto
13+
:toc-placement: auto
14+
:toc-position: auto
15+
:toc-title: Table of content
16+
:toclevels: 3
17+
:idprefix:
18+
:idseparator: -
19+
:sectanchors:
20+
:icons: font
21+
:source-highlighter: highlight.js
22+
:highlightjs-theme: idea
23+
:experimental:
24+
25+
Preamble of a document - TBD
26+
27+
toc::[]
28+
29+
== Prep, download and Build everything
30+
31+
[source,bash]
32+
.Make
33+
----
34+
make #<1>
35+
----
36+
<1> this command will create directories, build producer/consumer app and download tracing interceptors from https://github.com/riferrei/kafka-tracing-support[riferrei/kafka-tracing-support]
37+
38+
39+
== Producer app
40+
41+
== KSQL Server
42+
43+
[source, properties]
44+
----
45+
producer.interceptor.classes=io.confluent.devx.util.KafkaTracingProducerInterceptor
46+
consumer.interceptor.classes=io.confluent.devx.util.KafkaTracingConsumerInterceptor
47+
----
48+
49+
50+
`export JAEGER_SERVICE_NAME=DemoInterceptors`
51+
52+
or
53+
54+
`export INTERCEPTORS_CONFIG_FILE=/etc/jaeger/ext/interceptorsConfig.json`

Diff for: distributed-tracing/app/pom.xml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>io.confluent.devx.util</groupId>
7+
<artifactId>distributed-tracing</artifactId>
8+
<version>1.0</version>
9+
<name>springbootapp</name>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>2.1.8.RELEASE</version>
15+
<relativePath/> <!-- lookup parent from repository -->
16+
</parent>
17+
18+
<properties>
19+
<maven.compiler.source>1.8</maven.compiler.source>
20+
<maven.compiler.target>1.8</maven.compiler.target>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<opentracing.version>0.31.0</opentracing.version>
23+
<opentracing.kafka.version>0.0.19</opentracing.kafka.version>
24+
<jaeger.version>0.31.0</jaeger.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.kafka</groupId>
34+
<artifactId>spring-kafka</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.kafka</groupId>
44+
<artifactId>spring-kafka-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.projectlombok</groupId>
49+
<artifactId>lombok</artifactId>
50+
</dependency>
51+
52+
<!-- Distributed Tracing -->
53+
<dependency>
54+
<groupId>io.opentracing</groupId>
55+
<artifactId>opentracing-api</artifactId>
56+
<version>0.32.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.opentracing</groupId>
60+
<artifactId>opentracing-util</artifactId>
61+
<version>0.32.0</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>io.opentracing.contrib</groupId>
65+
<artifactId>opentracing-kafka-client</artifactId>
66+
<version>0.1.1</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>io.jaegertracing</groupId>
70+
<artifactId>jaeger-client</artifactId>
71+
<version>0.34.0</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>io.jaegertracing</groupId>
75+
<artifactId>jaeger-core</artifactId>
76+
<version>0.34.0</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>io.jaegertracing</groupId>
80+
<artifactId>jaeger-thrift</artifactId>
81+
<version>0.34.0</version>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>org.apache.logging.log4j</groupId>
86+
<artifactId>log4j-core</artifactId>
87+
<version>2.8.2</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.apache.logging.log4j</groupId>
91+
<artifactId>log4j-api</artifactId>
92+
<version>2.8.2</version>
93+
</dependency>
94+
95+
<!-- tracking support -->
96+
<dependency>
97+
<groupId>com.github.riferrei</groupId>
98+
<artifactId>kafka-tracing-support</artifactId>
99+
<version>master-SNAPSHOT</version>
100+
</dependency>
101+
</dependencies>
102+
103+
<repositories>
104+
<repository>
105+
<id>jitpack.io</id>
106+
<url>https://jitpack.io</url>
107+
</repository>
108+
</repositories>
109+
110+
<build>
111+
<plugins>
112+
<plugin>
113+
<groupId>org.springframework.boot</groupId>
114+
<artifactId>spring-boot-maven-plugin</artifactId>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
119+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.confluent.devx.util;
2+
3+
import org.apache.kafka.clients.admin.NewTopic;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.scheduling.annotation.EnableScheduling;
8+
9+
@EnableScheduling
10+
@SpringBootApplication
11+
public class MyApplication {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(MyApplication.class, args);
15+
}
16+
17+
@Bean
18+
// kafka-topics --bootstrap-server localhost:9092 --create --topic STAGE1 --partitions 4 --replication-factor 1
19+
NewTopic newTopic() {
20+
return new NewTopic("STAGE1", 4, (short) 1);
21+
}
22+
}

0 commit comments

Comments
 (0)