Add ConnectionDetail support to Zipkin auto-configuration
Update Zipkin auto-configuration so that `ZipkinConnectionDetails` beans may be optionally used to provide connection details. See gh-34657 Co-Authored-By: Mortitz Halbritter <mkammerer@vmware.com> Co-Authored-By: Phillip Webb <pwebb@vmware.com>
This commit is contained in:
parent
ac55caa463
commit
8721c0e64f
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2012-2023 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
|
||||
*
|
||||
* https://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.boot.actuate.autoconfigure.tracing.zipkin;
|
||||
|
||||
/**
|
||||
* Adapts {@link ZipkinProperties} to {@link ZipkinConnectionDetails}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class PropertiesZipkinConnectionDetails implements ZipkinConnectionDetails {
|
||||
|
||||
private final ZipkinProperties properties;
|
||||
|
||||
PropertiesZipkinConnectionDetails(ZipkinProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpanEndpoint() {
|
||||
return this.properties.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
|
@ -59,11 +59,14 @@ class ZipkinConfigurations {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(Sender.class)
|
||||
URLConnectionSender urlConnectionSender(ZipkinProperties properties) {
|
||||
URLConnectionSender urlConnectionSender(ZipkinProperties properties,
|
||||
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
|
||||
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
|
||||
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
|
||||
URLConnectionSender.Builder builder = URLConnectionSender.newBuilder();
|
||||
builder.connectTimeout((int) properties.getConnectTimeout().toMillis());
|
||||
builder.readTimeout((int) properties.getReadTimeout().toMillis());
|
||||
builder.endpoint(properties.getEndpoint());
|
||||
builder.endpoint(connectionDetails.getSpanEndpoint());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
@ -77,12 +80,15 @@ class ZipkinConfigurations {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean(Sender.class)
|
||||
ZipkinRestTemplateSender restTemplateSender(ZipkinProperties properties,
|
||||
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) {
|
||||
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers,
|
||||
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
|
||||
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
|
||||
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
|
||||
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
|
||||
.setConnectTimeout(properties.getConnectTimeout())
|
||||
.setReadTimeout(properties.getReadTimeout());
|
||||
restTemplateBuilder = applyCustomizers(restTemplateBuilder, customizers);
|
||||
return new ZipkinRestTemplateSender(properties.getEndpoint(), restTemplateBuilder.build());
|
||||
return new ZipkinRestTemplateSender(connectionDetails.getSpanEndpoint(), restTemplateBuilder.build());
|
||||
}
|
||||
|
||||
private RestTemplateBuilder applyCustomizers(RestTemplateBuilder restTemplateBuilder,
|
||||
|
@ -106,10 +112,13 @@ class ZipkinConfigurations {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean(Sender.class)
|
||||
ZipkinWebClientSender webClientSender(ZipkinProperties properties,
|
||||
ObjectProvider<ZipkinWebClientBuilderCustomizer> customizers) {
|
||||
ObjectProvider<ZipkinWebClientBuilderCustomizer> customizers,
|
||||
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
|
||||
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
|
||||
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
|
||||
WebClient.Builder builder = WebClient.builder();
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
|
||||
return new ZipkinWebClientSender(properties.getEndpoint(), builder.build());
|
||||
return new ZipkinWebClientSender(connectionDetails.getSpanEndpoint(), builder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright 2012-2023 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
|
||||
*
|
||||
* https://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.boot.actuate.autoconfigure.tracing.zipkin;
|
||||
|
||||
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
|
||||
|
||||
/**
|
||||
* Details required to establish a connection to a Zipkin server.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public interface ZipkinConnectionDetails extends ConnectionDetails {
|
||||
|
||||
/**
|
||||
* The endpoint for the span reporting.
|
||||
* @return the endpoint
|
||||
*/
|
||||
String getSpanEndpoint();
|
||||
|
||||
}
|
Loading…
Reference in New Issue