Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Adds initial Finagle Adjuster (#6)
Browse files Browse the repository at this point in the history
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
adriancole authored Feb 10, 2017
1 parent f2831ca commit 40d8d47
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ An adjuster conditionally changes spans sharing the same trace ID.
You can make adjusters to fixup data reported by instrumentation, or to
scrub private data.

TODO: briefly describe and link to built-in adjusters
Adjuster | Description
--- | --- | ---
[Finagle](./adjuster/finagle) | Fixes up spans reported by [Finagle](https://github.com/twitter/finagle/tree/develop/finagle-zipkin).

### Consumer
A consumer is an end-recipient of potentially adjusted spans sharing the
Expand Down
21 changes: 21 additions & 0 deletions adjuster/finagle/README.md
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)
41 changes: 41 additions & 0 deletions adjuster/finagle/pom.xml
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>
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() {
}
}
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);
}
}
1 change: 1 addition & 0 deletions adjuster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</properties>

<modules>
<module>finagle</module>
</modules>

<dependencies>
Expand Down
39 changes: 39 additions & 0 deletions autoconfigure/adjuster-finagle/pom.xml
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>
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();
}
}

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);
}
}
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
Loading

0 comments on commit 40d8d47

Please sign in to comment.