From 3de65d44ac3bdde6efd59559aa8a916c86599325 Mon Sep 17 00:00:00 2001 From: "Tiger(EunHo Lee)" Date: Wed, 16 Sep 2015 16:19:07 +0900 Subject: [PATCH 1/4] The Servlet parameter provides an option for the profile. --- .../bootstrap/config/ProfilerConfig.java | 8 ++++++++ .../interceptor/HttpServletInterceptor.java | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java index 4f735fbe0cd4..03cb09df93b8 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java @@ -101,6 +101,8 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept private boolean tcpDataSenderCommandAcceptEnable = false; + private boolean servletProfileParameter = false; + private int jdbcSqlCacheSize = 1024; private int jdbcMaxSqlBindValueSize = 1024; private boolean jdbcProfile = true; @@ -298,6 +300,10 @@ public boolean isProfileEnable() { return profileEnable; } + public boolean isServletProfileParameter() { + return servletProfileParameter; + } + public boolean isJdbcProfile() { return jdbcProfile; } @@ -648,6 +654,8 @@ void readPropertyValues() { this.tcpDataSenderCommandAcceptEnable = readBoolean("profiler.tcpdatasender.command.accept.enable", false); + this.servletProfileParameter = readBoolean("profiler.servlet.parameter", false); + // JDBC this.jdbcProfile = readBoolean("profiler.jdbc", true); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java index 4ea91a9a8481..d70acdccf87c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java @@ -16,8 +16,7 @@ package com.navercorp.pinpoint.profiler.modifier.servlet.interceptor; -import java.util.Enumeration; - +import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.context.Header; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; @@ -32,9 +31,10 @@ import com.navercorp.pinpoint.bootstrap.util.NumberUtils; import com.navercorp.pinpoint.common.AnnotationKey; import com.navercorp.pinpoint.common.ServiceType; -import com.navercorp.pinpoint.profiler.context.*; +import com.navercorp.pinpoint.profiler.context.SpanId; import javax.servlet.http.HttpServletRequest; +import java.util.Enumeration; /** * @author emeroad @@ -47,6 +47,7 @@ public class HttpServletInterceptor implements SimpleAroundInterceptor, ByteCode private MethodDescriptor descriptor; private TraceContext traceContext; + private boolean parameter; /* java.lang.IllegalStateException: already Trace Object exist. @@ -154,9 +155,12 @@ public void after(Object target, Object[] args, Object result, Throwable throwab traceContext.detachTraceObject(); HttpServletRequest request = (HttpServletRequest) args[0]; - String parameters = getRequestParameter(request); - if (parameters != null && parameters.length() > 0) { - trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); + + if (parameter) { + String parameters = getRequestParameter(request); + if (parameters != null && parameters.length() > 0) { + trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); + } } @@ -233,5 +237,7 @@ public void setMethodDescriptor(MethodDescriptor descriptor) { @Override public void setTraceContext(TraceContext traceContext) { this.traceContext = traceContext; + ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); + this.parameter = profilerConfig.isServletProfileParameter(); } } From 540467486b426bcc318cc5abd7eb2bfc110c6b21 Mon Sep 17 00:00:00 2001 From: "Tiger(EunHo Lee)" Date: Thu, 17 Sep 2015 19:35:45 +0900 Subject: [PATCH 2/4] The tomcat parameter provides an option for the profile. --- .../bootstrap/config/ExcludeMethodFilter.java | 42 +++++++++++++++++++ .../bootstrap/config/ProfilerConfig.java | 20 +++++---- .../interceptor/HttpServletInterceptor.java | 13 ++---- .../StandardHostValveInvokeInterceptor.java | 21 ++++++---- profiler/src/test/resources/pinpoint.config | 2 + 5 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java new file mode 100644 index 000000000000..4462c2be55d9 --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java @@ -0,0 +1,42 @@ +package com.navercorp.pinpoint.bootstrap.config; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class ExcludeMethodFilter implements Filter { + private final Set excludeMethods; + + public ExcludeMethodFilter(String excludeFormat) { + this(excludeFormat, ","); + } + + public ExcludeMethodFilter(String excludeFormat, String separator) { + if (excludeFormat == null || excludeFormat.isEmpty()) { + this.excludeMethods = Collections.emptySet(); + return; + } + + final String[] split = excludeFormat.split(separator); + this.excludeMethods = new HashSet(); + for (String method : split) { + if (isEmpty(method)) { + continue; + } + method = method.trim(); + if (method.isEmpty()) { + continue; + } + excludeMethods.add(method); + } + } + + private boolean isEmpty(String string) { + return string == null || string.isEmpty(); + } + + @Override + public boolean filter(String value) { + return excludeMethods.contains(value); + } +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java index 03cb09df93b8..e9aad66d83ba 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java @@ -101,8 +101,6 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept private boolean tcpDataSenderCommandAcceptEnable = false; - private boolean servletProfileParameter = false; - private int jdbcSqlCacheSize = 1024; private int jdbcMaxSqlBindValueSize = 1024; private boolean jdbcProfile = true; @@ -134,6 +132,7 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept private Filter tomcatExcludeUrlFilter = new SkipFilter(); private String tomcatRealIpHeader; private String tomcatRealIpEmptyValue; + private Filter tomcatExcludeProfileMethodFilter = new SkipFilter(); private boolean arucs = true; private boolean arucsKeyTrace = false; @@ -300,10 +299,6 @@ public boolean isProfileEnable() { return profileEnable; } - public boolean isServletProfileParameter() { - return servletProfileParameter; - } - public boolean isJdbcProfile() { return jdbcProfile; } @@ -435,6 +430,10 @@ public String getTomcatRealIpEmptyValue() { return tomcatRealIpEmptyValue; } + public Filter getTomcatExcludeProfileMethodFilter() { + return tomcatExcludeProfileMethodFilter; + } + public boolean isArucs() { return arucs; } @@ -654,8 +653,6 @@ void readPropertyValues() { this.tcpDataSenderCommandAcceptEnable = readBoolean("profiler.tcpdatasender.command.accept.enable", false); - this.servletProfileParameter = readBoolean("profiler.servlet.parameter", false); - // JDBC this.jdbcProfile = readBoolean("profiler.jdbc", true); @@ -698,6 +695,12 @@ void readPropertyValues() { this.tomcatRealIpHeader = readString("profiler.tomcat.realipheader", null); this.tomcatRealIpEmptyValue = readString("profiler.tomcat.realipemptyvalue", null); + final String tomcatExcludeProfileMethod = readString("profiler.tomcat.excludemethod", ""); + if (!tomcatExcludeProfileMethod.isEmpty()) { + this.tomcatExcludeProfileMethodFilter = new ExcludeMethodFilter(tomcatExcludeProfileMethod); + } + + this.arucs = readBoolean("profiler.arcus", true); this.arucsKeyTrace = readBoolean("profiler.arcus.keytrace", false); this.memcached = readBoolean("profiler.memcached", true); @@ -945,6 +948,7 @@ public String toString() { sb.append(", tomcatExcludeUrlFilter=").append(tomcatExcludeUrlFilter); sb.append(", tomcatRealIpHeader=").append(tomcatRealIpHeader); sb.append(", tomcatRealIpEmptyValue=").append(tomcatRealIpEmptyValue); + sb.append(", tomcatExcludeProfileMethodFilter=").append(tomcatExcludeProfileMethodFilter); sb.append(", arucs=").append(arucs); sb.append(", arucsKeyTrace=").append(arucsKeyTrace); sb.append(", memcached=").append(memcached); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java index d70acdccf87c..b1ee5c67b806 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/servlet/interceptor/HttpServletInterceptor.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.profiler.modifier.servlet.interceptor; -import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.context.Header; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; @@ -47,7 +46,6 @@ public class HttpServletInterceptor implements SimpleAroundInterceptor, ByteCode private MethodDescriptor descriptor; private TraceContext traceContext; - private boolean parameter; /* java.lang.IllegalStateException: already Trace Object exist. @@ -156,14 +154,11 @@ public void after(Object target, Object[] args, Object result, Throwable throwab HttpServletRequest request = (HttpServletRequest) args[0]; - if (parameter) { - String parameters = getRequestParameter(request); - if (parameters != null && parameters.length() > 0) { - trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); - } + String parameters = getRequestParameter(request); + if (parameters != null && parameters.length() > 0) { + trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); } - trace.recordApi(descriptor); trace.recordException(throwable); @@ -237,7 +232,5 @@ public void setMethodDescriptor(MethodDescriptor descriptor) { @Override public void setTraceContext(TraceContext traceContext) { this.traceContext = traceContext; - ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); - this.parameter = profilerConfig.isServletProfileParameter(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java index 8259ac750315..ea687c99c816 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java @@ -16,21 +16,22 @@ package com.navercorp.pinpoint.profiler.modifier.tomcat.interceptor; -import java.util.Enumeration; - import com.navercorp.pinpoint.bootstrap.config.Filter; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.context.*; -import com.navercorp.pinpoint.bootstrap.interceptor.*; +import com.navercorp.pinpoint.bootstrap.interceptor.RemoteAddressResolver; +import com.navercorp.pinpoint.bootstrap.interceptor.SpanSimpleAroundInterceptor; +import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; import com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils; import com.navercorp.pinpoint.bootstrap.util.NetworkUtils; import com.navercorp.pinpoint.bootstrap.util.NumberUtils; import com.navercorp.pinpoint.bootstrap.util.StringUtils; import com.navercorp.pinpoint.common.AnnotationKey; import com.navercorp.pinpoint.common.ServiceType; -import com.navercorp.pinpoint.profiler.context.*; +import com.navercorp.pinpoint.profiler.context.SpanId; import javax.servlet.http.HttpServletRequest; +import java.util.Enumeration; /** * @author emeroad @@ -40,6 +41,8 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep private final boolean isTrace = logger.isTraceEnabled(); private Filter excludeUrlFilter; + private Filter excludeProfileMethod; + private RemoteAddressResolver remoteAddressResolver; public StandardHostValveInvokeInterceptor() { @@ -197,9 +200,11 @@ private void recordParentInfo(RecordableTrace trace, HttpServletRequest request) protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { if (trace.canSampled()) { final HttpServletRequest request = (HttpServletRequest) args[0]; - final String parameters = getRequestParameter(request, 64, 512); - if (parameters != null && parameters.length() > 0) { - trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); + if (!excludeProfileMethod.filter(request.getMethod())) { + final String parameters = getRequestParameter(request, 64, 512); + if (parameters != null && parameters.length() > 0) { + trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); + } } trace.recordApi(getMethodDescriptor()); @@ -273,6 +278,7 @@ public void setTraceContext(TraceContext traceContext) { ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); this.excludeUrlFilter = profilerConfig.getTomcatExcludeUrlFilter(); + this.excludeProfileMethod = profilerConfig.getTomcatExcludeProfileMethodFilter(); final String proxyIpHeader = profilerConfig.getTomcatRealIpHeader(); if (proxyIpHeader == null || proxyIpHeader.isEmpty()) { @@ -281,5 +287,6 @@ public void setTraceContext(TraceContext traceContext) { final String tomcatRealIpEmptyValue = profilerConfig.getTomcatRealIpEmptyValue(); remoteAddressResolver = new RealIpHeaderResolver(proxyIpHeader, tomcatRealIpEmptyValue); } + } } diff --git a/profiler/src/test/resources/pinpoint.config b/profiler/src/test/resources/pinpoint.config index 7ea2d939d035..fbb208beb5e1 100644 --- a/profiler/src/test/resources/pinpoint.config +++ b/profiler/src/test/resources/pinpoint.config @@ -68,6 +68,8 @@ profiler.tomcat.hidepinpointheader=true #naver standard l7 check profiler.tomcat.excludeurl=/monitor/l7check.html #profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html +#profiler.tomcat.excludemethod=POST,PUT + # original IP address header # https://en.wikipedia.org/wiki/X-Forwarded-For From 87842a11debaa465cd237fbfd8daa96eeac76591 Mon Sep 17 00:00:00 2001 From: youtome Date: Fri, 18 Sep 2015 12:04:41 +0900 Subject: [PATCH 3/4] The tomcat parameter provides an option for the profile. --- .../pinpoint/bootstrap/config/ExcludeMethodFilter.java | 2 +- .../interceptor/StandardHostValveInvokeInterceptor.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java index 4462c2be55d9..a13668fbfa37 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilter.java @@ -27,7 +27,7 @@ public ExcludeMethodFilter(String excludeFormat, String separator) { if (method.isEmpty()) { continue; } - excludeMethods.add(method); + excludeMethods.add(method.toUpperCase()); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java index ea687c99c816..ef427a7cab9d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java @@ -41,7 +41,7 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep private final boolean isTrace = logger.isTraceEnabled(); private Filter excludeUrlFilter; - private Filter excludeProfileMethod; + private Filter excludeProfileMethodFilter; private RemoteAddressResolver remoteAddressResolver; @@ -200,7 +200,7 @@ private void recordParentInfo(RecordableTrace trace, HttpServletRequest request) protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { if (trace.canSampled()) { final HttpServletRequest request = (HttpServletRequest) args[0]; - if (!excludeProfileMethod.filter(request.getMethod())) { + if (!excludeProfileMethodFilter.filter(request.getMethod())) { final String parameters = getRequestParameter(request, 64, 512); if (parameters != null && parameters.length() > 0) { trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); @@ -278,7 +278,7 @@ public void setTraceContext(TraceContext traceContext) { ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); this.excludeUrlFilter = profilerConfig.getTomcatExcludeUrlFilter(); - this.excludeProfileMethod = profilerConfig.getTomcatExcludeProfileMethodFilter(); + this.excludeProfileMethodFilter = profilerConfig.getTomcatExcludeProfileMethodFilter(); final String proxyIpHeader = profilerConfig.getTomcatRealIpHeader(); if (proxyIpHeader == null || proxyIpHeader.isEmpty()) { From f91149b4e31b37545a5b0631fd73fb34bf304ce7 Mon Sep 17 00:00:00 2001 From: youtome Date: Fri, 18 Sep 2015 12:05:30 +0900 Subject: [PATCH 4/4] The tomcat parameter provides an option for the profile. --- .../config/ExcludeMethodFilterTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilterTest.java diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilterTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilterTest.java new file mode 100644 index 000000000000..0617db06e386 --- /dev/null +++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/config/ExcludeMethodFilterTest.java @@ -0,0 +1,30 @@ +package com.navercorp.pinpoint.bootstrap.config; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ExcludeMethodFilterTest { + + @Test + public void testFilter() throws Exception { + Filter filter = new ExcludeMethodFilter("get,post"); + + boolean getResult = filter.filter("GET"); + boolean postResult = filter.filter("POST"); + + assertTrue(getResult); + assertTrue(postResult); + } + + @Test + public void testUnFilter() throws Exception { + Filter filter = new ExcludeMethodFilter("get,post"); + + boolean putResult = filter.filter("PUT"); + boolean headResult = filter.filter("HEAD"); + + assertFalse(putResult); + assertFalse(headResult); + } +} \ No newline at end of file