-
Notifications
You must be signed in to change notification settings - Fork 232
Initial implementation of a TracerResolver for Jaeger #175
Changes from 1 commit
a40e73d
1a8bf4d
3f393a2
1120eae
15b6e71
18fcf32
c6139ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Jaeger Tracer Resolver | ||
|
||
## Maven Dependency | ||
```xml | ||
<dependency> | ||
<groupId>com.uber.jaeger</groupId> | ||
<artifactId>jaeger-tracerresolver</artifactId> | ||
<version>$jaegerVersion</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
```java | ||
Tracer tracer = TracerResolver.resolveTracer(); | ||
``` | ||
|
||
## Configuration Options | ||
|
||
The following configuration properties can be provided either as an environment variable or system property. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move these to the README in core as well? We can link to that file from here. Right now the main README only suggests Configuration config = new Configuration("myServiceName", null, null); for production. I would add a sub-section there "Configuration via Environment" with what we have here. And it would also make sense to add yet another subsection that it's possible to init via TracerLoader, and link to here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good - I'll have to look at this next week. |
||
The system property will override an environment variable for the same property name. | ||
|
||
Property | Default | Description | ||
--- | --- | --- | ||
JAEGER_SERVICE_NAME | _none_ | The service name (must be defined) | ||
JAEGER_AGENT_UDP_MAX_PACKET_SIZE | 65000 | The maximum packet size when communicating with the agent via UDP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These default values can get quickly outdated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed - better to just say required/optional. The defaults will be applied by Configuration class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will update |
||
JAEGER_AGENT_UDP_HOST | localhost | The hostname for communicating with agent via UDP | ||
JAEGER_AGENT_UDP_PORT | 6831 | The port for communicating with agent via UDP | ||
JAEGER_REPORTER_MAX_QUEUE_SIZE | 1000 | The reporter's maximum queue size | ||
JAEGER_REPORTER_FLUSH_INTERVAL | 500 | The reporter's flush interval (ms) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
description = 'TracerResolver implementation for Jaeger Tracer' | ||
|
||
dependencies { | ||
compile project(':jaeger-core') | ||
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: tracerResolverVersion | ||
|
||
testCompile group: 'junit', name: 'junit', version: junitVersion | ||
|
||
signature 'org.codehaus.mojo.signature:java16:1.1@signature' | ||
} | ||
|
||
sourceSets { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be this boilerplate avoided? I think it's redundant as we are sticking to default file hierarchy. I know this is repeated over and over it other modules, but should be used only in places where it's required to override a default conventions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this should probably be discussed as a separate issue and applied to all artifacts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous maybe yes. This can be done independently it does not affect other modules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep that works. |
||
main { | ||
java { | ||
srcDir 'src/main/java' | ||
} | ||
resources { | ||
srcDir 'src/main/resources' | ||
} | ||
} | ||
|
||
test { | ||
java { | ||
srcDir 'src/test/java' | ||
} | ||
} | ||
} | ||
|
||
jar { | ||
from sourceSets.main.output | ||
manifest { | ||
attributes('Implementation-Title': 'jaeger-tracerresolver', 'Implementation-Version': project.version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't be this added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's repeated in every module. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If its possible then sounds like a good idea, but outside the remit of this PR. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2017, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.uber.jaeger.tracerresolver; | ||
|
||
import com.uber.jaeger.Tracer; | ||
import com.uber.jaeger.metrics.Metrics; | ||
import com.uber.jaeger.metrics.NullStatsReporter; | ||
import com.uber.jaeger.reporters.RemoteReporter; | ||
import com.uber.jaeger.reporters.Reporter; | ||
import com.uber.jaeger.samplers.ConstSampler; | ||
import com.uber.jaeger.samplers.Sampler; | ||
import com.uber.jaeger.senders.Sender; | ||
import com.uber.jaeger.senders.UdpSender; | ||
|
||
import io.opentracing.contrib.tracerresolver.TracerResolver; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class JaegerTracerResolver extends TracerResolver { | ||
|
||
static final String JAEGER_PREFIX = "JAEGER_"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should be public and with javadoc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are only used by the resolver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are used outside of this module. Consumers set these when starting instrumented app, so are public. Somebody could use them programmatically. Readmes might get outdated, therefore having javadoc is a plus. |
||
static final String JAEGER_AGENT_UDP_MAX_PACKET_SIZE = JAEGER_PREFIX + "AGENT_UDP_MAX_PACKET_SIZE"; | ||
static final String JAEGER_AGENT_UDP_PORT = JAEGER_PREFIX + "AGENT_UDP_PORT"; | ||
static final String JAEGER_AGENT_UDP_HOST = JAEGER_PREFIX + "AGENT_UDP_HOST"; | ||
static final String JAEGER_REPORTER_MAX_QUEUE_SIZE = JAEGER_PREFIX + "REPORTER_MAX_QUEUE_SIZE"; | ||
static final String JAEGER_REPORTER_FLUSH_INTERVAL = JAEGER_PREFIX + "REPORTER_FLUSH_INTERVAL"; | ||
static final String JAEGER_SERVICE_NAME = JAEGER_PREFIX + "SERVICE_NAME"; | ||
|
||
static final int DEFAULT_REPORTER_FLUSH_INTERVAL = 500; | ||
static final int DEFAULT_REPORTER_MAX_QUEUE_SIZE = 1000; | ||
|
||
@Override | ||
protected io.opentracing.Tracer resolve() { | ||
String serviceName = getProperty(JAEGER_SERVICE_NAME); | ||
|
||
return new Tracer.Builder(serviceName, getReporter(), getSampler()).build(); | ||
} | ||
|
||
protected static Reporter getReporter() { | ||
return new RemoteReporter(getSender(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we avoid writing this code and instead use the Configuration class to create the tracer? Here we just need to set the parameters on the respective Config classes, but leave the init logic to one place in the main config. |
||
getPropertyAsInt(JAEGER_REPORTER_FLUSH_INTERVAL, DEFAULT_REPORTER_FLUSH_INTERVAL), | ||
getPropertyAsInt(JAEGER_REPORTER_MAX_QUEUE_SIZE, DEFAULT_REPORTER_MAX_QUEUE_SIZE), | ||
getMetrics()); | ||
} | ||
|
||
protected static Sender getSender() { | ||
return new UdpSender(getProperty(JAEGER_AGENT_UDP_HOST), | ||
getPropertyAsInt(JAEGER_AGENT_UDP_PORT, 0), | ||
getPropertyAsInt(JAEGER_AGENT_UDP_MAX_PACKET_SIZE, 0)); | ||
} | ||
|
||
protected static Metrics getMetrics() { | ||
// TODO: Support other stats reporters | ||
return Metrics.fromStatsReporter(new NullStatsReporter()); | ||
} | ||
|
||
protected static Sampler getSampler() { | ||
// TODO: Support other samplers | ||
return new ConstSampler(true); | ||
} | ||
|
||
private static String getProperty(String name) { | ||
return System.getProperty(name, System.getenv(name)); | ||
} | ||
|
||
private static int getPropertyAsInt(String name, int def) { | ||
String value = getProperty(name); | ||
if (value != null) { | ||
try { | ||
return Integer.parseInt(value); | ||
} catch (NumberFormatException e) { | ||
log.error("Failed to parse integer for property '" + name + "' with value '" + value + "'", e); | ||
} | ||
} | ||
return def; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.uber.jaeger.tracerresolver.JaegerTracerResolver |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2017, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.uber.jaeger.tracerresolver; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.uber.jaeger.reporters.RemoteReporter; | ||
import com.uber.jaeger.reporters.Reporter; | ||
import com.uber.jaeger.samplers.ConstSampler; | ||
import com.uber.jaeger.senders.UdpSender; | ||
|
||
import io.opentracing.Tracer; | ||
import io.opentracing.contrib.tracerresolver.TracerResolver; | ||
|
||
import java.util.Enumeration; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class JaegerTracerResolverTest { | ||
|
||
@Before | ||
public void clearProperties() { | ||
Enumeration<?> iter = System.getProperties().propertyNames(); | ||
while (iter.hasMoreElements()) { | ||
String propName = (String)iter.nextElement(); | ||
if (propName.startsWith(JaegerTracerResolver.JAEGER_PREFIX)) { | ||
System.clearProperty(propName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: clear only properties set by this test |
||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testResolveTracerNoServiceName() { | ||
assertNull(TracerResolver.resolveTracer()); | ||
} | ||
|
||
@Test | ||
public void testResolveTracerDefault() { | ||
System.setProperty(JaegerTracerResolver.JAEGER_SERVICE_NAME, "MyService"); | ||
Tracer tracer = TracerResolver.resolveTracer(); | ||
assertNotNull(tracer); | ||
assertTrue(tracer instanceof com.uber.jaeger.Tracer); | ||
} | ||
|
||
@Test | ||
public void testSamplerConst() { | ||
assertTrue(JaegerTracerResolver.getSampler() instanceof ConstSampler); | ||
} | ||
|
||
@Test | ||
public void testSender() { | ||
assertTrue(JaegerTracerResolver.getSender() instanceof UdpSender); | ||
} | ||
|
||
@Test | ||
public void testMetrics() { | ||
assertNotNull(JaegerTracerResolver.getMetrics()); | ||
} | ||
|
||
@Test | ||
public void testReporter() { | ||
System.setProperty(JaegerTracerResolver.JAEGER_REPORTER_MAX_QUEUE_SIZE, "10"); | ||
Reporter reporter = JaegerTracerResolver.getReporter(); | ||
assertTrue(reporter instanceof RemoteReporter); | ||
assertEquals(10, ((RemoteReporter)reporter).getMaxQueueSize()); | ||
} | ||
|
||
@Test | ||
public void testReporterInvalidQueueSize() { | ||
System.setProperty(JaegerTracerResolver.JAEGER_REPORTER_MAX_QUEUE_SIZE, "X"); | ||
Reporter reporter = JaegerTracerResolver.getReporter(); | ||
assertTrue(reporter instanceof RemoteReporter); | ||
assertEquals(JaegerTracerResolver.DEFAULT_REPORTER_MAX_QUEUE_SIZE, ((RemoteReporter)reporter).getMaxQueueSize()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have here a short comment describing what it is