Skip to content

Commit

Permalink
Merge branch 'master' into top_period
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-sheng committed Nov 19, 2019
2 parents d24886b + a2dce71 commit e4a505b
Show file tree
Hide file tree
Showing 48 changed files with 1,795 additions and 25 deletions.
8 changes: 7 additions & 1 deletion Jenkinsfile-Agent-Test-2
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pipeline {
sh './mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build'
}
}
stage('Test Cases Report (136)') {
stage('Test Cases Report (146)') {
steps {
echo "Test Cases Report"
}
Expand All @@ -82,6 +82,12 @@ pipeline {
parallel {
stage('Group1') {
stages {
stage('spring-tx 4.x+ (10)') {
steps {
sh 'bash test/plugin/run.sh spring-tx-scenario'
}
}

stage('spring 4.3.x-5.2.x (54)') {
steps {
sh 'bash test/plugin/run.sh spring-4.3.x-scenario'
Expand Down
8 changes: 7 additions & 1 deletion Jenkinsfile-Agent-Test-3
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pipeline {
sh './mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build'
}
}
stage('Test Cases Report (140)') {
stage('Test Cases Report (160)') {
steps {
echo "Test Cases Report"
}
Expand All @@ -82,6 +82,12 @@ pipeline {
parallel {
stage('Group1') {
stages {
stage('hystrix 1.4.20-1.5.12 (20)') {
steps {
sh 'bash test/plugin/run.sh hystrix-scenario'
}
}

stage('postgresql 9.2.x-9.4.x (36)') {
steps {
sh 'bash test/plugin/run.sh postgresql-scenario'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ public class ComponentsDefine {
public static final OfficialComponent SOCKET_IO = new OfficialComponent(76, "SocketIO");

public static final OfficialComponent REST_HIGH_LEVEL_CLIENT = new OfficialComponent(77, "rest-high-level-client");

public static final OfficialComponent SPRING_TX = new OfficialComponent(78, "spring-tx");
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,13 @@ public static class Light4J {
*/
public static boolean TRACE_HANDLER_CHAIN = false;
}

public static class SpringTransaction {

/**
* If true, the transaction definition name will be simplified
*/
public static boolean SIMPLIFY_TRANSACTION_DEFINITION_NAME = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.Method;
Expand All @@ -32,7 +33,7 @@ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
@Override
public String getRequestURL(Method method) {
String requestURL = "";
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
RequestMapping methodRequestMapping = AnnotationUtils.getAnnotation(method, RequestMapping.class);
if (methodRequestMapping.value().length > 0) {
requestURL = methodRequestMapping.value()[0];
} else if (methodRequestMapping.path().length > 0) {
Expand All @@ -43,7 +44,7 @@ public String getRequestURL(Method method) {

@Override
public String getAcceptedMethodTypes(Method method) {
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
RequestMapping methodRequestMapping = AnnotationUtils.getAnnotation(method, RequestMapping.class);
StringBuilder methodTypes = new StringBuilder();
if (methodRequestMapping.method().length > 0) {
methodTypes.append("{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;
Expand All @@ -34,11 +35,11 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
@Override
public String getRequestURL(Method method) {
String requestURL = "";
GetMapping getMapping = method.getAnnotation(GetMapping.class);
PostMapping postMapping = method.getAnnotation(PostMapping.class);
PutMapping putMapping = method.getAnnotation(PutMapping.class);
DeleteMapping deleteMapping = method.getAnnotation(DeleteMapping.class);
PatchMapping patchMapping = method.getAnnotation(PatchMapping.class);
GetMapping getMapping = AnnotationUtils.getAnnotation(method, GetMapping.class);
PostMapping postMapping = AnnotationUtils.getAnnotation(method, PostMapping.class);
PutMapping putMapping = AnnotationUtils.getAnnotation(method, PutMapping.class);
DeleteMapping deleteMapping = AnnotationUtils.getAnnotation(method, DeleteMapping.class);
PatchMapping patchMapping = AnnotationUtils.getAnnotation(method, PatchMapping.class);
if (getMapping != null) {
if (getMapping.value().length > 0) {
requestURL = getMapping.value()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<modules>
<module>spring-annotation-plugin</module>
<module>spring-tx-plugin</module>
<module>optional-spring-cloud</module>
</modules>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->

<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>optional-spring-plugins</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

<artifactId>apm-spring-tx-plugin</artifactId>

<properties>
<spring-tx.version>5.1.2.RELEASE</spring-tx.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-tx.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 org.apache.skywalking.apm.plugin.spring.transaction;

import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.spring.transaction.context.Constants;
import org.springframework.transaction.TransactionStatus;

import java.lang.reflect.Method;

/**
* @author zhaoyuguang
*/
public class EndTransactionMethodInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan(Constants.OPERATION_NAME_SPRING_TRANSACTION_PREFIX + method.getName());
TransactionStatus status = (TransactionStatus) allArguments[0];
span.tag(Constants.TAG_SPRING_TRANSACTION_IS_NEW_TRANSACTION, String.valueOf(status.isNewTransaction()));
span.tag(Constants.TAG_SPRING_TRANSACTION_HAS_SAVEPOINT, String.valueOf(status.hasSavepoint()));
span.tag(Constants.TAG_SPRING_TRANSACTION_ROLLBACK_ONLY, String.valueOf(status.isRollbackOnly()));
span.tag(Constants.TAG_SPRING_TRANSACTION_IS_COMPLETED, String.valueOf(status.isCompleted()));
span.setComponent(ComponentsDefine.SPRING_TX);
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 org.apache.skywalking.apm.plugin.spring.transaction;

import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.spring.transaction.context.Constants;
import org.springframework.transaction.TransactionDefinition;

import java.lang.reflect.Method;

/**
* @author zhaoyuguang
*/
public class GetTransactionMethodInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
if (allArguments[0] == null) {
AbstractSpan span = ContextManager.createLocalSpan(Constants.OPERATION_NAME_SPRING_TRANSACTION_NO_TRANSACTION_DEFINITION_GIVEN);
span.setComponent(ComponentsDefine.SPRING_TX);
return;
}
TransactionDefinition definition = (TransactionDefinition) allArguments[0];
AbstractSpan span = ContextManager.createLocalSpan(Constants.OPERATION_NAME_SPRING_TRANSACTION_GET_TRANSACTION_METHOD + buildOperationName(definition.getName()));
span.tag(Constants.TAG_SPRING_TRANSACTION_ISOLATION_LEVEL, String.valueOf(definition.getIsolationLevel()));
span.tag(Constants.TAG_SPRING_TRANSACTION_PROPAGATION_BEHAVIOR, String.valueOf(definition.getPropagationBehavior()));
span.tag(Constants.TAG_SPRING_TRANSACTION_TIMEOUT, String.valueOf(definition.getTimeout()));
span.setComponent(ComponentsDefine.SPRING_TX);
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}

private String buildOperationName(String transactionDefinitionName) {
if (!Config.Plugin.SpringTransaction.SIMPLIFY_TRANSACTION_DEFINITION_NAME) {
return transactionDefinitionName;
}
String[] ss = transactionDefinitionName.split("\\.");

int simplifiedLength = ss.length - 2;
if (simplifiedLength < 0) {
return transactionDefinitionName;
}
StringBuilder name = new StringBuilder();
for (int i = 0; i < ss.length - 1; i++) {
name.append(i < simplifiedLength ? ss[i].charAt(0) : ss[i]).append(".");
}
return name.append(ss[ss.length - 1]).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 org.apache.skywalking.apm.plugin.spring.transaction.context;

/**
* @author zhaoyuguang
*/

public interface Constants {
String OPERATION_NAME_SPRING_TRANSACTION_PREFIX = "TX/";
String OPERATION_NAME_SPRING_TRANSACTION_GET_TRANSACTION_METHOD = OPERATION_NAME_SPRING_TRANSACTION_PREFIX + "get/";
String OPERATION_NAME_SPRING_TRANSACTION_NO_TRANSACTION_DEFINITION_GIVEN = OPERATION_NAME_SPRING_TRANSACTION_GET_TRANSACTION_METHOD + "noTransactionDefinitionGiven";
String TAG_SPRING_TRANSACTION_ISOLATION_LEVEL = "isolationLevel";
String TAG_SPRING_TRANSACTION_PROPAGATION_BEHAVIOR = "propagationBehavior";
String TAG_SPRING_TRANSACTION_TIMEOUT = "timeout";
String TAG_SPRING_TRANSACTION_IS_NEW_TRANSACTION = "isNewTransaction";
String TAG_SPRING_TRANSACTION_HAS_SAVEPOINT = "hasSavepoint";
String TAG_SPRING_TRANSACTION_ROLLBACK_ONLY = "rollbackOnly";
String TAG_SPRING_TRANSACTION_IS_COMPLETED = "isCompleted";
}
Loading

0 comments on commit e4a505b

Please sign in to comment.