Skip to content

Commit c85db8c

Browse files
authored
Merge branch 'master' into feature/split-agent-module
2 parents eaa0254 + 1996e6e commit c85db8c

File tree

9 files changed

+250
-15
lines changed

9 files changed

+250
-15
lines changed

apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,12 @@ private HttpGet buildGet() {
141141
*/
142142
private void findBackupServer() {
143143
selectedServer++;
144-
if (selectedServer == serverList.length) {
144+
if (selectedServer >= serverList.length) {
145145
selectedServer = 0;
146146
}
147-
}
148-
149-
/**
150-
* Try to sleep, and ignore the {@link InterruptedException}
151-
*
152-
* @param millis the length of time to sleep in milliseconds
153-
*/
154-
private void try2Sleep(long millis) {
155-
try {
156-
Thread.sleep(millis);
157-
} catch (InterruptedException e) {
158147

148+
if (serverList.length == 0) {
149+
selectedServer = -1;
159150
}
160151
}
161152
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2017, OpenSkywalking Organization All rights reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
~ Project repository: https://github.com/OpenSkywalking/skywalking
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<parent>
24+
<artifactId>spring-plugins</artifactId>
25+
<groupId>org.skywalking</groupId>
26+
<version>3.2.5-2017</version>
27+
</parent>
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<artifactId>apm-spring-core-patch</artifactId>
31+
<name>core-patch</name>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.springframework</groupId>
36+
<artifactId>spring-aop</artifactId>
37+
<version>3.2.9.RELEASE</version>
38+
<scope>provided</scope>
39+
</dependency>
40+
</dependencies>
41+
42+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017, OpenSkywalking Organization All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Project repository: https://github.com/OpenSkywalking/skywalking
17+
*/
18+
19+
package org.skywalking.apm.plugin.spring.patch;
20+
21+
import java.lang.reflect.Method;
22+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
23+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
24+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
25+
import org.springframework.aop.framework.AdvisedSupport;
26+
27+
/**
28+
* {@link CreateAopProxyInterceptor} check that the bean has been implement {@link EnhancedInstance}. <p/>
29+
* if yes, true will be returned.
30+
*
31+
* @author zhang xin
32+
*/
33+
public class CreateAopProxyInterceptor implements InstanceMethodsAroundInterceptor {
34+
35+
@Override
36+
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
37+
MethodInterceptResult result) throws Throwable {
38+
39+
}
40+
41+
@Override
42+
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
43+
Object ret) throws Throwable {
44+
AdvisedSupport advisedSupport = (AdvisedSupport)allArguments[0];
45+
46+
if (EnhancedInstance.class.isAssignableFrom(advisedSupport.getTargetClass())) {
47+
return true;
48+
}
49+
return ret;
50+
}
51+
52+
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
53+
Class<?>[] argumentsTypes, Throwable t) {
54+
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2017, OpenSkywalking Organization All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Project repository: https://github.com/OpenSkywalking/skywalking
17+
*/
18+
19+
package org.skywalking.apm.plugin.spring.patch.define;
20+
21+
import net.bytebuddy.description.method.MethodDescription;
22+
import net.bytebuddy.matcher.ElementMatcher;
23+
import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
24+
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
26+
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
27+
28+
import static net.bytebuddy.matcher.ElementMatchers.named;
29+
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
30+
31+
/**
32+
* {@link AopProxyFactoryInstrumentation} indicate that spring core patch plugin intercepts the {@link
33+
* org.springframework.aop.framework.DefaultAopProxyFactory#hasNoUserSuppliedProxyInterfaces} method by using {@link
34+
* org.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor} class.
35+
*
36+
* @author zhangxin
37+
*/
38+
public class AopProxyFactoryInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
39+
40+
private static final String ENHANCE_CLASS = "org.springframework.aop.framework.DefaultAopProxyFactory";
41+
public static final String ENHANCE_METHOD = "hasNoUserSuppliedProxyInterfaces";
42+
public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor";
43+
44+
@Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
45+
return new ConstructorInterceptPoint[0];
46+
}
47+
48+
@Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
49+
return new InstanceMethodsInterceptPoint[] {
50+
new InstanceMethodsInterceptPoint() {
51+
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
52+
return named(ENHANCE_METHOD);
53+
}
54+
55+
@Override public String getMethodsInterceptor() {
56+
return INTERCEPT_CLASS;
57+
}
58+
59+
@Override public boolean isOverrideArgs() {
60+
return false;
61+
}
62+
}
63+
};
64+
}
65+
66+
@Override protected ClassMatch enhanceClass() {
67+
return byName(ENHANCE_CLASS);
68+
}
69+
70+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring-core-patch=org.skywalking.apm.plugin.spring.patch.define.AopProxyFactoryInstrumentation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2017, OpenSkywalking Organization All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Project repository: https://github.com/OpenSkywalking/skywalking
17+
*/
18+
19+
package org.skywalking.apm.plugin.spring.patch;
20+
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.Mock;
25+
import org.mockito.runners.MockitoJUnitRunner;
26+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
27+
import org.springframework.aop.framework.AdvisedSupport;
28+
29+
import static org.hamcrest.core.Is.is;
30+
import static org.junit.Assert.assertThat;
31+
import static org.mockito.Mockito.doReturn;
32+
33+
@RunWith(MockitoJUnitRunner.class)
34+
public class CreateAopProxyInterceptorTest {
35+
36+
private CreateAopProxyInterceptor interceptor;
37+
38+
@Mock
39+
private EnhancedInstance enhancedInstance;
40+
41+
@Mock
42+
private AdvisedSupport advisedSupport;
43+
44+
@Before
45+
public void setUp() {
46+
interceptor = new CreateAopProxyInterceptor();
47+
48+
}
49+
50+
@Test
51+
public void testInterceptNormalObject() throws Throwable {
52+
doReturn(Object.class).when(advisedSupport).getTargetClass();
53+
assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false)));
54+
}
55+
56+
@Test
57+
public void testInterceptEnhanceInstanceObject() throws Throwable {
58+
doReturn(MockClass.class).when(advisedSupport).getTargetClass();
59+
assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false)));
60+
}
61+
62+
private class MockClass implements EnhancedInstance {
63+
64+
@Override public Object getSkyWalkingDynamicField() {
65+
return null;
66+
}
67+
68+
@Override public void setSkyWalkingDynamicField(Object value) {
69+
70+
}
71+
}
72+
73+
}

apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<module>mvc-annotation-4.x-plugin</module>
3535
<module>spring-cloud</module>
3636
<module>mvc-annotation-3.x-plugin</module>
37+
<module>core-patch</module>
3738
</modules>
3839
<packaging>pom</packaging>
3940

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
* Project repository: https://github.com/OpenSkywalking/skywalking
1717
*/
1818

19-
package org.springframework.http.client;
19+
package org.skywalking.apm.plugin.spring.resttemplate.async;
2020

2121
import java.lang.reflect.Method;
2222
import org.skywalking.apm.agent.core.context.CarrierItem;
2323
import org.skywalking.apm.agent.core.context.ContextCarrier;
2424
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2525
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2626
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
27+
import org.springframework.http.client.AsyncClientHttpRequest;
2728

2829
public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor {
2930

@@ -36,7 +37,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
3637
@Override
3738
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
3839
Object ret) throws Throwable {
39-
AbstractAsyncClientHttpRequest clientHttpRequest = (AbstractAsyncClientHttpRequest)ret;
40+
AsyncClientHttpRequest clientHttpRequest = (AsyncClientHttpRequest)ret;
4041
if (ret != null) {
4142
Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
4243
ContextCarrier contextCarrier = (ContextCarrier)cacheValues[1];

apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePlug
4747
private static final String DO_EXECUTE_METHOD_NAME = "doExecute";
4848
private static final String DO_EXECUTE_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.RestExecuteInterceptor";
4949
private static final String CREATE_REQUEST_METHOD_NAME = "createAsyncRequest";
50-
private static final String CREATE_REQUEST_INTERCEPTOR = "org.springframework.http.client.RestRequestInterceptor";
50+
private static final String CREATE_REQUEST_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.RestRequestInterceptor";
5151

5252
@Override
5353
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {

0 commit comments

Comments
 (0)