This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
270 additions
and
42 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
group=io.netifi.proteus | ||
version=0.9.4 | ||
version=0.9.5 |
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dependencies { | ||
compile 'io.rsocket:rsocket-core:0.11.7' | ||
compile 'io.rsocket:rsocket-core:0.11.9' | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...eus-tracing-openzipkin/src/main/java/io/netifi/proteus/tracing/ProteusTracerSupplier.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,34 @@ | ||
package io.netifi.proteus.tracing; | ||
|
||
import brave.Tracing; | ||
import brave.opentracing.BraveTracer; | ||
import io.netifi.proteus.Proteus; | ||
import io.netifi.proteus.rsocket.ProteusSocket; | ||
import io.opentracing.Tracer; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
@Named("ProteusTracerSupplier") | ||
public class ProteusTracerSupplier implements Supplier<Tracer> { | ||
private final Tracer tracer; | ||
|
||
@Inject | ||
public ProteusTracerSupplier(Proteus proteus, Optional<String> tracingGroup) { | ||
ProteusSocket proteusSocket = proteus.group(tracingGroup.orElse("com.netifi.proteus.tracing")); | ||
|
||
ProteusTracingServiceClient client = new ProteusTracingServiceClient(proteusSocket); | ||
ProteusReporter reporter = | ||
new ProteusReporter(client, proteus.getGroupName(), proteus.getDestination()); | ||
|
||
Tracing tracing = Tracing.newBuilder().spanReporter(reporter).build(); | ||
|
||
tracer = BraveTracer.create(tracing); | ||
} | ||
|
||
@Override | ||
public Tracer get() { | ||
return tracer; | ||
} | ||
} |
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
118 changes: 118 additions & 0 deletions
118
proteus-tracing-openzipkin/src/main/java/io/netifi/proteus/tracing/TracesStreamer.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,118 @@ | ||
package io.netifi.proteus.tracing; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.module.SimpleDeserializers; | ||
import com.hubspot.jackson.datatype.protobuf.ProtobufModule; | ||
import io.netty.handler.codec.json.JsonObjectDecoder; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.Exceptions; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.netty.http.client.HttpClient; | ||
import zipkin2.proto3.Span; | ||
|
||
public class TracesStreamer { | ||
|
||
private final ObjectMapper objectMapper = protoMapper(); | ||
private Function<Integer, Publisher<InputStream>> inputSource; | ||
|
||
public TracesStreamer(String zipkinUrl, Mono<HttpClient> client) { | ||
this(zipkinServerStream(zipkinUrl, client)); | ||
} | ||
|
||
public TracesStreamer(Publisher<InputStream> tracesSource) { | ||
this(v -> tracesSource); | ||
} | ||
|
||
private TracesStreamer(Function<Integer, Publisher<InputStream>> inputSource) { | ||
this.inputSource = inputSource; | ||
} | ||
|
||
public Flux<Trace> streamTraces(int lookbackSeconds) { | ||
return streamTraces(inputSource.apply(lookbackSeconds)); | ||
} | ||
|
||
Flux<Trace> streamTraces(Publisher<InputStream> input) { | ||
return Flux.from(input) | ||
.filter( | ||
is -> { | ||
try { | ||
return is.available() > 0; | ||
} catch (IOException e) { | ||
throw Exceptions.propagate(e); | ||
} | ||
}) | ||
.map( | ||
is -> { | ||
try { | ||
return objectMapper.readValue(is, new TypeReference<Trace>() {}); | ||
} catch (IOException e) { | ||
throw Exceptions.propagate(e); | ||
} | ||
}); | ||
} | ||
|
||
private static Function<Integer, Publisher<InputStream>> zipkinServerStream( | ||
String zipkinUrl, Mono<HttpClient> client) { | ||
return lookbackSeconds -> | ||
client.flatMapMany( | ||
c -> | ||
c.doOnRequest( | ||
(__, connection) -> connection.addHandler(new JsonObjectDecoder(true))) | ||
.get() | ||
.uri(zipkinQuery(zipkinUrl, lookbackSeconds)) | ||
.responseContent() | ||
.asInputStream()); | ||
} | ||
|
||
private static String zipkinQuery(String zipkinUrl, int lookbackSeconds) { | ||
long lookbackMillis = TimeUnit.SECONDS.toMillis(lookbackSeconds); | ||
return zipkinUrl + "?lookback=" + lookbackMillis + "&limit=100000"; | ||
} | ||
|
||
private ObjectMapper protoMapper() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ProtobufModule module = new CustomProtoModule(); | ||
mapper.registerModule(module); | ||
return mapper; | ||
} | ||
|
||
public static class CustomProtoModule extends ProtobufModule { | ||
@Override | ||
public void setupModule(SetupContext context) { | ||
super.setupModule(context); | ||
SimpleDeserializers deser = new SimpleDeserializers(); | ||
deser.addDeserializer(Trace.class, new TracersDeserializer()); | ||
context.addDeserializers(deser); | ||
} | ||
} | ||
|
||
public static class TracersDeserializer extends StdDeserializer<Trace> { | ||
|
||
public TracersDeserializer() { | ||
this(null); | ||
} | ||
|
||
protected TracersDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public Trace deserialize(JsonParser p, DeserializationContext ctx) throws IOException { | ||
Trace.Builder traceBuilder = Trace.newBuilder(); | ||
while (p.nextToken() != JsonToken.END_ARRAY) { | ||
traceBuilder.addSpans(ctx.readValue(p, Span.class)); | ||
} | ||
return traceBuilder.build(); | ||
} | ||
} | ||
} |
Oops, something went wrong.