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

Add parameter to optionally strip deploy path. #639

Merged
merged 2 commits into from Jul 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -60,6 +60,7 @@ public class MetricsFilter implements Filter {
static final String HELP_PARAM = "help";
static final String METRIC_NAME_PARAM = "metric-name";
static final String BUCKET_CONFIG_PARAM = "buckets";
static final String STRIP_CONTEXT_PATH_PARAM = "strip-context-path";
static final String UNKNOWN_HTTP_STATUS_CODE = "";

private Histogram histogram = null;
Expand All @@ -68,6 +69,7 @@ public class MetricsFilter implements Filter {
// Package-level for testing purposes.
int pathComponents = 1;
private String metricName = null;
private boolean stripContextPath = false;
private String help = "The time taken fulfilling servlet requests";
private double[] buckets = null;

Expand Down Expand Up @@ -145,6 +147,10 @@ public void init(FilterConfig filterConfig) throws ServletException {
buckets[i] = Double.parseDouble(bucketParams[i]);
}
}

if (!isEmpty(filterConfig.getInitParameter(STRIP_CONTEXT_PATH_PARAM))) {
stripContextPath = Boolean.parseBoolean(filterConfig.getInitParameter(STRIP_CONTEXT_PATH_PARAM));
}
}

if (buckets != null) {
Expand All @@ -171,6 +177,8 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
HttpServletRequest request = (HttpServletRequest) servletRequest;

String path = request.getRequestURI();
if (stripContextPath)
lapo-luchini marked this conversation as resolved.
Show resolved Hide resolved
path = path.substring(request.getContextPath().length());

String components = getComponents(path);
String method = request.getMethod();
Expand Down