Add metric to count the requests to CLA checks

Change-Id: Ib1db33c3570f4c9e15ddbf77381ade756d99884a
This commit is contained in:
Minh Thai 2017-02-28 17:39:37 -08:00
parent 021d7df24c
commit 44e95ee49a
3 changed files with 29 additions and 2 deletions

View File

@ -111,6 +111,10 @@ remote destination.
* `plugins/replication/replication_retries`: Number of retries when pushing to
remote destination.
=== License
* `license/cla_check_count`: Total number of CLA check requests.
GERRIT
------
Part of link:index.html[Gerrit Code Review]

View File

@ -25,6 +25,9 @@ import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.common.data.PermissionRule.Action;
import com.google.gerrit.metrics.Counter0;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
@ -47,6 +50,7 @@ import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.ArrayList;
@ -138,6 +142,19 @@ public class ProjectControl {
ProjectControl create(CurrentUser who, ProjectState ps);
}
@Singleton
protected static class Metrics {
final Counter0 claCheckCount;
@Inject
Metrics(MetricMaker metricMaker) {
claCheckCount =
metricMaker.newCounter(
"license/cla_check_count",
new Description("Total number of CLA check requests").setRate().setUnit("requests"));
}
}
private final Set<AccountGroup.UUID> uploadGroups;
private final Set<AccountGroup.UUID> receiveGroups;
@ -151,6 +168,7 @@ public class ProjectControl {
private final TagCache tagCache;
@Nullable private final SearchingChangeCacheImpl changeCache;
private final Provider<InternalChangeQuery> queryProvider;
private final Metrics metrics;
private List<SectionMatcher> allSections;
private List<SectionMatcher> localSections;
@ -171,7 +189,8 @@ public class ProjectControl {
@Nullable SearchingChangeCacheImpl changeCache,
@CanonicalWebUrl @Nullable String canonicalWebUrl,
@Assisted CurrentUser who,
@Assisted ProjectState ps) {
@Assisted ProjectState ps,
Metrics metrics) {
this.changeNotesFactory = changeNotesFactory;
this.changeControlFactory = changeControlFactory;
this.tagCache = tagCache;
@ -182,6 +201,7 @@ public class ProjectControl {
this.contributorAgreements = pc.getAllProjects().getConfig().getContributorAgreements();
this.canonicalWebUrl = canonicalWebUrl;
this.queryProvider = queryProvider;
this.metrics = metrics;
user = who;
state = ps;
}
@ -348,6 +368,7 @@ public class ProjectControl {
}
private Capable verifyActiveContributorAgreement() {
metrics.claCheckCount.increment();
if (!(user.isIdentifiedUser())) {
return new Capable("Must be logged in to verify Contributor Agreement");
}

View File

@ -203,6 +203,7 @@ public class RefControlTest {
@Inject private InMemoryDatabase schemaFactory;
@Inject private ThreadLocalRequestContext requestContext;
@Inject private Provider<InternalChangeQuery> queryProvider;
@Inject private ProjectControl.Metrics metrics;
@Before
public void setUp() throws Exception {
@ -902,7 +903,8 @@ public class RefControlTest {
null,
canonicalWebUrl,
new MockUser(name, memberOf),
newProjectState(local));
newProjectState(local),
metrics);
}
private ProjectState newProjectState(ProjectConfig local) {