Skip to content

Commit

Permalink
Working XRayUDPReporter and STORAGE_TYPE xray
Browse files Browse the repository at this point in the history
This adds `XRayUDPReporter` which defaults to localhost:2000 or
AWS_XRAY_DAEMON_ADDRESS. This can be used in applications directly or
integrated with a zipkin-server where `STORAGE_TYPE=xray`

Note: this is experimental and makes assumptions about trace ID format:
See openzipkin/b3-propagation#6
  • Loading branch information
Adrian Cole committed Oct 17, 2017
1 parent 80c6bc9 commit 3e1b56d
Show file tree
Hide file tree
Showing 28 changed files with 914 additions and 14 deletions.
4 changes: 2 additions & 2 deletions autoconfigure/collector-kinesis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>zipkin-autoconfigure</artifactId>
<groupId>io.zipkin.aws</groupId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -66,7 +66,7 @@
<classifier>module</classifier>
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work -->
<excludeGroupIds>
io.zipkin.java,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion
io.zipkin.java,io.zipkin.zipkin2,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion
</excludeGroupIds>
<!-- already packaged in zipkin-server -->
<excludeArtifactIds>aws-java-sdk-core,aws-java-sdk-sts,jmespath-java</excludeArtifactIds>
Expand Down
4 changes: 2 additions & 2 deletions autoconfigure/collector-sqs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.aws</groupId>
<artifactId>zipkin-autoconfigure</artifactId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-autoconfigure-collector-sqs</artifactId>
Expand Down Expand Up @@ -66,7 +66,7 @@
<layout>MODULE</layout>
<classifier>module</classifier>
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work -->
<excludeGroupIds>io.zipkin.java,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion</excludeGroupIds>
<excludeGroupIds>io.zipkin.java,io.zipkin.zipkin2,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion</excludeGroupIds>
<!-- already packaged in zipkin-server -->
<excludeArtifactIds>aws-java-sdk-core,aws-java-sdk-sts,jmespath-java</excludeArtifactIds>
</configuration>
Expand Down
4 changes: 3 additions & 1 deletion autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.aws</groupId>
<artifactId>zipkin-aws-parent</artifactId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-autoconfigure</artifactId>
Expand All @@ -35,13 +35,15 @@
<module>collector-sqs</module>
<module>sparkstreaming-stream-kinesis</module>
<module>collector-kinesis</module>
<module>storage-xray</module>
</modules>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
2 changes: 1 addition & 1 deletion autoconfigure/sparkstreaming-stream-kinesis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>zipkin-autoconfigure</artifactId>
<groupId>io.zipkin.aws</groupId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
49 changes: 49 additions & 0 deletions autoconfigure/storage-xray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# autoconfigure-storage-xray

## Overview

This is a Spring Boot [AutoConfiguration](http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html)
module that can be added to a [Zipkin Server](https://github.com/openzipkin/zipkin/tree/master/zipkin-server)
deployment to send Spans to Amazon XRay.

This currently only supports sending to an XRay UDP daemon, not reading back spans from the service.
Internally this module wraps the [XRayUDPStorage](https://github.com/openzipkin/zipkin-aws/tree/master/storage-xray-udp)
and exposes configuration options through environment variables.

## Experimental
* Note: This is currently experimental! *
* Note: This requires reporters send 128-bit trace IDs, with the first 32bits as epoch seconds *
* Check https://github.com/openzipkin/b3-propagation/issues/6 for tracers that support epoch128 trace IDs

## Usage

Download the module from [TODO] link and extract it to a directory relative to the
Zipkin Server jar.

### Configuration

Configuration can be applied either through environment variables or an external Zipkin
configuration file. The module includes default configuration that can be used as a
[reference](https://github.com/openzipkin/zipkin-aws/tree/master/autoconfigure/storage-xray/src/main/resources/zipkin-server-xray.yml)
for users that prefer a file based approach.

##### Environment Variables

- `AWS_XRAY_DAEMON_ADDRESS` The UDP endpoint to send spans to. _Defaults to localhost:2000_

### Running

```bash
STORAGE_TYPE=xray
java -Dloader.path=xray -Dspring.profiles.active=xray -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher
```

### Testing

Once your storage is enabled, verify it is running:
```bash
$ curl -s localhost:9411/health|jq .zipkin.XrayStorage
{
"status": "UP"
}
```
71 changes: 71 additions & 0 deletions autoconfigure/storage-xray/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016-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>
<artifactId>zipkin-autoconfigure</artifactId>
<groupId>io.zipkin.aws</groupId>
<version>0.8.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>zipkin-autoconfigure-storage-xray</artifactId>
<name>Auto Configuration: XRay Storage</name>

<properties>
<main.basedir>${project.basedir}/../..</main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>zipkin-storage-xray-udp</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<layout>MODULE</layout>
<classifier>module</classifier>
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work -->
<excludeGroupIds>
io.zipkin.java,io.zipkin.zipkin2,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion
</excludeGroupIds>
<!-- already packaged in zipkin-server -->
<excludeArtifactIds>aws-java-sdk-core,aws-java-sdk-sts,jmespath-java</excludeArtifactIds>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2016-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.autoconfigure.storage.xray;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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.internal.V2StorageComponent;
import zipkin.storage.StorageComponent;
import zipkin2.storage.xray_udp.XRayUDPStorage;

@Configuration
@EnableConfigurationProperties(zipkin.autoconfigure.storage.xray.ZipkinXRayStorageProperties.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "xray")
@ConditionalOnMissingBean(StorageComponent.class)
public class ZipkinXRayStorageAutoConfiguration {

@Bean
@ConditionalOnMissingBean
V2StorageComponent storage(
zipkin.autoconfigure.storage.xray.ZipkinXRayStorageProperties properties,
@Value("${zipkin.storage.strict-trace-id:true}") boolean strictTraceId) {
XRayUDPStorage result = properties.toBuilder().strictTraceId(strictTraceId).build();
return V2StorageComponent.create(result);
}

@Bean XRayUDPStorage v2Storage(V2StorageComponent component) {
return (XRayUDPStorage) component.delegate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2016-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.autoconfigure.storage.xray;

import java.io.Serializable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import zipkin2.storage.xray_udp.XRayUDPStorage;

@ConfigurationProperties("zipkin.storage.xray")
public class ZipkinXRayStorageProperties implements Serializable { // for Spark jobs
private static final long serialVersionUID = 0L;

/** Amazon X-Ray Daemon UDP daemon address; defaults to localhost:2000 */
private String daemonAddress;

public String getDaemonAddress() {
return daemonAddress;
}

public void setDaemonAddress(String daemonAddress) {
this.daemonAddress = "".equals(daemonAddress) ? null : daemonAddress;
}

public XRayUDPStorage.Builder toBuilder() {
XRayUDPStorage.Builder builder = XRayUDPStorage.newBuilder();
if (daemonAddress != null) builder.address(daemonAddress);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
zipkin.autoconfigure.storage.xray.ZipkinXRayStorageAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# When enabled, this allows shorter env properties (ex -Dspring.profiles.active=xray)
zipkin:
storage:
xray:
# Amazon X-Ray Daemon UDP daemon address; defaults to localhost:2000
daemon-address: ${AWS_XRAY_DAEMON_ADDRESS:}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2016-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 zipkin2.storage.xray;

import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import zipkin.autoconfigure.storage.xray.ZipkinXRayStorageAutoConfiguration;
import zipkin.autoconfigure.storage.xray.ZipkinXRayStorageProperties;
import zipkin2.storage.xray_udp.XRayUDPStorage;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class ZipkinXRayStorageAutoConfigurationTest {

@Rule public ExpectedException thrown = ExpectedException.none();

AnnotationConfigApplicationContext context;

@After public void close() {
if (context != null) {
context.close();
}
}

@Test public void doesntProvideStorageComponent_whenStorageTypeNotXRay() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.storage.type:elasticsearch");
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinXRayStorageAutoConfiguration.class);
context.refresh();

thrown.expect(NoSuchBeanDefinitionException.class);
context.getBean(XRayUDPStorage.class);
}

@Test public void providesStorageComponent_whenStorageTypeXRay() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.storage.type:xray");
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinXRayStorageAutoConfiguration.class);
context.refresh();

assertThat(context.getBean(XRayUDPStorage.class)).isNotNull();
}

@Test public void canOverrideProperty_daemonAddress() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context,
"zipkin.storage.type:xray",
"zipkin.storage.xray.daemon-address:localhost:3000"
);
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinXRayStorageAutoConfiguration.class);
context.refresh();

assertThat(context.getBean(ZipkinXRayStorageProperties.class).getDaemonAddress())
.isEqualTo("localhost:3000");
}
}
2 changes: 1 addition & 1 deletion aws-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.zipkin.aws</groupId>
<artifactId>zipkin-aws-parent</artifactId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-aws-junit</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion collector-kinesis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>zipkin-aws-parent</artifactId>
<groupId>io.zipkin.aws</groupId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion collector-sqs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>zipkin-aws-parent</artifactId>
<groupId>io.zipkin.aws</groupId>
<version>0.7.2-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 3e1b56d

Please sign in to comment.