Added option to send spans to Zipkin over ActiveMQ

fixes gh-1380
This commit is contained in:
Marcin Grzejszczak
2019-07-29 12:32:38 +02:00
parent e13f7f8048
commit a912000f0f
6 changed files with 130 additions and 0 deletions

View File

@@ -89,6 +89,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-activemq-client</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>

View File

@@ -0,0 +1,61 @@
/*
* 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
*
* 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.cloud.sleuth.zipkin2.sender;
import org.apache.activemq.ActiveMQConnectionFactory;
import zipkin2.reporter.Sender;
import zipkin2.reporter.activemq.ActiveMQSender;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.cloud.sleuth.zipkin2.ZipkinAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnClass(ActiveMQConnectionFactory.class)
@ConditionalOnMissingBean(name = ZipkinAutoConfiguration.SENDER_BEAN_NAME)
@Conditional(ZipkinSenderCondition.class)
@ConditionalOnProperty(value = "spring.zipkin.sender.type", havingValue = "activemq")
@AutoConfigureAfter(ActiveMQAutoConfiguration.class)
class ZipkinActiveMqSenderConfiguration {
@Configuration
@ConditionalOnBean(ActiveMQConnectionFactory.class)
static class ZipkinActiveMqSenderBeanConfiguration {
@Value("${spring.zipkin.activemq.queue:zipkin}")
private String queue;
@Value("${spring.zipkin.activemq.message-max-bytes:100000}")
private int messageMaxBytes;
@Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME)
Sender activeMqSender(ActiveMQConnectionFactory factory) {
return ActiveMQSender.newBuilder().connectionFactory(factory)
.messageMaxBytes(this.messageMaxBytes).queue(this.queue).build();
}
}
}

View File

@@ -36,6 +36,7 @@ public class ZipkinSenderConfigurationImportSelector implements ImportSelector {
static {
// Mappings in descending priority (highest is last)
Map<String, String> mappings = new LinkedHashMap<>();
mappings.put("activemq", ZipkinActiveMqSenderConfiguration.class.getName());
mappings.put("rabbit", ZipkinRabbitSenderConfiguration.class.getName());
mappings.put("kafka", ZipkinKafkaSenderConfiguration.class.getName());
mappings.put("web", ZipkinRestTemplateSenderConfiguration.class.getName());

View File

@@ -45,6 +45,11 @@ public class ZipkinSenderProperties {
*/
public enum SenderType {
/**
* ActiveMQ sender.
*/
ACTIVEMQ,
/**
* RabbitMQ sender.
*/

View File

@@ -0,0 +1,28 @@
{
"properties": [
{
"name": "spring.zipkin.kafka.topic",
"type": "java.lang.String",
"description": "Name of the Kafka topic where spans should be sent to Zipkin.",
"defaultValue": "zipkin"
},
{
"name": "spring.zipkin.rabbitmq.queue",
"type": "java.lang.String",
"description": "Name of the RabbitMQ queue where spans should be sent to Zipkin.",
"defaultValue": "zipkin"
},
{
"name": "spring.zipkin.activemq.queue",
"type": "java.lang.String",
"description": "Name of the ActiveMQ queue where spans should be sent to Zipkin.",
"defaultValue": "zipkin"
},
{
"name": "spring.zipkin.activemq.message-max-bytes",
"type": "java.lang.String",
"description": "Maximum number of bytes for a given message with spans sent to Zipkin over ActiveMQ.",
"defaultValue": 100000
}
]
}

View File

@@ -36,11 +36,13 @@ import zipkin2.codec.Encoding;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.Sender;
import zipkin2.reporter.activemq.ActiveMQSender;
import zipkin2.reporter.amqp.RabbitMQSender;
import zipkin2.reporter.kafka.KafkaSender;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
@@ -155,6 +157,24 @@ public class ZipkinAutoConfigurationTests {
this.context.close();
}
@Test
public void overrideActiveMqQueue() throws Exception {
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.jms.cache.enabled", "false");
environment().setProperty("spring.zipkin.activemq.queue", "zipkin2");
environment().setProperty("spring.zipkin.activemq.message-max-bytes", "50");
environment().setProperty("spring.zipkin.sender.type", "activemq");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ActiveMQAutoConfiguration.class, ZipkinAutoConfiguration.class,
TraceAutoConfiguration.class,
ZipkinBackwardsCompatibilityAutoConfiguration.class);
this.context.refresh();
then(this.context.getBean(Sender.class)).isInstanceOf(ActiveMQSender.class);
this.context.close();
}
@Test
public void canOverrideBySender() throws Exception {
this.context = new AnnotationConfigApplicationContext();