Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new module supporting jaeger - opentracing #101

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@
<module>spring-cloud-kubernetes-discovery</module>
<module>spring-cloud-kubernetes-ribbon</module>
<module>spring-cloud-kubernetes-zipkin</module>
<module>spring-cloud-kubernetes-jaeger</module>
<module>spring-cloud-kubernetes-hystrix</module>
<module>spring-cloud-kubernetes-archaius</module>
<module>spring-cloud-starter-kubernetes</module>
<module>spring-cloud-starter-kubernetes-config</module>
<module>spring-cloud-starter-kubernetes-netflix</module>
<module>spring-cloud-starter-kubernetes-zipkin</module>
<module>spring-cloud-starter-kubernetes-all</module>
<module>spring-cloud-starter-kubernetes-jaeger</module>
<module>spring-cloud-kubernetes-examples</module>
</modules>

Expand Down
31 changes: 31 additions & 0 deletions spring-cloud-kubernetes-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<mockwebserver.version>0.0.12</mockwebserver.version>
<restassured.version>3.0.2</restassured.version>
<spock-spring.version>1.0-groovy-2.3</spock-spring.version>
<version.jaeger>0.19.0</version.jaeger>
<io.opentracing.version>0.22.0</io.opentracing.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi 0.22 is api incompatible with 0.30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine here, these versions match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the version as jaeger-core - 0.19.0 has a dep with opentracing 0.22

[INFO] com.uber.jaeger:jaeger-core:jar:0.19.0
[INFO] +- com.uber.jaeger:jaeger-thrift:jar:0.19.0:compile
[INFO] |  \- org.apache.thrift:libthrift:jar:0.9.2:compile
[INFO] |     +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO] |     |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |     |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] |     \- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO] +- io.opentracing:opentracing-api:jar:0.22.0:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.16:compile

<io.opentracing.contrib.spring.autoconfigure.version>0.0.4</io.opentracing.contrib.spring.autoconfigure.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -74,6 +77,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-jaeger</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Own dependencies - Starters -->
<dependency>
Expand Down Expand Up @@ -106,6 +114,27 @@
<version>${project.version}</version>
</dependency>

<!-- OpenTracing -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-noop</artifactId>
<version>${io.opentracing.version}</version>
</dependency>

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-web-autoconfigure</artifactId>
<version>${io.opentracing.contrib.spring.autoconfigure.version}</version>
</dependency>

<!-- OpenTracing implementation - Jaeger -->
<dependency>
<groupId>com.uber.jaeger</groupId>
<artifactId>jaeger-core</artifactId>
<version>${version.jaeger}</version>
</dependency>


<!-- Testing Dependencies -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
Expand Down Expand Up @@ -159,6 +188,8 @@
<artifactId>spock-spring</artifactId>
<version>${spock-spring.version}</version>
</dependency>


</dependencies>
</dependencyManagement>
<profiles>
Expand Down
Empty file.
83 changes: 83 additions & 0 deletions spring-cloud-kubernetes-jaeger/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 to the original 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>spring-cloud-kubernetes</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>0.2.0.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-jaeger</artifactId>
<name>Spring Cloud Kubernetes :: Jaeger</name>

<dependencies>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<optional>true</optional>
</dependency>

<!-- OpenTracing -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-noop</artifactId>
</dependency>

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-web-autoconfigure</artifactId>
</dependency>

<!-- OpenTracing implementation - Jaeger -->
<dependency>
<groupId>com.uber.jaeger</groupId>
<artifactId>jaeger-core</artifactId>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (C) 2016 to the original 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 org.springframework.cloud.kubernetes.jaeger;

import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.uber.jaeger.metrics.Metrics;
import com.uber.jaeger.metrics.NullStatsReporter;
import com.uber.jaeger.metrics.StatsFactoryImpl;
import com.uber.jaeger.reporters.RemoteReporter;
import com.uber.jaeger.samplers.ProbabilisticSampler;
import com.uber.jaeger.senders.Sender;
import com.uber.jaeger.senders.UdpSender;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.utils.Utils;
import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.web.autoconfig.TracerAutoConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Configuration
@AutoConfigureBefore(TracerAutoConfiguration.class)
@EnableConfigurationProperties(KubernetesJaegerDiscoveryProperties.class)
public class JaegerKubernetesAutoConfiguration {

private static final Log LOG = LogFactory.getLog(JaegerKubernetesAutoConfiguration.class);

@Bean
public Tracer tracer(KubernetesClient client, KubernetesJaegerDiscoveryProperties discoveryProperties) throws Exception {

String serviceName = discoveryProperties.getServiceName();
String traceServerName = discoveryProperties.getTracerServerName();
String serviceNamespace = Utils.isNotNullOrEmpty(discoveryProperties.getServiceNamespace()) ? discoveryProperties.getServiceNamespace() : client.getNamespace();

List<ServiceInstance> services = getInstances(client, traceServerName, serviceNamespace);
String serviceUrl = services.stream()
.findFirst()
.map(s -> s.getUri().toString())
.orElse(null);

if (serviceUrl == null || serviceUrl.isEmpty()) {
LOG.info("Jaeger k8s starter creating Noop Tracer");
return NoopTracerFactory.create();
}

return jaegerTracer(serviceUrl, serviceName);
}

private static List<ServiceInstance> getInstances(KubernetesClient client, String name, String namespace) {
Assert.notNull(name, "[Assertion failed] - the service name must not be null");

return Optional.ofNullable(client.endpoints().inNamespace(namespace).withName(name).get())
.orElse(new Endpoints())
.getSubsets()
.stream()
.flatMap(s -> s.getAddresses().stream().map(a -> (ServiceInstance) new KubernetesServiceInstance(name, a ,s.getPorts().stream().findFirst().orElseThrow(IllegalStateException::new), false)))
.collect(Collectors.toList());
}

private Tracer jaegerTracer(String serviceURL, String serviceName) throws Exception {
URL url = new URL(serviceURL);
Sender sender = new UdpSender(url.getHost(), url.getPort(), 0);
return new com.uber.jaeger.Tracer.Builder(serviceName,
new RemoteReporter(sender, 100, 50,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these properties should be configurable, see https://github.com/uber/jaeger-client-java/tree/master/jaeger-core#configuration-via-environment at least queue size and flush interval.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

new Metrics(new StatsFactoryImpl(new NullStatsReporter()))),
new ProbabilisticSampler(1.0))
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2016 to the original 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 org.springframework.cloud.kubernetes.jaeger;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* @author <a href="mailto:[email protected]">Charles Moulliard</a>
*/
@ConfigurationProperties("spring.cloud.kubernetes.jaeger.discovery")
public class KubernetesJaegerDiscoveryProperties {

private String tracerServerName = "jaeger-all-in-one";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be called agentServiceName data could be sent to agent and collector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that.

private String serviceName;
private String serviceNamespace;

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public String getTracerServerName() {
return tracerServerName;
}

public void setTracerServerName(String tracerServerName) {
this.tracerServerName = tracerServerName;
}

public String getServiceNamespace() {
return serviceNamespace;
}

public void setServiceNamespace(String serviceNamespace) {
this.serviceNamespace = serviceNamespace;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.kubernetes.jaeger.JaegerKubernetesAutoConfiguration
50 changes: 50 additions & 0 deletions spring-cloud-starter-kubernetes-jaeger/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 to the original 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>spring-cloud-kubernetes</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>0.2.0.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-jaeger</artifactId>
<name>Spring Cloud Kubernetes :: Starter :: Jaeger</name>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-jaeger</artifactId>
</dependency>
</dependencies>

</project>