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..a13668fbfa37 --- /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.toUpperCase()); + } + } + + 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 4f735fbe0cd4..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 @@ -132,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; @@ -429,6 +430,10 @@ public String getTomcatRealIpEmptyValue() { return tomcatRealIpEmptyValue; } + public Filter getTomcatExcludeProfileMethodFilter() { + return tomcatExcludeProfileMethodFilter; + } + public boolean isArucs() { return arucs; } @@ -690,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); @@ -937,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/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 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..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,8 +16,6 @@ package com.navercorp.pinpoint.profiler.modifier.servlet.interceptor; -import java.util.Enumeration; - import com.navercorp.pinpoint.bootstrap.context.Header; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; @@ -32,9 +30,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 @@ -154,12 +153,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); } - trace.recordApi(descriptor); trace.recordException(throwable); 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..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 @@ -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 excludeProfileMethodFilter; + 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 (!excludeProfileMethodFilter.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.excludeProfileMethodFilter = 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