Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
ea766c1e
Commit
ea766c1e
authored
Apr 25, 2018
by
技术部-高工-张恒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
brave config
parent
80b14d63
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
403 additions
and
4 deletions
+403
-4
pom.xml
commons-brave/pom.xml
+213
-0
BraveAutoConfiguration.java
...roup/tech/brave/configuration/BraveAutoConfiguration.java
+150
-0
BraveProperties.java
.../cn/quantgroup/tech/brave/properties/BraveProperties.java
+35
-0
pom.xml
commons-core/pom.xml
+1
-1
pom.xml
commons-spring/pom.xml
+1
-1
pom.xml
pom.xml
+2
-1
pom.xml
shutdown-spring-boot-starter/pom.xml
+1
-1
No files found.
commons-brave/pom.xml
0 → 100644
View file @
ea766c1e
<?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"
>
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.1.6
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
commons-brave
</artifactId>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<spring.version>
4.3.8.RELEASE
</spring.version>
<brave.version>
4.19.1
</brave.version>
<zipkin-reporter2.version>
2.5.0
</zipkin-reporter2.version>
<log4j.version>
2.8.2
</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.4
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
16.0.1
</version>
</dependency>
<dependency>
<groupId>
commons-beanutils
</groupId>
<artifactId>
commons-beanutils
</artifactId>
</dependency>
<dependency>
<groupId>
commons-cli
</groupId>
<artifactId>
commons-cli
</artifactId>
<version>
1.3.1
</version>
</dependency>
<dependency>
<groupId>
commons-net
</groupId>
<artifactId>
commons-net
</artifactId>
<version>
3.3
</version>
</dependency>
<dependency>
<groupId>
com.jcraft
</groupId>
<artifactId>
jsch
</artifactId>
<version>
0.1.53
</version>
</dependency>
<dependency>
<groupId>
ch.ethz.ganymed
</groupId>
<artifactId>
ganymed-ssh2
</artifactId>
<version>
262
</version>
</dependency>
<dependency>
<groupId>
commons-codec
</groupId>
<artifactId>
commons-codec
</artifactId>
<version>
1.10
</version>
</dependency>
<dependency>
<groupId>
commons-collections
</groupId>
<artifactId>
commons-collections
</artifactId>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.4
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.16.6
</version>
</dependency>
<dependency>
<groupId>
commons-validator
</groupId>
<artifactId>
commons-validator
</artifactId>
<version>
1.4.1
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
3.10.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.amqp
</groupId>
<artifactId>
spring-rabbit
</artifactId>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-spring-beans
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-spring-web
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-spring-webmvc
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.reporter2
</groupId>
<artifactId>
zipkin-sender-kafka11
</artifactId>
<version>
${zipkin-reporter2.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-core
</artifactId>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-context-log4j2
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-jul
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-jcl
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-slf4j-impl
</artifactId>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.1.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-httpclient
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-mysql
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-okhttp3
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
<version>
${brave.version}
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
commons-brave/src/main/java/cn/quantgroup/tech/brave/configuration/BraveAutoConfiguration.java
0 → 100644
View file @
ea766c1e
package
cn
.
quantgroup
.
tech
.
brave
.
configuration
;
import
brave.Tracing
;
import
brave.context.log4j2.ThreadContextCurrentTraceContext
;
import
brave.http.HttpTracing
;
import
brave.httpclient.TracingHttpClientBuilder
;
import
brave.okhttp3.TracingInterceptor
;
import
brave.propagation.B3Propagation
;
import
brave.propagation.ExtraFieldPropagation
;
import
brave.spring.rabbit.SpringRabbitTracing
;
import
brave.spring.web.TracingClientHttpRequestInterceptor
;
import
brave.spring.webmvc.DelegatingTracingFilter
;
import
brave.spring.webmvc.SpanCustomizingAsyncHandlerInterceptor
;
import
cn.quantgroup.tech.brave.properties.BraveProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.Dispatcher
;
import
okhttp3.OkHttpClient
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureOrder
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
zipkin2.Span
;
import
zipkin2.codec.Encoding
;
import
zipkin2.reporter.AsyncReporter
;
import
zipkin2.reporter.Sender
;
import
zipkin2.reporter.kafka11.KafkaSender
;
import
javax.annotation.PostConstruct
;
import
javax.servlet.Filter
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 注册brave
*
* @author zhangheng
* create on 2018.04.25
*/
@Slf4j
@Configuration
@AutoConfigureOrder
@EnableWebMvc
@EnableConfigurationProperties
(
BraveProperties
.
class
)
@Import
(
{
TracingClientHttpRequestInterceptor
.
class
,
SpanCustomizingAsyncHandlerInterceptor
.
class
}
)
public
class
BraveAutoConfiguration
extends
WebMvcConfigurerAdapter
{
@Autowired
private
BraveProperties
braveProperties
;
@Autowired
SpanCustomizingAsyncHandlerInterceptor
spanCustomizingAsyncHandlerInterceptor
;
@Autowired
TracingClientHttpRequestInterceptor
clientInterceptor
;
@Bean
Sender
sender
()
{
return
KafkaSender
.
newBuilder
().
bootstrapServers
(
braveProperties
.
getKafkaHost
()).
topic
(
braveProperties
.
getKafkaTopic
()).
encoding
(
Encoding
.
JSON
).
build
();
}
@Bean
AsyncReporter
<
Span
>
spanReporter
()
{
return
AsyncReporter
.
create
(
sender
());
}
@Bean
Tracing
tracing
()
{
return
Tracing
.
newBuilder
()
.
sampler
(
brave
.
sampler
.
Sampler
.
create
(
braveProperties
.
getSample
()))
.
localServiceName
(
braveProperties
.
getServiceName
())
.
propagationFactory
(
ExtraFieldPropagation
.
newFactory
(
B3Propagation
.
FACTORY
,
"user-name"
))
.
currentTraceContext
(
ThreadContextCurrentTraceContext
.
create
())
// puts trace IDs into logs
.
spanReporter
(
spanReporter
()).
build
();
}
@Bean
public
HttpTracing
httpTracing
(
Tracing
tracing
)
{
return
HttpTracing
.
create
(
tracing
);
}
@Bean
public
SpringRabbitTracing
springRabbitTracing
(
Tracing
tracing
)
{
return
SpringRabbitTracing
.
newBuilder
(
tracing
)
.
remoteServiceName
(
"my-mq-service"
).
build
();
}
@Bean
(
name
=
"techHttpClient"
)
public
CloseableHttpClient
httpClient
(
Tracing
tracing
)
{
log
.
info
(
"注册HttpClient"
);
return
TracingHttpClientBuilder
.
create
(
tracing
).
build
();
}
@Bean
(
name
=
"techOkHttpClient"
)
public
OkHttpClient
httpClient
(
HttpTracing
httpTracing
)
{
log
.
info
(
"注册OkHttpClient"
);
return
new
OkHttpClient
.
Builder
()
.
dispatcher
(
new
Dispatcher
(
httpTracing
.
tracing
().
currentTraceContext
().
executorService
(
new
Dispatcher
().
executorService
())))
.
addNetworkInterceptor
(
TracingInterceptor
.
create
(
httpTracing
)).
build
();
}
/**
* 创建一个bean
*
* @return
*/
@Bean
public
Filter
delegatingTracingFilter
()
{
return
new
DelegatingTracingFilter
();
}
@Bean
public
FilterRegistrationBean
someFilterRegistration
(
Filter
delegatingTracingFilter
)
{
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
registration
.
setFilter
(
delegatingTracingFilter
);
registration
.
addUrlPatterns
(
"/*"
);
registration
.
setName
(
"DelegatingTracingFilter"
);
return
registration
;
}
/**
* adds tracing to the application-defined rest template
*/
@PostConstruct
public
void
init
()
{
log
.
info
(
"添加restTemplate拦截器"
);
RestTemplate
restTemplate
=
new
RestTemplate
();
List
<
ClientHttpRequestInterceptor
>
interceptors
=
new
ArrayList
<>(
restTemplate
.
getInterceptors
());
interceptors
.
add
(
clientInterceptor
);
restTemplate
.
setInterceptors
(
interceptors
);
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
log
.
info
(
"添加webmvc拦截器"
);
registry
.
addInterceptor
(
spanCustomizingAsyncHandlerInterceptor
);
}
}
commons-brave/src/main/java/cn/quantgroup/tech/brave/properties/BraveProperties.java
0 → 100644
View file @
ea766c1e
package
cn
.
quantgroup
.
tech
.
brave
.
properties
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* brave配置信息
*
* @author zhangheng
* create on 2018.04.25
*/
@Data
@ConfigurationProperties
(
prefix
=
"tech.brave"
)
public
class
BraveProperties
{
/**
* 指定serviceName
*/
private
String
serviceName
;
/**
* kafka地址
*/
private
String
kafkaHost
;
/**
* kafka的topic
*/
private
String
kafkaTopic
;
/**
* 采集率
*/
private
Float
sample
=
1.0f
;
}
commons-core/pom.xml
View file @
ea766c1e
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.1.
5
</version>
<version>
0.1.
6
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
commons-spring/pom.xml
View file @
ea766c1e
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.1.
5
</version>
<version>
0.1.
6
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
pom.xml
View file @
ea766c1e
...
...
@@ -6,7 +6,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-parent
</artifactId>
<version>
0.1.
5
</version>
<version>
0.1.
6
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -18,6 +18,7 @@
<module>
commons-core
</module>
<module>
commons-spring
</module>
<module>
shutdown-spring-boot-starter
</module>
<module>
commons-brave
</module>
</modules>
<packaging>
pom
</packaging>
...
...
shutdown-spring-boot-starter/pom.xml
View file @
ea766c1e
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.1.
5
</version>
<version>
0.1.
6
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment