-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:katharsis-project/katharsis-fram…
…ework into develop
- Loading branch information
Showing
177 changed files
with
7,518 additions
and
2,665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<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.katharsis</groupId> | ||
<artifactId>katharsis-parent</artifactId> | ||
<version>2.8.2-SNAPSHOT</version> | ||
<relativePath>../katharsis-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>katharsis-brave</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>katharsis-brave</name> | ||
|
||
<properties> | ||
<brave.version>3.14.1</brave.version> | ||
<jersey.version>2.17</jersey.version> | ||
<javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version> | ||
<guava.version>15.0</guava.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eluder.coveralls</groupId> | ||
<artifactId>coveralls-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.danielflower.mavenplugins</groupId> | ||
<artifactId>gitlog-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<configuration> | ||
<instructions> | ||
<Export-Package>io.katharsis.brave.*</Export-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.katharsis</groupId> | ||
<artifactId>katharsis-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.katharsis</groupId> | ||
<artifactId>katharsis-client</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.zipkin.brave</groupId> | ||
<artifactId>brave-okhttp</artifactId> | ||
<version>${brave.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>${guava.version}</version> | ||
</dependency> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
<optional>true</optional> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.katharsis</groupId> | ||
<artifactId>katharsis-rs</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>${javax.ws.rs-api.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-common</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-grizzly2-http</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework</groupId> | ||
<artifactId>jersey-test-framework-core</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
94 changes: 94 additions & 0 deletions
94
katharsis-brave/src/main/java/io/katharsis/brave/BraveModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package io.katharsis.brave; | ||
|
||
import com.github.kristofa.brave.Brave; | ||
import com.github.kristofa.brave.BraveExecutorService; | ||
import com.github.kristofa.brave.okhttp.BraveTracingInterceptor; | ||
import com.github.kristofa.brave.okhttp.BraveTracingInterceptor.Builder; | ||
|
||
import io.katharsis.brave.internal.BraveRepositoryFilter; | ||
import io.katharsis.client.http.HttpAdapter; | ||
import io.katharsis.client.http.okhttp.OkHttpAdapter; | ||
import io.katharsis.client.http.okhttp.OkHttpAdapterListener; | ||
import io.katharsis.client.module.HttpAdapterAware; | ||
import io.katharsis.module.Module; | ||
import okhttp3.Dispatcher; | ||
|
||
/** | ||
* Integrates Brave into katharsis client and server: | ||
* | ||
* <ul> | ||
* <li>On the client-side all requests are traced with the brave-okhttp implementation.</li> | ||
* <li> | ||
* On the server-side all the repository accesses are traced. Keep in mind that a single HTTP request | ||
* can trigger multiple repository accesses if the request contains an inclusion of relations. | ||
* Note that no HTTP calls itself are traced by this module. That is the responsibility of the | ||
* web container and Brave. | ||
* </li> | ||
* </ul> | ||
*/ | ||
public class BraveModule implements Module, HttpAdapterAware, OkHttpAdapterListener { | ||
|
||
private Brave brave; | ||
|
||
private boolean server; | ||
|
||
private BraveModule(Brave brave, boolean server) { | ||
this.brave = brave; | ||
this.server = server; | ||
} | ||
|
||
public static BraveModule newClientModule(Brave brave) { | ||
return new BraveModule(brave, false); | ||
} | ||
|
||
public static BraveModule newServerModule(Brave brave) { | ||
return new BraveModule(brave, true); | ||
} | ||
|
||
@Override | ||
public String getModuleName() { | ||
return "brave"; | ||
} | ||
|
||
@Override | ||
public void setupModule(ModuleContext context) { | ||
// nothing to do | ||
if (server) { | ||
BraveRepositoryFilter filter = new BraveRepositoryFilter(brave, context); | ||
context.addRepositoryFilter(filter); | ||
} | ||
} | ||
|
||
@Override | ||
public void setHttpAdapter(HttpAdapter adapter) { | ||
if (!(adapter instanceof OkHttpAdapter)) { | ||
throw new IllegalStateException(adapter.getClass() + " not supported yet"); | ||
} | ||
OkHttpAdapter okHttpAdapter = (OkHttpAdapter) adapter; | ||
okHttpAdapter.addListener(this); | ||
} | ||
|
||
@Override | ||
public void onBuild(okhttp3.OkHttpClient.Builder builder) { | ||
BraveTracingInterceptor interceptor = buildInterceptor(); | ||
|
||
BraveExecutorService tracePropagatingExecutor = buildExecutor(builder); | ||
|
||
builder.addInterceptor(interceptor); | ||
builder.addNetworkInterceptor(interceptor); | ||
builder.dispatcher(new Dispatcher(tracePropagatingExecutor)); | ||
} | ||
|
||
protected BraveExecutorService buildExecutor(okhttp3.OkHttpClient.Builder builder) { | ||
return new BraveExecutorService(new Dispatcher().executorService(), brave.serverSpanThreadBinder()); | ||
} | ||
|
||
protected BraveTracingInterceptor buildInterceptor() { | ||
Builder tracingBuilder = BraveTracingInterceptor.builder(brave); | ||
return tracingBuilder.build(); | ||
} | ||
|
||
public Brave getBrave() { | ||
return brave; | ||
} | ||
} |
Oops, something went wrong.