This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes up spans reported by [Finagle](https://github.com/twitter/finagle/tree/develop/finagle-zipkin). Adjustment code should not be added without a tracking issue either in [Finagle](https://github.com/twitter/finagle/issues) or [Zipkin Finagle](https://github.com/openzipkin/zipkin-finagle/issues). FinagleAdjuster can be used as a library, where attributes are set via `FinagleAdjuster.Builder`. It is more commonly enabled with Spring via autoconfiguration when "zipkin.sparkstreaming.adjuster.finagle.enabled" is set to "true" Here are the relevant setting and a short description. Properties all have a prefix of "zipkin.sparkstreaming.adjuster.finagle" Attribute | Property | Description | Fix --- | --- | --- | --- applyTimestampAndDuration | apply-timestamp-and-duration | Backfill span.timestamp and duration based on annotations. Defaults to true | [Use zipkin-finagle](openzipkin/zipkin-finagle#10)
- Loading branch information
1 parent
f2831ca
commit 40d8d47
Showing
15 changed files
with
414 additions
and
6 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,21 @@ | ||
# adjuster-finagle | ||
|
||
## FinagleAdjuster | ||
This fixes up spans reported by [Finagle](https://github.com/twitter/finagle/tree/develop/finagle-zipkin). | ||
|
||
Adjustment code should not be added without a tracking issue either in | ||
[Finagle](https://github.com/twitter/finagle/issues) or [Zipkin Finagle](https://github.com/openzipkin/zipkin-finagle/issues). | ||
|
||
## Configuration | ||
FinagleAdjuster can be used as a library, where attributes are set via | ||
`FinagleAdjuster.Builder`. | ||
|
||
It is more commonly enabled with Spring via autoconfiguration when | ||
"zipkin.sparkstreaming.adjuster.finagle.enabled" is set to "true" | ||
|
||
Here are the relevant setting and a short description. Properties all | ||
have a prefix of "zipkin.sparkstreaming.adjuster.finagle" | ||
|
||
Attribute | Property | Description | Fix | ||
--- | --- | --- | --- | ||
applyTimestampAndDuration | apply-timestamp-and-duration | Backfill span.timestamp and duration based on annotations. Defaults to true | [Use zipkin-finagle](https://github.com/openzipkin/zipkin-finagle/issues/10) |
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2017 The OpenZipkin Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the License for the specific language governing permissions and limitations under | ||
the License. | ||
--> | ||
<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"> | ||
<parent> | ||
<groupId>io.zipkin.sparkstreaming</groupId> | ||
<artifactId>zipkin-sparkstreaming-adjuster-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>zipkin-sparkstreaming-adjuster-finagle</artifactId> | ||
<name>Zipkin Spark Streaming Adjuster: Finagle</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/../..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.auto.value</groupId> | ||
<artifactId>auto-value</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
66 changes: 66 additions & 0 deletions
66
adjuster/finagle/src/main/java/zipkin/sparkstreaming/adjuster/finagle/FinagleAdjuster.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,66 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.sparkstreaming.adjuster.finagle; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import zipkin.BinaryAnnotation; | ||
import zipkin.Span; | ||
import zipkin.internal.ApplyTimestampAndDuration; | ||
import zipkin.sparkstreaming.Adjuster; | ||
|
||
/** | ||
* Contains adjustments that pertain to Finagle tracing. Detection is based on the binary | ||
* annotations named ".*finagle.version.*". | ||
*/ | ||
@AutoValue | ||
public abstract class FinagleAdjuster extends Adjuster { | ||
|
||
public static Builder newBuilder() { | ||
return new AutoValue_FinagleAdjuster.Builder() | ||
.applyTimestampAndDuration(true); | ||
} | ||
|
||
abstract boolean applyTimestampAndDuration(); | ||
|
||
@AutoValue.Builder | ||
public interface Builder { | ||
/** | ||
* As of Finagle 6.41.0, tracing is always RPC in nature, but timestamp and duration are not | ||
* added. This backfills timestamps. Default true | ||
* | ||
* <p>The current fix is to use zipkin-finagle to report spans. | ||
* See https://github.com/openzipkin/zipkin-finagle/issues/10 | ||
*/ | ||
Builder applyTimestampAndDuration(boolean applyTimestampAndDuration); | ||
|
||
FinagleAdjuster build(); | ||
} | ||
|
||
@Override protected boolean shouldAdjust(Span span) { | ||
for (BinaryAnnotation b : span.binaryAnnotations) { | ||
if (b.key.indexOf("finagle.version") != -1) return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override protected Span adjust(Span span) { | ||
if (applyTimestampAndDuration()) { | ||
return ApplyTimestampAndDuration.apply(span); | ||
} | ||
return span; | ||
} | ||
|
||
FinagleAdjuster() { | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ter/finagle/src/test/java/zipkin/sparkstreaming/adjuster/finagle/FinagleAdjusterTest.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,68 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.sparkstreaming.adjuster.finagle; | ||
|
||
import org.junit.Test; | ||
import zipkin.Annotation; | ||
import zipkin.BinaryAnnotation; | ||
import zipkin.Constants; | ||
import zipkin.Endpoint; | ||
import zipkin.Span; | ||
import zipkin.TestObjects; | ||
import zipkin.internal.ApplyTimestampAndDuration; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class FinagleAdjusterTest { | ||
FinagleAdjuster adjuster = FinagleAdjuster.newBuilder().build(); | ||
|
||
Endpoint localEndpoint = | ||
Endpoint.builder().serviceName("my-host").ipv4(127 << 24 | 1).port(9411).build(); | ||
Endpoint localEndpoint0 = localEndpoint.toBuilder().port(null).build(); | ||
// finagle often sets to the client endpoint to the same as the local endpoint | ||
Endpoint remoteEndpoint = localEndpoint.toBuilder().port(63840).build(); | ||
|
||
Span serverSpan = Span.builder() | ||
.traceId(-6054243957716233329L) | ||
.name("my-span") | ||
.id(-3615651937927048332L) | ||
.parentId(-6054243957716233329L) | ||
.addAnnotation(Annotation.create(1442493420635000L, Constants.SERVER_RECV, localEndpoint)) | ||
.addAnnotation(Annotation.create(1442493422680000L, Constants.SERVER_SEND, localEndpoint)) | ||
.addBinaryAnnotation(BinaryAnnotation.create("srv/finagle.version", "6.28.0", localEndpoint0)) | ||
.addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, localEndpoint)) | ||
.addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, remoteEndpoint)) | ||
.build(); | ||
|
||
/** Default is to apply timestamp and duration */ | ||
@Test | ||
public void adjustsFinagleSpans() throws Exception { | ||
Iterable<Span> adjusted = adjuster.adjust(asList(serverSpan)); | ||
assertThat(adjusted).containsExactly(ApplyTimestampAndDuration.apply(serverSpan)); | ||
} | ||
|
||
@Test | ||
public void applyTimestampAndDuration_disabled() throws Exception { | ||
adjuster = FinagleAdjuster.newBuilder().applyTimestampAndDuration(false).build(); | ||
Iterable<Span> adjusted = adjuster.adjust(asList(serverSpan)); | ||
assertThat(adjusted).containsExactly(serverSpan); | ||
} | ||
|
||
@Test | ||
public void doesntAdjustNonFinagleSpans() throws Exception { | ||
Iterable<Span> adjusted = adjuster.adjust(TestObjects.TRACE); | ||
assertThat(adjusted).containsExactlyElementsOf(TestObjects.TRACE); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
</properties> | ||
|
||
<modules> | ||
<module>finagle</module> | ||
</modules> | ||
|
||
<dependencies> | ||
|
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2017 The OpenZipkin Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the License for the specific language governing permissions and limitations under | ||
the License. | ||
--> | ||
<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"> | ||
<parent> | ||
<groupId>io.zipkin.sparkstreaming</groupId> | ||
<artifactId>zipkin-sparkstreaming-autoconfigure-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>zipkin-sparkstreaming-autoconfigure-adjuster-finagle</artifactId> | ||
<name>Zipkin Spark Streaming Auto Configure: Finagle Adjuster</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/../..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.zipkin.sparkstreaming</groupId> | ||
<artifactId>zipkin-sparkstreaming-adjuster-finagle</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
...sparkstreaming/autoconfigure/adjuster/finagle/ZipkinFinagleAdjusterAutoConfiguration.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,35 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.sparkstreaming.autoconfigure.adjuster.finagle; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import zipkin.sparkstreaming.Adjuster; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(ZipkinFinagleAdjusterProperties.class) | ||
@ConditionalOnProperty( | ||
value = "zipkin.sparkstreaming.adjuster.finagle.enabled", | ||
havingValue = "true" | ||
) | ||
public class ZipkinFinagleAdjusterAutoConfiguration { | ||
|
||
@Bean | ||
Adjuster finagleAdjuster(ZipkinFinagleAdjusterProperties properties) { | ||
return properties.toBuilder().build(); | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...zipkin/sparkstreaming/autoconfigure/adjuster/finagle/ZipkinFinagleAdjusterProperties.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,35 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.sparkstreaming.autoconfigure.adjuster.finagle; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import zipkin.sparkstreaming.adjuster.finagle.FinagleAdjuster; | ||
|
||
@ConfigurationProperties("zipkin.sparkstreaming.adjuster.finagle") | ||
public class ZipkinFinagleAdjusterProperties { | ||
private boolean applyTimestampAndDuration = true; | ||
|
||
public boolean isApplyTimestampAndDuration() { | ||
return applyTimestampAndDuration; | ||
} | ||
|
||
public void setApplyTimestampAndDuration(boolean applyTimestampAndDuration) { | ||
this.applyTimestampAndDuration = applyTimestampAndDuration; | ||
} | ||
|
||
FinagleAdjuster.Builder toBuilder() { | ||
return FinagleAdjuster.newBuilder() | ||
.applyTimestampAndDuration(applyTimestampAndDuration); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
autoconfigure/adjuster-finagle/src/main/resources/META-INF/spring.factories
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,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
zipkin.sparkstreaming.autoconfigure.adjuster.finagle.ZipkinFinagleAdjusterAutoConfiguration |
Oops, something went wrong.