Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#10637] Added trace method filter #10639

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 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, "");

Check warning on line 119 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ServerConfig.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ServerConfig.java#L119

Added line #L119 was not covered by tests
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 @@
return request.getRpcName();
}

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

Check warning on line 44 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServerRequestWrapperAdaptor.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServerRequestWrapperAdaptor.java#L44

Added line #L44 was not covered by tests
}

@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 @@
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 @@
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 @@
this.requestTraceReader = Objects.requireNonNull(requestTraceReader, "requestTraceReader");
this.proxyRequestRecorder = Objects.requireNonNull(proxyRequestRecorder, "proxyRequestRecorder");
this.excludeUrlFilter = Objects.requireNonNull(excludeUrlFilter, "excludeUrlFilter");
this.excludeMethodFilter = Objects.requireNonNull(excludeMethodFilter, "excludeMethodFilter");

Check warning on line 75 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java#L75

Added line #L75 was not covered by tests
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 @@
return null;
}

final String methodName = requestAdaptor.getMethodName(request);

Check warning on line 114 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java#L114

Added line #L114 was not covered by tests
if (this.excludeMethodFilter.filter(methodName)) {
if (isTrace) {
logger.trace("Filter methodName={}", methodName);

Check warning on line 117 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java#L117

Added line #L117 was not covered by tests
}
return null;

Check warning on line 119 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java#L119

Added line #L119 was not covered by tests
}

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 @@
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 @@
this.excludeUrlFilter = excludeUrlFilter;
}

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

Check warning on line 85 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java#L84-L85

Added lines #L84 - L85 were not covered by tests

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

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

Check warning on line 105 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java#L105

Added line #L105 was not covered by tests
}

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

Check warning on line 109 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java#L109

Added line #L109 was not covered by tests
}

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 @@


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

Check warning on line 135 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListenerBuilder.java#L135

Added line #L135 was not covered by tests

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

Expand All @@ -136,7 +149,8 @@


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 @@
return delegate.getRpcName(request);
}

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

Check warning on line 56 in bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/util/HeaderResolveRequestAdaptor.java

View check run for this annotation

Codecov / codecov/patch

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/util/HeaderResolveRequestAdaptor.java#L56

Added line #L56 was not covered by tests
}

@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