Skip to content

Commit c0e6416

Browse files
tulinkryVladimir Kotal
authored andcommitted
adding basic stats for authorization decisions (#1558)
1 parent db515e6 commit c0e6416

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/org/opensolaris/opengrok/authorization/AuthorizationFramework.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4747
import org.opensolaris.opengrok.logger.LoggerFactory;
4848
import org.opensolaris.opengrok.util.IOUtils;
49+
import org.opensolaris.opengrok.web.Statistics;
4950

5051
/**
5152
* Placeholder for performing authorization checks.
@@ -599,18 +600,38 @@ private boolean checkAll(HttpServletRequest request, String cache, Nameable enti
599600
return true;
600601
}
601602

603+
Statistics stats = RuntimeEnvironment.getInstance().getStatistics();
604+
602605
Boolean val;
603606
Map<String, Boolean> m = (Map<String, Boolean>) request.getAttribute(cache);
604607

605608
if (m == null) {
606609
m = new TreeMap<>();
607610
} else if ((val = m.get(entity.getName())) != null) {
608611
// cache hit
612+
stats.addRequest(request, "authorization_cache_hits");
609613
return val;
610614
}
611615

616+
stats.addRequest(request, "authorization_cache_misses");
617+
618+
long time = System.currentTimeMillis();
619+
612620
boolean overallDecision = performCheck(entity, predicate);
613621

622+
time = System.currentTimeMillis() - time;
623+
624+
stats.addRequestTime(request, "authorization", time);
625+
stats.addRequestTime(request,
626+
String.format("authorization_%s", overallDecision ? "positive" : "negative"),
627+
time);
628+
stats.addRequestTime(request,
629+
String.format("authorization_%s_of_%s", overallDecision ? "positive" : "negative", entity.getName()),
630+
time);
631+
stats.addRequestTime(request,
632+
String.format("authorization_of_%s", entity.getName()),
633+
time);
634+
614635
m.put(entity.getName(), overallDecision);
615636
request.setAttribute(cache, m);
616637
return overallDecision;

src/org/opensolaris/opengrok/web/Statistics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected void maybeRefresh() {
9999
/**
100100
* Adds a request into the category
101101
*
102+
* @param req the given request
102103
* @param category category
103104
*/
104105
public void addRequest(HttpServletRequest req, String category) {
@@ -113,6 +114,7 @@ public void addRequest(HttpServletRequest req, String category) {
113114
/**
114115
* Adds a request's process time into given category.
115116
*
117+
* @param req the given request
116118
* @param category category
117119
* @param v time spent on processing this request
118120
*/

src/org/opensolaris/opengrok/web/StatisticsFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ protected void collectStats(HttpServletRequest req, String category) {
7878
stats.addRequestTime(req, category, processTime); // add this category
7979

8080
/* supplementary categories */
81+
if (config.getProject() != null) {
82+
stats.addRequestTime(req, "viewing_of_" + config.getProject().getName(), processTime);
83+
}
84+
8185
SearchHelper helper = (SearchHelper) config.getRequestAttribute(SearchHelper.REQUEST_ATTR);
8286
if (helper != null) {
8387
if (helper.hits == null || helper.hits.length == 0) {

0 commit comments

Comments
 (0)