-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
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. 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. 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. +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"; | ||
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. Should be called 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. 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 |
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> |
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.
fyi 0.22 is api incompatible with 0.30
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.
This is fine here, these versions match
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.
I will update the version as jaeger-core - 0.19.0 has a dep with opentracing 0.22