Skip to content

Commit

Permalink
[pinpoint-apm#10637] Added trace method filter
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjin.kim2 authored and smilu97 committed Jan 23, 2024
1 parent 162a516 commit ce264f6
Show file tree
Hide file tree
Showing 42 changed files with 296 additions and 44 deletions.
1 change: 1 addition & 0 deletions agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ profiler.server.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.server.excludeurl=
profiler.server.trace.excludemethod=
# HTTP Request methods to exclude from tracing.
# e.g. POST, PUT
profiler.server.excludemethod=
Expand Down
10 changes: 10 additions & 0 deletions agent/src/main/resources/profiles/local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ profiler.tomcat.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.tomcat.excludeurl=
# profiler.tomcat.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.tomcat.excludemethod=
profiler.tomcat.tracerequestparam=true
Expand All @@ -363,6 +364,7 @@ profiler.jetty.bootstrap.main=org.eclipse.jetty.start.Main
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.jetty.excludeurl=
# profiler.jetty.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.jetty.excludemethod=
# Hide pinpoint headers.
Expand Down Expand Up @@ -404,6 +406,7 @@ profiler.jboss.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.jboss.excludeurl=
# profiler.jboss.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.jboss.excludemethod=
profiler.jboss.tracerequestparam=true
Expand All @@ -428,6 +431,7 @@ profiler.resin.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.resin.excludeurl=
# profiler.resin.trace.excludemethod=
# Hide pinpoint headers.
profiler.resin.hidepinpointheader=true
# HTTP Request methods to exclude from tracing
Expand All @@ -452,6 +456,7 @@ profiler.weblogic.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.weblogic.excludeurl=
# profiler.weblogic.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.weblogic.excludemethod=
# Hide pinpoint headers.
Expand All @@ -476,6 +481,7 @@ profiler.websphere.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.websphere.excludeurl=
# profiler.websphere.trace.excludemethod=
# HTTP Request methods to exclude from tracing
profiler.websphere.excludemethod=
# Hide pinpoint headers.
Expand Down Expand Up @@ -512,6 +518,7 @@ profiler.vertx.http.server.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.vertx.http.server.excludeurl=
# profiler.vertx.http.server.trace.excludemethod=
# original IP address header
# https://en.wikipedia.org/wiki/X-Forwarded-For
#profiler.vertx.http.server.realipheader=X-Forwarded-For
Expand Down Expand Up @@ -553,6 +560,7 @@ profiler.undertow.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.undertow.excludeurl=
# profiler.undertow.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.undertow.excludemethod=

Expand Down Expand Up @@ -586,6 +594,7 @@ profiler.reactor-netty.server.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.reactor-netty.server.excludeurl=
# profiler.reactor-netty.server.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.reactor-netty.server.excludemethod=

Expand Down Expand Up @@ -1254,6 +1263,7 @@ profiler.akka.http.enable=false
profiler.akka.http.realipheader=Remote-Address
# URLs to exclude from tracing
profiler.akka.http.excludeurl=
# profiler.akka.http.trace.excludemethod=
# HTTP Request methods to exclude from tracing
profiler.akka.http.excludemethod=
# Set transform target
Expand Down
10 changes: 10 additions & 0 deletions agent/src/main/resources/profiles/release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ profiler.tomcat.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.tomcat.excludeurl=
# profiler.tomcat.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.tomcat.excludemethod=POST,PUT
profiler.tomcat.tracerequestparam=true
Expand All @@ -360,6 +361,7 @@ profiler.jetty.bootstrap.main=org.eclipse.jetty.start.Main
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.jetty.excludeurl=
# profiler.jetty.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.jetty.excludemethod=
# Hide pinpoint headers.
Expand Down Expand Up @@ -401,6 +403,7 @@ profiler.jboss.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.jboss.excludeurl=
# profiler.jboss.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.jboss.excludemethod=
profiler.jboss.tracerequestparam=true
Expand All @@ -425,6 +428,7 @@ profiler.resin.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.resin.excludeurl=
# profiler.resin.trace.excludemethod=
# Hide pinpoint headers.
profiler.resin.hidepinpointheader=true
# HTTP Request methods to exclude from tracing
Expand All @@ -449,6 +453,7 @@ profiler.weblogic.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.weblogic.excludeurl=
# profiler.weblogic.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.weblogic.excludemethod=
# Hide pinpoint headers.
Expand All @@ -473,6 +478,7 @@ profiler.websphere.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.websphere.excludeurl=
# profiler.websphere.trace.excludemethod=
# HTTP Request methods to exclude from tracing
profiler.websphere.excludemethod=
# Hide pinpoint headers.
Expand Down Expand Up @@ -509,6 +515,7 @@ profiler.vertx.http.server.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.vertx.http.server.excludeurl=
# profiler.vertx.http.server.trace.excludemethod=
# original IP address header
# https://en.wikipedia.org/wiki/X-Forwarded-For
#profiler.vertx.http.server.realipheader=X-Forwarded-For
Expand Down Expand Up @@ -551,6 +558,7 @@ profiler.undertow.hidepinpointheader=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.undertow.excludeurl=
# profiler.undertow.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.undertow.excludemethod=

Expand Down Expand Up @@ -583,6 +591,7 @@ profiler.reactor-netty.server.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.reactor-netty.server.excludeurl=
# profiler.reactor-netty.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.reactor-netty.server.excludemethod=

Expand Down Expand Up @@ -1278,6 +1287,7 @@ profiler.akka.http.enable=false
profiler.akka.http.realipheader=Remote-Address
# URLs to exclude from tracing
profiler.akka.http.excludeurl=
# profiler.akka.http.trace.excludemethod=
# HTTP Request methods to exclude from tracing
profiler.akka.http.excludemethod=
# Set transform target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ServerConfig {
static final String REAL_IP_HEADER_PROPERTY_NAME = "profiler.server.realipheader";
static final String REAL_IP_EMPTY_VALUE_PROPERTY_NAME = "profiler.server.realipemptyvalue";
static final String EXCLUDE_METHOD_PROPERTY_NAME = "profiler.server.excludemethod";
static final String PRE_EXCLUDE_METHOD_PROPERTY_NAME = "profiler.server.trace.excludemethod";

private final ProfilerConfig config;

Expand Down Expand Up @@ -100,18 +101,27 @@ public String getRealIpEmptyValue(final String propertyName) {
}

public Filter<String> getExcludeMethodFilter(final String propertyName) {
return getStringFilter(propertyName, EXCLUDE_METHOD_PROPERTY_NAME);
}

public Filter<String> getTraceExcludeMethodFilter(final String propertyName) {
return getStringFilter(propertyName, PRE_EXCLUDE_METHOD_PROPERTY_NAME);
}

private Filter<String> getStringFilter(String propertyName, String fallbackPropertyName) {
Objects.requireNonNull(propertyName, "propertyName");

final String propertyValue = config.readString(propertyName, "");
if (!propertyValue.isEmpty()) {
// Individual settings take precedence.
return new ExcludeMethodFilter(propertyValue);
}
final String serverExcludeUrlPropertyValue = config.readString(EXCLUDE_METHOD_PROPERTY_NAME, "");
final String serverExcludeUrlPropertyValue = config.readString(fallbackPropertyName, "");
if (!serverExcludeUrlPropertyValue.isEmpty()) {
return new ExcludeMethodFilter(serverExcludeUrlPropertyValue);
}

return new SkipFilter<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public interface RequestAdaptor<REQ> {
*/
String getRpcName(REQ request);

/**
* Method name (optional)
*
* @return
*/
String getMethodName(REQ request);

/**
* Server address
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface ServerRequestWrapper extends RequestWrapper {
*/
String getRpcName();

/**
* Method name (optional)
*
* @return
*/
String getMethodName();

/**
* Server address
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public String getRpcName(ServerRequestWrapper request) {
return request.getRpcName();
}

@Override
public String getMethodName(ServerRequestWrapper request) {
return request.getMethodName();
}

@Override
public String getEndPoint(ServerRequestWrapper request) {
return request.getEndPoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ServletRequestListener<REQ> {
private final RequestAdaptor<REQ> requestAdaptor;

private final Filter<String> excludeUrlFilter;
private final Filter<String> excludeMethodFilter;
private final RequestTraceReader<REQ> requestTraceReader;
private final ServerRequestRecorder<REQ> serverRequestRecorder;
private final HttpStatusCodeRecorder httpStatusCodeRecorder;
Expand All @@ -60,6 +61,7 @@ public ServletRequestListener(final ServiceType serviceType,
final RequestAdaptor<REQ> requestAdaptor,
final RequestTraceReader<REQ> requestTraceReader,
final Filter<String> excludeUrlFilter,
final Filter<String> excludeMethodFilter,
final ParameterRecorder<REQ> parameterRecorder,
final ProxyRequestRecorder<REQ> proxyRequestRecorder,
final ServerRequestRecorder<REQ> serverRequestRecorder,
Expand All @@ -70,6 +72,7 @@ public ServletRequestListener(final ServiceType serviceType,
this.requestTraceReader = Objects.requireNonNull(requestTraceReader, "requestTraceReader");
this.proxyRequestRecorder = Objects.requireNonNull(proxyRequestRecorder, "proxyRequestRecorder");
this.excludeUrlFilter = Objects.requireNonNull(excludeUrlFilter, "excludeUrlFilter");
this.excludeMethodFilter = Objects.requireNonNull(excludeMethodFilter, "excludeMethodFilter");
this.parameterRecorder = Objects.requireNonNull(parameterRecorder, "parameterRecorder");
this.serverRequestRecorder = Objects.requireNonNull(serverRequestRecorder, "serverRequestRecorder");
this.httpStatusCodeRecorder = Objects.requireNonNull(httpStatusCodeRecorder, "httpStatusCodeRecorder");
Expand Down Expand Up @@ -108,6 +111,14 @@ private Trace createTrace(REQ request) {
return null;
}

final String methodName = requestAdaptor.getMethodName(request);
if (this.excludeMethodFilter.filter(methodName)) {
if (isTrace) {
logger.trace("Filter methodName={}", methodName);
}
return null;
}

final Trace trace = this.requestTraceReader.read(request);
if (trace.canSampled()) {
final SpanRecorder recorder = trace.getSpanRecorder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ServletRequestListenerBuilder<REQ> {
private ParameterRecorder<REQ> parameterRecorder;

private Filter<String> excludeUrlFilter;
private Filter<String> traceExcludeMethodFilter;
private RequestRecorderFactory<REQ> requestRecorderFactory;

private HttpStatusCodeErrors httpStatusCodeErrors;
Expand Down Expand Up @@ -79,6 +80,10 @@ public void setExcludeURLFilter(Filter<String> excludeUrlFilter) {
this.excludeUrlFilter = excludeUrlFilter;
}

public void setTraceExcludeMethodFilter(Filter<String> traceExcludeMethodFilter) {
this.traceExcludeMethodFilter = traceExcludeMethodFilter;
}

public void setRequestRecorderFactory(RequestRecorderFactory<REQ> requestRecorderFactory) {
this.requestRecorderFactory = requestRecorderFactory;
}
Expand All @@ -97,13 +102,20 @@ public void setServerCookieRecorder(List<String> recordRequestCookies) {
}

private <T> Filter<T> newExcludeUrlFilter(Filter<T> excludeUrlFilter) {
return filterNonNull(excludeUrlFilter);
}

private <T> Filter<T> newTraceExcludeMethodFilter(Filter<T> excludeMethodFilter) {
return filterNonNull(excludeMethodFilter);
}

private static <T> Filter<T> filterNonNull(Filter<T> excludeUrlFilter) {
if (excludeUrlFilter == null) {
return new SkipFilter<>();
}
return excludeUrlFilter;
}


public ServletRequestListener<REQ> build() {

RequestAdaptor<REQ> requestAdaptor = RemoteAddressResolverFactory.wrapRealIpSupport(this.requestAdaptor, realIpHeader, realIpEmptyValue);
Expand All @@ -120,6 +132,7 @@ public ServletRequestListener<REQ> build() {


Filter<String> excludeUrlFilter = newExcludeUrlFilter(this.excludeUrlFilter);
Filter<String> traceExcludeMethodFilter = newTraceExcludeMethodFilter(this.traceExcludeMethodFilter);

final ServerRequestRecorder<REQ> serverRequestRecorder = newServerRequestRecorder(requestAdaptor);

Expand All @@ -136,7 +149,8 @@ public ServletRequestListener<REQ> build() {


return new ServletRequestListener<>(serviceType, traceContext, requestAdaptor, requestTraceReader,
excludeUrlFilter, parameterRecorder, proxyRequestRecorder, serverRequestRecorder, httpStatusCodeRecorder);
excludeUrlFilter, traceExcludeMethodFilter, parameterRecorder, proxyRequestRecorder,
serverRequestRecorder, httpStatusCodeRecorder);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public String getRpcName(T request) {
return delegate.getRpcName(request);
}

@Override
public String getMethodName(T request) {
return delegate.getMethodName(request);
}

@Override
public String getEndPoint(T request) {
return delegate.getEndPoint(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,19 @@ public void getExcludeMethodFilter() {
Assertions.assertTrue(filter.filter("HEAD"));
Assertions.assertFalse(filter.filter("POST"));
}

@Test
public void getTraceExcludeMethodFilter() {
final String propertyName = "profiler.tomcat.trace.excludemethod";
Properties properties = new Properties();
properties.setProperty(ServerConfig.PRE_EXCLUDE_METHOD_PROPERTY_NAME, "POST");
properties.setProperty(propertyName, "HEAD");

ProfilerConfig profilerConfig = ProfilerConfigLoader.load(properties);
ServerConfig serverConfig = new ServerConfig(profilerConfig);

Filter<String> filter = serverConfig.getTraceExcludeMethodFilter(propertyName);
Assertions.assertTrue(filter.filter("HEAD"));
Assertions.assertFalse(filter.filter("POST"));
}
}
Loading

0 comments on commit ce264f6

Please sign in to comment.