This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Initial implementation of a TracerResolver for Jaeger #175
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a40e73d
Initial implementation of a TracerResolver for Jaeger
objectiser 1a8bf4d
Add description to the readme
objectiser 3f393a2
Updates following review - remove sourceset, make constants public wi…
objectiser 1120eae
Clear properties before and after test
objectiser 15b6e71
Changed resolver to use existing Configuration class and remove the d…
objectiser 18fcf32
Moved config init from env to Configuration class
objectiser c6139ee
Move the documentation of the configuration properties to the core ar…
objectiser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
109 changes: 109 additions & 0 deletions
109
jaeger-core/src/test/java/com/uber/jaeger/ConfigurationTest.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,109 @@ | ||
/* | ||
* 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; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.uber.jaeger.Configuration.ReporterConfiguration; | ||
import com.uber.jaeger.Configuration.SamplerConfiguration; | ||
import com.uber.jaeger.samplers.ConstSampler; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class ConfigurationTest { | ||
|
||
@Before | ||
@After | ||
public void clearProperties() { | ||
// Explicitly clear all properties | ||
System.clearProperty(Configuration.JAEGER_AGENT_HOST); | ||
System.clearProperty(Configuration.JAEGER_AGENT_PORT); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_LOG_SPANS); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_MAX_QUEUE_SIZE); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_TYPE); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_PARAM); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_MANAGER_HOST_PORT); | ||
System.clearProperty(Configuration.JAEGER_SERVICE_NAME); | ||
} | ||
|
||
@Test | ||
public void testFromEnv() { | ||
System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test"); | ||
assertNotNull(Configuration.fromEnv().getTracer()); | ||
} | ||
|
||
@Test | ||
public void testSamplerConst() { | ||
System.setProperty(Configuration.JAEGER_SAMPLER_TYPE, ConstSampler.TYPE); | ||
System.setProperty(Configuration.JAEGER_SAMPLER_PARAM, "1"); | ||
SamplerConfiguration samplerConfig = Configuration.getSamplerConfigurationFromEnv(); | ||
assertEquals(ConstSampler.TYPE, samplerConfig.getType()); | ||
assertEquals(1, samplerConfig.getParam().intValue()); | ||
} | ||
|
||
@Test | ||
public void testSamplerConstInvalidParam() { | ||
System.setProperty(Configuration.JAEGER_SAMPLER_TYPE, ConstSampler.TYPE); | ||
System.setProperty(Configuration.JAEGER_SAMPLER_PARAM, "X"); | ||
SamplerConfiguration samplerConfig = Configuration.getSamplerConfigurationFromEnv(); | ||
assertEquals(ConstSampler.TYPE, samplerConfig.getType()); | ||
assertNull(samplerConfig.getParam()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfiguration() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_LOG_SPANS, "true"); | ||
System.setProperty(Configuration.JAEGER_AGENT_HOST, "MyHost"); | ||
System.setProperty(Configuration.JAEGER_AGENT_PORT, "1234"); | ||
System.setProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL, "500"); | ||
System.setProperty(Configuration.JAEGER_REPORTER_MAX_QUEUE_SIZE, "1000"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertTrue(reporterConfig.getLogSpans()); | ||
assertEquals("MyHost", reporterConfig.getAgentHost()); | ||
assertEquals(1234, reporterConfig.getAgentPort().intValue()); | ||
assertEquals(500, reporterConfig.getFlushIntervalMs().intValue()); | ||
assertEquals(1000, reporterConfig.getMaxQueueSize().intValue()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfigurationInvalidFlushInterval() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL, "X"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertNull(reporterConfig.getFlushIntervalMs()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfigurationInvalidLogSpans() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_LOG_SPANS, "X"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertFalse(reporterConfig.getLogSpans()); | ||
} | ||
|
||
} |
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,23 @@ | ||
# Jaeger Tracer Resolver | ||
|
||
This module provides a Jaeger implementation for the [TracerResolver](https://github.com/opentracing-contrib/java-tracerresolver). This mechanism provides a vendor neutral approach for obtaining a `Tracer` using the JDK | ||
`ServiceLoader`. | ||
|
||
|
||
## Maven Dependency | ||
```xml | ||
<dependency> | ||
<groupId>com.uber.jaeger</groupId> | ||
<artifactId>jaeger-tracerresolver</artifactId> | ||
<version>$jaegerVersion</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
```java | ||
Tracer tracer = TracerResolver.resolveTracer(); | ||
``` | ||
|
||
This tracer is configured via environment variables (or system properties). The properties are | ||
described [here](../jaeger-core/README.md). |
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,17 @@ | ||
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' | ||
} | ||
|
||
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. |
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
jaeger-tracerresolver/src/main/java/com/uber/jaeger/tracerresolver/JaegerTracerResolver.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,36 @@ | ||
/* | ||
* 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.Configuration; | ||
|
||
import io.opentracing.contrib.tracerresolver.TracerResolver; | ||
|
||
public class JaegerTracerResolver extends TracerResolver { | ||
|
||
@Override | ||
protected io.opentracing.Tracer resolve() { | ||
return Configuration.fromEnv().getTracer(); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/io.opentracing.contrib.tracerresolver.TracerResolver
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 @@ | ||
com.uber.jaeger.tracerresolver.JaegerTracerResolver |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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