Skip to content

Commit

Permalink
Add parameter to optionally strip deploy path.
Browse files Browse the repository at this point in the history
Closes #631.

Signed-off-by: Lapo Luchini <lapo@lapo.it>
  • Loading branch information
lapo-luchini committed Mar 15, 2021
1 parent 7a6b9f1 commit 0af8459
Showing 1 changed file with 8 additions and 0 deletions.
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)
path = path.substring(request.getContextPath().length());

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

0 comments on commit 0af8459

Please sign in to comment.