-
Notifications
You must be signed in to change notification settings - Fork 784
Added support for multiple reporters #1181
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
Merged
marcingrzejszczak
merged 14 commits into
spring-cloud:master
from
TYsewyn:feature/multiple-reporters
Jan 21, 2019
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
64f24a5
Added support for multiple span reporters
TYsewyn 07d2aa8
Updated zipkin config to support multiple span reporters/senders
TYsewyn 5c05186
Incorporated PR feedback
TYsewyn 92c9095
No reason to create a `SpanBytesEncoder` bean
TYsewyn d7eccee
Moved `ReporterMetrics sleuthReporterMetrics()` to `TraceAutoConfigur…
TYsewyn ca2244d
Updated license header
TYsewyn 14700ed
Added `@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)`
TYsewyn 9cb5e27
Merge branch 'master' into feature/multiple-reporters
TYsewyn 7c31475
Updated `ZipkinAutoConfiguration` for backwards compatibility
TYsewyn 8327ecb
Updated documentation
TYsewyn d8381b8
Create the restTemplateSender bean when there is no other bean named …
TYsewyn 453d942
Adapted new configuration to support backwards compatibility in case …
TYsewyn 3b47f77
Updated conditional for `ZipkinBackwardsCompatibilityAutoConfiguration`
TYsewyn 490a1d8
Updated access modifiers in `ZipkinBackwardsCompatibilityAutoConfigur…
TYsewyn 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
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
145 changes: 145 additions & 0 deletions
145
...g/springframework/cloud/sleuth/zipkin2/ZipkinBackwardsCompatibilityAutoConfiguration.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,145 @@ | ||
| /* | ||
| * Copyright 2013-2019 the original author or 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.sleuth.zipkin2; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import zipkin2.Span; | ||
| import zipkin2.codec.BytesEncoder; | ||
| import zipkin2.reporter.AsyncReporter; | ||
| import zipkin2.reporter.InMemoryReporterMetrics; | ||
| import zipkin2.reporter.Reporter; | ||
| import zipkin2.reporter.ReporterMetrics; | ||
| import zipkin2.reporter.Sender; | ||
|
|
||
| import org.springframework.beans.factory.support.DefaultListableBeanFactory; | ||
| import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionOutcome; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.boot.autoconfigure.condition.SpringBootCondition; | ||
| import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.ConditionContext; | ||
| import org.springframework.context.annotation.Conditional; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.ConfigurationCondition; | ||
| import org.springframework.core.type.AnnotatedTypeMetadata; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
| * Auto-configuration} that will provide backwards compatibility to be able to support | ||
| * multiple tracing systems on the classpath. | ||
| * | ||
| * Needs to be auto-configured before {@link ZipkinAutoConfiguration} in order to create a | ||
| * {@link Reporter<Span> span reporter} if needed. | ||
| * | ||
| * @author Tim Ysewyn | ||
| * @since 2.1.0 | ||
| * @see ZipkinAutoConfiguration | ||
| * @deprecated | ||
| */ | ||
| @Configuration | ||
| @ConditionalOnProperty(value = { "spring.sleuth.enabled" }, matchIfMissing = true) | ||
| @AutoConfigureAfter({ ZipkinAutoConfiguration.class }) | ||
| @Deprecated | ||
| class ZipkinBackwardsCompatibilityAutoConfiguration { | ||
|
|
||
| /** | ||
| * Reporter that is depending on a {@link Sender} bean which is created in another | ||
| * auto-configuration than {@link ZipkinAutoConfiguration}. | ||
| */ | ||
| @Bean | ||
| @Conditional(BackwardsCompatibilityCondition.class) | ||
| @Deprecated | ||
| Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin, | ||
| BytesEncoder<Span> spanBytesEncoder, DefaultListableBeanFactory beanFactory) { | ||
| List<String> beanNames = new ArrayList<>( | ||
| Arrays.asList(beanFactory.getBeanNamesForType(Sender.class))); | ||
| beanNames.remove(ZipkinAutoConfiguration.SENDER_BEAN_NAME); | ||
| Sender sender = (Sender) beanFactory.getBean(beanNames.get(0)); | ||
| // historical constraint. Note: AsyncReporter supports memory bounds | ||
| return AsyncReporter.builder(sender).queuedMaxSpans(1000) | ||
| .messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS) | ||
| .metrics(reporterMetrics).build(spanBytesEncoder); | ||
| } | ||
|
|
||
| /** | ||
| * Only used for creating a reporter bean with the method above | ||
| * @deprecated | ||
| */ | ||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| @Deprecated | ||
| BytesEncoder<Span> spanBytesEncoder(ZipkinProperties zipkinProperties) { | ||
| return zipkinProperties.getEncoder(); | ||
| } | ||
|
|
||
| /** | ||
| * Deprecated because this is moved to {@link TraceAutoConfiguration}. Left for | ||
| * backwards compatibility reasons. | ||
| * @deprecated | ||
| */ | ||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| @Deprecated | ||
| ReporterMetrics zipkinReporterMetrics() { | ||
| return new InMemoryReporterMetrics(); | ||
| } | ||
|
|
||
| static class BackwardsCompatibilityCondition extends SpringBootCondition | ||
| implements ConfigurationCondition { | ||
|
|
||
| @Override | ||
| public ConfigurationPhase getConfigurationPhase() { | ||
| return ConfigurationPhase.REGISTER_BEAN; | ||
| } | ||
|
|
||
| @Override | ||
| public ConditionOutcome getMatchOutcome(ConditionContext context, | ||
| AnnotatedTypeMetadata metadata) { | ||
| Assert.isInstanceOf(DefaultListableBeanFactory.class, | ||
| context.getBeanFactory()); | ||
| DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) context | ||
| .getBeanFactory(); | ||
| int foundSenders = listableBeanFactory | ||
| .getBeanNamesForType(Sender.class).length; | ||
|
|
||
| // Previously we supported 1 Sender bean at a time | ||
| // which could be overridden by another auto-configuration. | ||
| // Now we support both the overridden bean and our default zipkinSender bean. | ||
| if (foundSenders < 2) { | ||
| return ConditionOutcome.noMatch( | ||
| "We don't support backwards compatibility for more than 2 Sender beans"); | ||
| } | ||
| int foundReporters = listableBeanFactory | ||
| .getBeanNamesForType(Reporter.class).length; | ||
| // Check if we need to provide a Reporter bean for the overridden Sender bean | ||
| if (foundReporters == foundSenders) { | ||
| return ConditionOutcome.noMatch( | ||
| "Both tracing systems already define their own Reporter bean"); | ||
| } | ||
| return ConditionOutcome.match(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
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
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.
optional: I would pull this into a static or package private class as it isn't debug friendly. a toString would be nice, and it would also be nice to not have to loop for the common case where there is only one reporter. Another optional would be to catch exceptions in the loop such that one report failure doesn't fail others.