Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Java 6 compatibility (#132)
Browse files Browse the repository at this point in the history
jaeger-crossdock still requires Java 7 because it calls
InetAddress#getLoopbackAddress()

Add animal sniffer plugin

(closes #129)
  • Loading branch information
felixbarny authored and vprithvi committed Mar 21, 2017
1 parent 1b13636 commit 7839d9f
Show file tree
Hide file tree
Showing 33 changed files with 321 additions and 104 deletions.
22 changes: 16 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'com.github.sherter.google-java-format' version '0.3.2'
id "com.github.johnrengelman.shadow" version "1.2.3"
id "net.ltgt.errorprone" version "0.0.9"
id 'ru.vyarus.animalsniffer' version '1.2.0'
}


Expand All @@ -31,24 +32,32 @@ allprojects {
mavenCentral()
}

repositories {
mavenCentral()
}

task wrapper(type: Wrapper) {
gradleVersion = '3.1.2' //version required
}
}


subprojects {
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'com.github.hierynomus.license'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

sourceCompatibility = 1.7
targetCompatibility = 1.7
compileJava {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}

compileTestJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}

animalsniffer {
sourceSets = [sourceSets.main]
}

[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

Expand Down Expand Up @@ -91,6 +100,7 @@ subprojects {

dependencies {
compileOnly 'org.projectlombok:lombok:1.16.12'
compileOnly 'org.codehaus.mojo:animal-sniffer-annotations:1.15'
}

}
Expand Down
2 changes: 2 additions & 0 deletions jaeger-apachehttpclient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies {
testCompile group: 'org.mock-server', name: 'mockserver-netty', version: '3.10.4'
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion

signature 'org.codehaus.mojo.signature:java16:1.1@signature'
}

sourceSets {
Expand Down
2 changes: 2 additions & 0 deletions jaeger-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies {
// Testing Frameworks
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion

signature 'org.codehaus.mojo.signature:java16:1.1@signature'
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedE

@Override
public <T> Future<T> submit(java.util.concurrent.Callable<T> task) {
return delegate.submit(new Callable<>(task, traceContext));
return delegate.submit(new Callable<T>(task, traceContext));
}

@Override
Expand Down Expand Up @@ -113,9 +113,9 @@ public void execute(final java.lang.Runnable command) {
private <T> Collection<? extends java.util.concurrent.Callable<T>> wrapJaegerCallableCollection(
Collection<? extends java.util.concurrent.Callable<T>> originalCollection) {
Collection<java.util.concurrent.Callable<T>> collection =
new ArrayList<>(originalCollection.size());
new ArrayList<java.util.concurrent.Callable<T>>(originalCollection.size());
for (java.util.concurrent.Callable<T> c : originalCollection) {
collection.add(new Callable<>(c, traceContext));
collection.add(new Callable<T>(c, traceContext));
}
return collection;
}
Expand Down
2 changes: 2 additions & 0 deletions jaeger-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testCompile group: 'com.tngtech.java', name: 'junit-dataprovider', version: junitDataProviderVersion

signature 'org.codehaus.mojo.signature:java16:1.1@signature'
}

sourceSets {
Expand Down
34 changes: 18 additions & 16 deletions jaeger-core/src/main/java/com/uber/jaeger/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
package com.uber.jaeger;

import com.twitter.zipkin.thriftjava.Endpoint;
import io.opentracing.tag.Tags;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.opentracing.tag.Tags;

public class Span implements io.opentracing.Span {
private final Tracer tracer;
private final long startTimeMicroseconds;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class Span implements io.opentracing.Span {
this.startTimeMicroseconds = startTimeMicroseconds;
this.startTimeNanoTicks = startTimeNanoTicks;
this.computeDurationViaNanoTicks = computeDurationViaNanoTicks;
this.tags = new HashMap<>();
this.tags = new HashMap<String, Object>();

for (Map.Entry<String, Object> tag : tags.entrySet()) {
setTagAsObject(tag.getKey(), tag.getValue());
Expand Down Expand Up @@ -205,6 +206,7 @@ public synchronized Span setTag(String key, Number value) {

/**
* Sets various fields on the {@link Span} when certain {@link Tags} are encountered
*
* @return true iff a special tag is handled
*/
private boolean handleSpecialTag(String key, Object value) {
Expand Down Expand Up @@ -245,23 +247,23 @@ private boolean handleSpecialTag(String key, Object value) {
* See {@link #handleSpecialTag(String, Object)}
*/
private Span setTagAsObject(String key, Object value) {
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
int priority = ((Number) value).intValue();
byte newFlags;
if (priority > 0) {
newFlags = (byte) (context.getFlags() | SpanContext.flagSampled | SpanContext.flagDebug);
} else {
newFlags = (byte) (context.getFlags() & (~SpanContext.flagSampled));
}

context = context.withFlags(newFlags);
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
int priority = ((Number) value).intValue();
byte newFlags;
if (priority > 0) {
newFlags = (byte) (context.getFlags() | SpanContext.flagSampled | SpanContext.flagDebug);
} else {
newFlags = (byte) (context.getFlags() & (~SpanContext.flagSampled));
}

if (context.isSampled()) {
if (!handleSpecialTag(key, value)) {
tags.put(key, value);
}
context = context.withFlags(newFlags);
}

if (context.isSampled()) {
if (!handleSpecialTag(key, value)) {
tags.put(key, value);
}
}

return this;
}
Expand Down
2 changes: 1 addition & 1 deletion jaeger-core/src/main/java/com/uber/jaeger/SpanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static SpanContext contextFromString(String value)
}

public SpanContext withBaggageItem(String key, String val) {
Map<String, String> newBaggage = new HashMap<>(this.baggage);
Map<String, String> newBaggage = new HashMap<String, String>(this.baggage);
newBaggage.put(key, val);
return new SpanContext(traceID, spanID, parentID, flags, newBaggage, debugID);
}
Expand Down
25 changes: 14 additions & 11 deletions jaeger-core/src/main/java/com/uber/jaeger/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
import com.uber.jaeger.utils.Clock;
import com.uber.jaeger.utils.SystemClock;
import com.uber.jaeger.utils.Utils;
import io.opentracing.References;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tags;

import java.io.InputStream;
import java.net.Inet4Address;
Expand All @@ -46,8 +43,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;

import io.opentracing.References;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tags;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -89,7 +89,7 @@ private Tracer(

this.version = loadVersion();

Map<String, Object> tags = new HashMap<>();
Map<String, Object> tags = new HashMap<String, Object>();
tags.put("jaeger.version", this.version);
String hostname = getHostName();
if (hostname != null) {
Expand Down Expand Up @@ -164,7 +164,7 @@ class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {
private String operationName = null;
private long startTimeMicroseconds;
private SpanContext parent;
private final Map<String, Object> tags = new HashMap<>();
private final Map<String, Object> tags = new HashMap<String, Object>();

SpanBuilder(String operationName) {
this.operationName = operationName;
Expand Down Expand Up @@ -192,8 +192,8 @@ public io.opentracing.Tracer.SpanBuilder asChildOf(io.opentracing.Span parent) {
public io.opentracing.Tracer.SpanBuilder addReference(
String referenceType, io.opentracing.SpanContext referencedContext) {
if (parent == null
&& (Objects.equals(referenceType, References.CHILD_OF)
|| Objects.equals(referenceType, References.FOLLOWS_FROM))) {
&& (Utils.equals(referenceType, References.CHILD_OF)
|| Utils.equals(referenceType, References.FOLLOWS_FROM))) {
this.parent = (SpanContext) referencedContext;
}
return this;
Expand Down Expand Up @@ -376,8 +376,8 @@ public Tracer build() {
}

private static class PropagationRegistry {
private final Map<Format<?>, Injector<?>> injectors = new HashMap<>();
private final Map<Format<?>, Extractor<?>> extractors = new HashMap<>();
private final Map<Format<?>, Injector<?>> injectors = new HashMap<Format<?>, Injector<?>>();
private final Map<Format<?>, Extractor<?>> extractors = new HashMap<Format<?>, Extractor<?>>();

@SuppressWarnings("unchecked")
<T> Injector<T> getInjector(Format<T> format) {
Expand All @@ -401,10 +401,13 @@ public <T> void register(Format<T> format, Extractor<T> extractor) {
private static String loadVersion() {
String version;
try {
try (InputStream is = Tracer.class.getResourceAsStream("jaeger.properties")) {
InputStream is = Tracer.class.getResourceAsStream("jaeger.properties");
try {
Properties prop = new Properties();
prop.load(is);
version = prop.getProperty("jaeger.version");
} finally {
is.close();
}
} catch (Exception e) {
throw new RuntimeException("Cannot read jaeger.properties", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import java.util.Map;

public class InMemoryStatsReporter implements StatsReporter {
public Map<String, Long> counters = new HashMap<>();
public Map<String, Long> gauges = new HashMap<>();
public Map<String, Long> timers = new HashMap<>();
public Map<String, Long> counters = new HashMap<String, Long>();
public Map<String, Long> gauges = new HashMap<String, Long>();
public Map<String, Long> timers = new HashMap<String, Long>();

void reset() {
counters = new HashMap<>();
gauges = new HashMap<>();
timers = new HashMap<>();
counters = new HashMap<String, Long>();
gauges = new HashMap<String, Long>();
timers = new HashMap<String, Long>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Metrics(StatsFactory factory) {
}

String metricName = "jaeger.";
HashMap<String, String> tags = new HashMap<>();
HashMap<String, String> tags = new HashMap<String, String>();

Annotation[] annotations = field.getAnnotations();
for (Annotation anno : annotations) {
Expand All @@ -66,7 +66,7 @@ public Metrics(StatsFactory factory) {
throw new RuntimeException(
"A field type that was neither Counter, Gauge, or Timer was parsed in reflection.");
}
} catch (ReflectiveOperationException e) {
} catch (Exception e) {
// This exception should only happen at the start of a program if the code below is not set up correctly.
// As long as tests are run this code should never be thrown in production.
throw new RuntimeException(
Expand All @@ -84,7 +84,7 @@ public static String addTagsToMetricName(String name, Map<String, String> tags)
StringBuilder sb = new StringBuilder();
sb.append(name);

SortedSet<String> sortedKeys = new TreeSet<>(tags.keySet());
SortedSet<String> sortedKeys = new TreeSet<String>(tags.keySet());
for (String key : sortedKeys) {
sb.append(".");
sb.append(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

import com.uber.jaeger.Constants;
import com.uber.jaeger.SpanContext;
import io.opentracing.propagation.TextMap;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import io.opentracing.propagation.TextMap;

public class TextMapCodec implements Injector<TextMap>, Extractor<TextMap> {
/** Key used to store serialized span context representation */
private static final String SPAN_CONTEXT_KEY = "uber-trace-id";
Expand Down Expand Up @@ -78,7 +79,7 @@ public SpanContext extract(TextMap carrier) {
debugID = decodedValue(entry.getValue());
} else if (key.startsWith(baggagePrefix)) {
if (baggage == null) {
baggage = new HashMap<>();
baggage = new HashMap<String, String>();
}
baggage.put(keys.unprefixedKey(key, baggagePrefix), decodedValue(entry.getValue()));
}
Expand All @@ -98,9 +99,17 @@ public SpanContext extract(TextMap carrier) {
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("TextMapCodec{").append("contextKey=").append(contextKey).append(',')
.append("baggagePrefix=").append(baggagePrefix).append(',')
.append("urlEncoding=").append(urlEncoding).append('}');
buffer
.append("TextMapCodec{")
.append("contextKey=")
.append(contextKey)
.append(',')
.append("baggagePrefix=")
.append(baggagePrefix)
.append(',')
.append("urlEncoding=")
.append(urlEncoding)
.append('}');
return buffer.toString();
}

Expand Down Expand Up @@ -130,6 +139,7 @@ private String decodedValue(String value) {

/**
* Returns a builder for TextMapCodec
*
* @return Builder
*/
public static Builder builder() {
Expand Down Expand Up @@ -160,6 +170,5 @@ public Builder withBaggagePrefix(String baggagePrefix) {
public TextMapCodec build() {
return new TextMapCodec(this);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CompositeReporter implements Reporter {
private final List<Reporter> reporters;

public CompositeReporter(Reporter... reporters) {
this.reporters = new ArrayList<>();
this.reporters = new ArrayList<Reporter>();
for (int i = 0; i < reporters.length; i++) {
this.reporters.add(reporters[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public RemoteReporter(final Sender sender, int flushInterval, int maxQueueSize,
this.sender = sender;
this.maxQueueSize = maxQueueSize;
this.metrics = metrics;
commandQueue = new ArrayBlockingQueue<>(maxQueueSize);
commandQueue = new ArrayBlockingQueue<Command>(maxQueueSize);

// start a thread to append spans
queueProcessor = new QueueProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public static com.uber.jaeger.thriftjava.Span convertSpan(Span span) {
span.getOperationName(),
context.getFlags(),
span.getStart(),
span.getDuration()
)
span.getDuration())
.setTags(buildTags(span.getTags()))
.setLogs(buildLogs(span.getLogs()));
}
Expand Down
Loading

0 comments on commit 7839d9f

Please sign in to comment.