Skip to content

Commit

Permalink
Merge pull request #977 from coupang/optionable_request_parameter
Browse files Browse the repository at this point in the history
backport #978 The tomcat parameter provides an option for the profile.
  • Loading branch information
emeroad committed Sep 18, 2015
2 parents 77f61df + f91149b commit 14f56c1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> {
private final Set<String> 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<String>();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept
private Filter<String> tomcatExcludeUrlFilter = new SkipFilter<String>();
private String tomcatRealIpHeader;
private String tomcatRealIpEmptyValue;
private Filter<String> tomcatExcludeProfileMethodFilter = new SkipFilter<String>();

private boolean arucs = true;
private boolean arucsKeyTrace = false;
Expand Down Expand Up @@ -429,6 +430,10 @@ public String getTomcatRealIpEmptyValue() {
return tomcatRealIpEmptyValue;
}

public Filter<String> getTomcatExcludeProfileMethodFilter() {
return tomcatExcludeProfileMethodFilter;
}

public boolean isArucs() {
return arucs;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> filter = new ExcludeMethodFilter("get,post");

boolean putResult = filter.filter("PUT");
boolean headResult = filter.filter("HEAD");

assertFalse(putResult);
assertFalse(headResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,6 +41,8 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep
private final boolean isTrace = logger.isTraceEnabled();
private Filter<String> excludeUrlFilter;

private Filter<String> excludeProfileMethodFilter;

private RemoteAddressResolver<HttpServletRequest> remoteAddressResolver;

public StandardHostValveInvokeInterceptor() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand All @@ -281,5 +287,6 @@ public void setTraceContext(TraceContext traceContext) {
final String tomcatRealIpEmptyValue = profilerConfig.getTomcatRealIpEmptyValue();
remoteAddressResolver = new RealIpHeaderResolver<HttpServletRequest>(proxyIpHeader, tomcatRealIpEmptyValue);
}

}
}
2 changes: 2 additions & 0 deletions profiler/src/test/resources/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14f56c1

Please # to comment.