Skip to content
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

support reactor #228

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<module>sofa-tracer-plugins/sofa-tracer-zipkin-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-dubbo-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-webflux-plugin</module>
<module>tracer-all</module>
<module>tracer-sofa-boot-starter</module>
<module>tracer-samples</module>
Expand All @@ -35,6 +36,7 @@

<properties>
<opentracing.version>0.22.0</opentracing.version>
<reactor.version>3.2.6.RELEASE</reactor.version>
shengxiang205 marked this conversation as resolved.
Show resolved Hide resolved
<sofa.tracer.version>3.0.6-SNAPSHOT</sofa.tracer.version>
<java.compiler.source.version>1.8</java.compiler.source.version>
<java.compiler.target.version>1.8</java.compiler.target.version>
Expand Down Expand Up @@ -99,6 +101,16 @@
<artifactId>sofa-tracer-springmvc-plugin</artifactId>
<version>${sofa.tracer.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-webflux-plugin</artifactId>
<version>${sofa.tracer.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-reactor-plugin</artifactId>
shengxiang205 marked this conversation as resolved.
Show resolved Hide resolved
<version>${sofa.tracer.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-httpclient-plugin</artifactId>
Expand Down Expand Up @@ -170,6 +182,14 @@
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>${reactor.version}</version>
<scope>provided</scope>
</dependency>

<!-- HttpClient Dependency -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
12 changes: 7 additions & 5 deletions sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-core</artifactId>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-httpclient-plugin</artifactId>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-extensions</artifactId>
Expand All @@ -25,11 +31,7 @@
<artifactId>javax.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<optional>true</optional>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private SpringMvcTracer() {
super("springmvc");
}

protected SpringMvcTracer(String name) {
super(name);
}

@Override
protected String getServerDigestReporterLogName() {
return SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName();
Expand All @@ -71,27 +75,31 @@ protected String getServerDigestReporterLogNameKey() {
@Override
protected SpanEncoder<SofaTracerSpan> getServerDigestEncoder() {
if (Boolean.TRUE.toString().equalsIgnoreCase(
SofaTracerConfiguration.getProperty(SPRING_MVC_JSON_FORMAT_OUTPUT))) {
SofaTracerConfiguration.getProperty(jsonPropertyName()))) {
return new SpringMvcDigestJsonEncoder();
} else {
return new SpringMvcDigestEncoder();
}
}

protected String jsonPropertyName() {
return SPRING_MVC_JSON_FORMAT_OUTPUT;
}

@Override
protected AbstractSofaTracerStatisticReporter generateServerStatReporter() {
return generateSofaMvcStatReporter();
}

private SpringMvcStatReporter generateSofaMvcStatReporter() {
protected SpringMvcStatReporter generateSofaMvcStatReporter() {
SpringMvcLogEnum springMvcLogEnum = SpringMvcLogEnum.SPRING_MVC_STAT;
String statLog = springMvcLogEnum.getDefaultLogName();
String statRollingPolicy = SofaTracerConfiguration.getRollingPolicy(springMvcLogEnum
.getRollingKey());
String statLogReserveConfig = SofaTracerConfiguration.getLogReserveConfig(springMvcLogEnum
.getLogNameKey());
if (Boolean.TRUE.toString().equalsIgnoreCase(
SofaTracerConfiguration.getProperty(SPRING_MVC_JSON_FORMAT_OUTPUT))) {
SofaTracerConfiguration.getProperty(jsonPropertyName()))) {
return new SpringMvcJsonStatReporter(statLog, statRollingPolicy, statLogReserveConfig);
} else {
return new SpringMvcStatReporter(statLog, statRollingPolicy, statLogReserveConfig);
Expand Down
33 changes: 33 additions & 0 deletions sofa-tracer-plugins/sofa-tracer-webflux-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sofa-tracer-webflux-plugin</artifactId>

<dependencies>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-springmvc-plugin</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里感觉不用依赖 springmvc 的插件,部分重复代码冗余一份,既然分开两个插件,就应该相互独立开

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复用度很高, 抽取一个sofa-tracer-web-base-plugin ?

</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.sofa.tracer.plugins.webflux;

import com.alipay.common.tracer.core.reactor.SofaTracerBarrier;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.reactive.HandlerResult;
import reactor.core.publisher.Mono;

/**
* in webflux, every request will run in defer
*
* @author xiang.sheng
* @since 3.0.0
*/
@Aspect
public class SofaTracerControllerAspect {

@Pointcut("execution(* org.springframework.web.reactive.HandlerAdapter.handle(..))")
private void invokePointCut() {
}

@Around("invokePointCut()")
public Object wrapReactorContext(ProceedingJoinPoint pjp) {
return SofaTracerBarrier.withSofaTracerContainer().flatMap(c -> {
try {
//noinspection unchecked
return (Mono<HandlerResult>) pjp.proceed();
} catch (Throwable throwable) {
return Mono.error(throwable);
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.sofa.tracer.plugins.webflux;

/**
* add log enum
*
* @author xiang.sheng
* @since 3.0.0
*/
public enum SpringWebFluxLogEnum {
// SOFA MVC 日志
SPRING_WEBFLUX_DIGEST("spring_webflux_digest_log_name", "spring-webflux-digest.log",
"spring_webflux_digest_rolling"), //
SPRING_WEBFLUX_STAT("spring_webflux_stat_log_name", "spring-webflux-stat.log",
"spring_webflux_stat_rolling");

private String logNameKey;
private String defaultLogName;
private String rollingKey;

SpringWebFluxLogEnum(String logNameKey, String defaultLogName, String rollingKey) {
this.logNameKey = logNameKey;
this.defaultLogName = defaultLogName;
this.rollingKey = rollingKey;
}

public String getLogNameKey() {
//log reserve config key
return logNameKey;
}

public String getDefaultLogName() {
return defaultLogName;
}

public String getRollingKey() {
return rollingKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.sofa.tracer.plugins.webflux;

import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcJsonStatReporter;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcStatReporter;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcTracer;

/**
* webflux tracer, extend spring mvc tracer
*
* @author @author xiang.sheng
* @since 3.0.0
*/
public class SpringWebfluxTracer extends SpringMvcTracer {
public static final String SPRING_WEBFLUX_JSON_FORMAT_OUTPUT = "spring_webflux_json_format_output";
private volatile static SpringWebfluxTracer springWebfluxTracer = null;

/***
* Spring MVC Tracer Singleton
* @return singleton
*/
public static SpringWebfluxTracer getSpringWebfluxTracerSingleton() {
if (springWebfluxTracer == null) {
synchronized (SpringWebfluxTracer.class) {
if (springWebfluxTracer == null) {
springWebfluxTracer = new SpringWebfluxTracer();
}
}
}
return springWebfluxTracer;
}

private SpringWebfluxTracer() {
super("springwebflux");
}

@Override
protected String getServerDigestReporterLogName() {
return SpringWebFluxLogEnum.SPRING_WEBFLUX_DIGEST.getDefaultLogName();
}

@Override
protected String getServerDigestReporterRollingKey() {
return SpringWebFluxLogEnum.SPRING_WEBFLUX_DIGEST.getRollingKey();
}

@Override
protected String getServerDigestReporterLogNameKey() {
return SpringWebFluxLogEnum.SPRING_WEBFLUX_DIGEST.getLogNameKey();
}

@Override
protected String jsonPropertyName() {
return SPRING_WEBFLUX_JSON_FORMAT_OUTPUT;
}

@SuppressWarnings("Duplicates")
@Override
protected SpringMvcStatReporter generateSofaMvcStatReporter() {
SpringWebFluxLogEnum springWebFluxLogEnum = SpringWebFluxLogEnum.SPRING_WEBFLUX_STAT;
String statLog = springWebFluxLogEnum.getDefaultLogName();
String statRollingPolicy = SofaTracerConfiguration.getRollingPolicy(springWebFluxLogEnum
.getRollingKey());
String statLogReserveConfig = SofaTracerConfiguration
.getLogReserveConfig(springWebFluxLogEnum.getLogNameKey());
if (Boolean.TRUE.toString().equalsIgnoreCase(
SofaTracerConfiguration.getProperty(jsonPropertyName()))) {
return new SpringMvcJsonStatReporter(statLog, statRollingPolicy, statLogReserveConfig);
} else {
return new SpringMvcStatReporter(statLog, statRollingPolicy, statLogReserveConfig);
}
}
}
Loading