-
Notifications
You must be signed in to change notification settings - Fork 144
WIP: Auto-config for Extensions API tracer wrapper, metrics (with promethe… #15
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
Closed
objectiser
wants to merge
3
commits into
opentracing-contrib:master
from
objectiser:metricsprototype
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,61 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-spring-cloud-parent</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>opentracing-spring-cloud-api-extensions</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-api-extensions</artifactId> | ||
| <version>${version.io.opentracing.contrib-opentracing-api-extensions}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-api-extensions-tracer</artifactId> | ||
| <version>${version.io.opentracing.contrib-opentracing-api-extensions}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-autoconfigure</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing</groupId> | ||
| <artifactId>opentracing-mock</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.opentracing</groupId> | ||
| <artifactId>opentracing-util</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.awaitility</groupId> | ||
| <artifactId>awaitility</artifactId> | ||
| <version>${version.org.awaitility-awaitility}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
60 changes: 60 additions & 0 deletions
60
...main/java/io/opentracing/contrib/spring/cloud/api/extensions/TracerBeanPostProcessor.java
This file contains hidden or 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,60 @@ | ||
| /** | ||
| * Copyright 2017 The OpenTracing 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 io.opentracing.contrib.spring.cloud.api.extensions; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import org.springframework.beans.BeansException; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.config.BeanPostProcessor; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import io.opentracing.Tracer; | ||
| import io.opentracing.contrib.api.TracerObserver; | ||
| import io.opentracing.contrib.api.tracer.APIExtensionsTracer; | ||
|
|
||
| @Configuration | ||
| public class TracerBeanPostProcessor implements BeanPostProcessor { | ||
|
|
||
| private static final Logger log = Logger.getLogger(TracerBeanPostProcessor.class.getName()); | ||
|
|
||
| @Autowired(required=false) | ||
| private Set<TracerObserver> tracerObservers; | ||
|
|
||
| @Override | ||
| public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
| if (tracerObservers != null && bean instanceof Tracer) { | ||
| boolean observerFound = false; | ||
| APIExtensionsTracer tracer = new APIExtensionsTracer((Tracer)bean); | ||
| for (TracerObserver observer : tracerObservers) { | ||
| if (observer != null) { | ||
| observerFound = true; | ||
| tracer.addTracerObserver(observer); | ||
| } | ||
| } | ||
| if (observerFound) { | ||
| log.info("Use extensions API tracer with observers=" + tracerObservers); | ||
| return tracer; | ||
| } | ||
| } | ||
| return bean; | ||
| } | ||
|
|
||
| @Override | ||
| public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | ||
| return bean; | ||
| } | ||
|
|
||
| } | ||
2 changes: 2 additions & 0 deletions
2
opentracing-spring-cloud-api-extensions/src/main/resources/META-INF/spring.factories
This file contains hidden or 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=\ | ||
| io.opentracing.contrib.spring.cloud.api.extensions.TracerBeanPostProcessor |
51 changes: 51 additions & 0 deletions
51
...entracing/contrib/spring/cloud/api/extensions/TracerBeanPostProcessorNoObserversTest.java
This file contains hidden or 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,51 @@ | ||
| /** | ||
| * Copyright 2017 The OpenTracing 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 io.opentracing.contrib.spring.cloud.api.extensions; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
| import io.opentracing.Tracer; | ||
| import io.opentracing.mock.MockTracer; | ||
| import io.opentracing.util.ThreadLocalActiveSpanSource; | ||
|
|
||
| @SpringBootTest( | ||
| classes = {TracerBeanPostProcessorNoObserversTest.SpringConfiguration.class}) | ||
| @RunWith(SpringJUnit4ClassRunner.class) | ||
| public class TracerBeanPostProcessorNoObserversTest { | ||
|
|
||
| @Configuration | ||
| @EnableAutoConfiguration | ||
| public static class SpringConfiguration { | ||
| @Bean | ||
| public MockTracer tracer() { | ||
| return new MockTracer(new ThreadLocalActiveSpanSource()); | ||
| } | ||
| } | ||
|
|
||
| @Autowired | ||
| protected Tracer tracer; | ||
|
|
||
| @Test | ||
| public void testTracerNotWrapped() { | ||
| assertEquals(MockTracer.class, tracer.getClass()); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
.../java/io/opentracing/contrib/spring/cloud/api/extensions/TracerBeanPostProcessorTest.java
This file contains hidden or 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,76 @@ | ||
| /** | ||
| * Copyright 2017 The OpenTracing 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 io.opentracing.contrib.spring.cloud.api.extensions; | ||
|
|
||
| import static org.junit.Assert.assertNotEquals; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Matchers; | ||
| import org.mockito.Mockito; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
|
||
| import io.opentracing.Tracer; | ||
| import io.opentracing.contrib.api.SpanData; | ||
| import io.opentracing.contrib.api.TracerObserver; | ||
| import io.opentracing.mock.MockTracer; | ||
| import io.opentracing.util.ThreadLocalActiveSpanSource; | ||
|
|
||
| @SpringBootTest( | ||
| classes = {TracerBeanPostProcessorTest.SpringConfiguration.class}) | ||
| @RunWith(SpringJUnit4ClassRunner.class) | ||
| public class TracerBeanPostProcessorTest { | ||
|
|
||
| private static final MockTracer mockTracer = new MockTracer(new ThreadLocalActiveSpanSource()); | ||
|
|
||
| private static final TracerObserver tracerObserver = Mockito.mock(TracerObserver.class); | ||
|
|
||
| @Configuration | ||
| @EnableAutoConfiguration | ||
| public static class SpringConfiguration { | ||
| @Bean | ||
| public Tracer tracer() { | ||
| return mockTracer; | ||
| } | ||
|
|
||
| @Bean | ||
| public TracerObserver observer() { | ||
| return tracerObserver; | ||
| } | ||
| } | ||
|
|
||
| @Autowired | ||
| protected Tracer tracer; | ||
|
|
||
| @Before | ||
| public void before() { | ||
| mockTracer.reset(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTracerWrapped() { | ||
| assertNotEquals(MockTracer.class, tracer.getClass()); | ||
|
|
||
| tracer.buildSpan("testop").startManual(); | ||
|
|
||
| Mockito.verify(tracerObserver).onStart(Matchers.any(SpanData.class)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,89 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-spring-cloud-parent</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>opentracing-spring-cloud-metrics-prometheus</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-spring-cloud-metrics</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-metrics-prometheus</artifactId> | ||
| <version>${version.io.opentracing.contrib-opentracing-metrics}</version> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>io.prometheus</groupId> | ||
| <artifactId>*</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.prometheus</groupId> | ||
| <artifactId>simpleclient</artifactId> | ||
| <version>${version.io.prometheus}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.prometheus</groupId> | ||
| <artifactId>simpleclient_servlet</artifactId> | ||
| <version>${version.io.prometheus}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>javax.servlet</groupId> | ||
| <artifactId>javax.servlet-api</artifactId> | ||
| <version>${version.javax.servlet-api}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-web-servlet-filter</artifactId> | ||
| <version>${version.io.opentracing.contrib-opentracing-web-servlet-filter}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-autoconfigure</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing</groupId> | ||
| <artifactId>opentracing-mock</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.awaitility</groupId> | ||
| <artifactId>awaitility</artifactId> | ||
| <version>${version.org.awaitility-awaitility}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| <version>${version.org.springframework.boot}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
32 changes: 32 additions & 0 deletions
32
.../java/io/opentracing/contrib/spring/cloud/metrics/prometheus/PrometheusConfiguration.java
This file contains hidden or 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,32 @@ | ||
| /** | ||
| * Copyright 2017 The OpenTracing 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 io.opentracing.contrib.spring.cloud.metrics.prometheus; | ||
|
|
||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import io.prometheus.client.CollectorRegistry; | ||
|
|
||
| @Configuration | ||
| @ConditionalOnClass(value = {CollectorRegistry.class}) | ||
| public class PrometheusConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| public CollectorRegistry defaultCollectorRegistry() { | ||
| return CollectorRegistry.defaultRegistry; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not slf4j logger?
Uh oh!
There was an error while loading. Please reload this page.
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.
All logging frameworks provide a logback for JUL, and JUL is the only logging framework that doesn't require an external dependency. So, it's usually a better choice for a library.
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.
By the way: my point is moot if slf4j is already a dependency (I'm not sure that's the case)
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 think we should use what is default/preferred in spring boot, and I guess it's not JUL
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.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html
commons logging - so could switch.