Skip to content

Commit 2987a36

Browse files
author
Vladimir Kotal
committed
move request latency meter to StatisticsFilter
1 parent b1f92b1 commit 2987a36

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Prefix.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ public enum Prefix {
7373
/** Related source file or directory not found/unavailable/ignored. */
7474
NOT_FOUND("/enoent"),
7575
/** Misc error occurred. */
76-
ERROR("/error");
76+
ERROR("/error"),
77+
/** RESTful API */
78+
REST_API("/api"),
79+
/** Monitoring */
80+
METRICS("/metrics"),
81+
/** CSS and images */
82+
STATIC("/default");
7783

7884
private final String prefix;
7985
Prefix(String prefix) {

opengrok-web/src/main/java/org/opengrok/web/StatisticsFilter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public void init(FilterConfig fc) throws ServletException {
6060
@Override
6161
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc)
6262
throws IOException, ServletException {
63+
/*
64+
* Add the request to the statistics. Be aware of the colliding call in
65+
* {@code AuthorizationFilter#doFilter}.
66+
*/
67+
requests.record(1);
68+
6369
HttpServletRequest httpReq = (HttpServletRequest) sr;
6470

6571
Instant start = Instant.now();
@@ -79,13 +85,7 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc)
7985
return;
8086
}
8187

82-
/*
83-
* Add the request to the statistics. Be aware of the colliding call in
84-
* {@code AuthorizationFilter#doFilter}.
85-
*/
86-
requests.record(1);
87-
88-
Timer categoryTimer = Timer.builder("requests.latency.category").
88+
Timer categoryTimer = Timer.builder("requests.latency").
8989
tags("category", category).
9090
register(Metrics.getRegistry());
9191
categoryTimer.record(duration);

opengrok-web/src/main/java/org/opengrok/web/WebappListener.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,13 @@ public final class WebappListener
5757

5858
private static final Logger LOGGER = LoggerFactory.getLogger(WebappListener.class);
5959

60-
private static final String TIMER_ATTR_NAME = WebappListener.class.getName() + ".request_start";
61-
private Timer requestTimer;
62-
6360
/**
6461
* {@inheritDoc}
6562
*/
6663
@Override
6764
public void contextInitialized(final ServletContextEvent servletContextEvent) {
6865
ServletContext context = servletContextEvent.getServletContext();
6966
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
70-
requestTimer = Timer.builder("request.latency").
71-
description("web application request latency").
72-
register(Metrics.getRegistry());
7367

7468
LOGGER.log(Level.INFO, "Starting webapp with version {0} ({1})",
7569
new Object[]{Info.getVersion(), Info.getRevision()});
@@ -130,20 +124,14 @@ public void contextDestroyed(final ServletContextEvent servletContextEvent) {
130124
*/
131125
@Override
132126
public void requestInitialized(ServletRequestEvent e) {
133-
e.getServletRequest().setAttribute(TIMER_ATTR_NAME, Instant.now());
127+
// pass
134128
}
135129

136130
/**
137131
* {@inheritDoc}
138132
*/
139133
@Override
140134
public void requestDestroyed(ServletRequestEvent e) {
141-
Instant start = (Instant) e.getServletRequest().getAttribute(TIMER_ATTR_NAME);
142-
if (start != null) {
143-
Duration duration = Duration.between(start, Instant.now());
144-
requestTimer.record(duration);
145-
}
146-
147135
PageConfig.cleanup(e.getServletRequest());
148136
SearchHelper sh = (SearchHelper) e.getServletRequest().getAttribute(SearchHelper.REQUEST_ATTR);
149137
if (sh != null) {

0 commit comments

Comments
 (0)