-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #955 from lioolli/master
Moved spring mvc servlet profiling feature to spring plugin
- Loading branch information
Showing
29 changed files
with
210 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
agent/src/test/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2014 NAVER Corp. | ||
* 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 | ||
* | ||
* 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.navercorp.pinpoint.plugin.spring.web; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.mock.web.MockHttpServletResponse; | ||
import org.springframework.mock.web.MockServletConfig; | ||
import org.springframework.web.servlet.DispatcherServlet; | ||
import org.springframework.web.servlet.FrameworkServlet; | ||
|
||
import com.navercorp.pinpoint.bootstrap.plugin.test.Expectations; | ||
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; | ||
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder; | ||
import com.navercorp.pinpoint.test.plugin.Dependency; | ||
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; | ||
|
||
/** | ||
* @author Jongho Moon | ||
* | ||
*/ | ||
@RunWith(PinpointPluginTestSuite.class) | ||
@Dependency({"org.springframework:spring-webmvc:[3.0.7.RELEASE],[3.1.4.RELEASE],[3.2.14.RELEASE],[4.0.9.RELEASE],[4.1.7.RELEASE],[4.2.0.RELEASE,)", "org.springframework:spring-test", "javax.servlet:javax.servlet-api:3.0.1"}) | ||
public class SpringWebMvcIT { | ||
private static final String SPRING_MVC = "SPRING_MVC"; | ||
|
||
@Test | ||
public void testRequest() throws Exception { | ||
MockServletConfig config = new MockServletConfig(); | ||
MockHttpServletRequest req = new MockHttpServletRequest(); | ||
MockHttpServletResponse res = new MockHttpServletResponse(); | ||
|
||
config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml"); | ||
req.setMethod("GET"); | ||
req.setRequestURI("/"); | ||
req.setRemoteAddr("1.2.3.4"); | ||
|
||
DispatcherServlet servlet = new DispatcherServlet(); | ||
servlet.init(config); | ||
|
||
servlet.service(req, res); | ||
|
||
Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class); | ||
|
||
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); | ||
verifier.printCache(); | ||
|
||
verifier.verifyTrace(Expectations.event(SPRING_MVC, method)); | ||
verifier.verifyTraceCount(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xmlns:beans="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<!-- Enables the Spring MVC @Controller programming model --> | ||
<mvc:annotation-driven/> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
...ins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright 2014 NAVER Corp. | ||
* 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 | ||
* | ||
* 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.navercorp.pinpoint.plugin.spring.web; | ||
|
||
import static com.navercorp.pinpoint.common.trace.HistogramSchema.*; | ||
|
||
import java.security.ProtectionDomain; | ||
|
||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; | ||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException; | ||
import com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor; | ||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; | ||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginInstrumentContext; | ||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; | ||
import com.navercorp.pinpoint.bootstrap.plugin.transformer.PinpointClassFileTransformer; | ||
import com.navercorp.pinpoint.common.trace.ServiceType; | ||
|
||
/** | ||
* @author Jongho Moon | ||
* | ||
*/ | ||
public class SpringWebMvcPlugin implements ProfilerPlugin { | ||
public static final ServiceType SPRING_MVC = ServiceType.of(5051, "SPRING_MVC", "SPRING", NORMAL_SCHEMA); | ||
|
||
@Override | ||
public void setup(ProfilerPluginSetupContext context) { | ||
context.addClassFileTransformer("org.springframework.web.servlet.FrameworkServlet", new PinpointClassFileTransformer() { | ||
|
||
@Override | ||
public byte[] transform(ProfilerPluginInstrumentContext instrumentContext, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException { | ||
InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); | ||
|
||
target.getDeclaredMethod("doGet", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), SPRING_MVC); | ||
target.getDeclaredMethod("doPost", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), SPRING_MVC); | ||
|
||
return target.toBytecode(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcTraceMetadataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright 2014 NAVER Corp. | ||
* 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 | ||
* | ||
* 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.navercorp.pinpoint.plugin.spring.web; | ||
|
||
import com.navercorp.pinpoint.common.trace.TraceMetadataProvider; | ||
import com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext; | ||
|
||
/** | ||
* @author Jongho Moon | ||
* | ||
*/ | ||
public class SpringWebMvcTraceMetadataProvider implements TraceMetadataProvider { | ||
|
||
/* (non-Javadoc) | ||
* @see com.navercorp.pinpoint.common.trace.TraceMetadataProvider#setup(com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext) | ||
*/ | ||
@Override | ||
public void setup(TraceMetadataSetupContext context) { | ||
context.addServiceType(SpringWebMvcPlugin.SPRING_MVC); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
....pinpoint.bootstrap.plugin.ProfilerPlugin → ....pinpoint.bootstrap.plugin.ProfilerPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
com.navercorp.pinpoint.plugin.spring.beans.SpringBeansPlugin | ||
com.navercorp.pinpoint.plugin.spring.web.SpringWebMvcPlugin |
1 change: 1 addition & 0 deletions
1
...npoint.common.trace.TraceMetadataProvider → ...npoint.common.trace.TraceMetadataProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
com.navercorp.pinpoint.plugin.spring.beans.SpringBeansTraceMetadataProvider | ||
com.navercorp.pinpoint.plugin.spring.web.SpringWebMvcTraceMetadataProvider |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.