diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt index e90e3e5cc8..7440634b3c 100644 --- a/Documentation/metrics.txt +++ b/Documentation/metrics.txt @@ -63,6 +63,12 @@ of the process. * `sql/connection_pool/connections`: SQL database connections. +=== Topics + +* `topic/cross_project_submit`: number of cross-project topic submissions. +* `topic/cross_project_submit_completed`: number of cross-project +topic submissions that concluded successfully. + === JGit * `jgit/block_cache/cache_used`: Bytes of memory retained in JGit block cache. diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java index 241080853f..28cdebf0a2 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java @@ -40,6 +40,9 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.RestApiException; +import com.google.gerrit.metrics.Counter0; +import com.google.gerrit.metrics.Description; +import com.google.gerrit.metrics.MetricMaker; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Change; @@ -70,6 +73,7 @@ import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.util.RequestId; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; +import com.google.inject.Singleton; import com.google.inject.assistedinject.Assisted; import java.io.IOException; import java.sql.Timestamp; @@ -235,6 +239,7 @@ public class MergeOp implements AutoCloseable { private ListMultimap accountsToNotify; private Set allProjects; private boolean dryrun; + private TopicMetrics topicMetrics; @Inject MergeOp( @@ -247,6 +252,7 @@ public class MergeOp implements AutoCloseable { SubmoduleOp.Factory subOpFactory, MergeOpRepoManager orm, NotifyUtil notifyUtil, + TopicMetrics topicMetrics, @Assisted BatchUpdate.Factory batchUpdateFactory) { this.cmUtil = cmUtil; this.internalUserFactory = internalUserFactory; @@ -258,6 +264,7 @@ public class MergeOp implements AutoCloseable { this.orm = orm; this.notifyUtil = notifyUtil; this.batchUpdateFactory = batchUpdateFactory; + this.topicMetrics = topicMetrics; } @Override @@ -445,6 +452,25 @@ public class MergeOp implements AutoCloseable { } } + @Singleton + private static class TopicMetrics { + final Counter0 topicSubmissions; + final Counter0 topicSubmissionsCompleted; + + @Inject + TopicMetrics(MetricMaker metrics) { + topicSubmissions = + metrics.newCounter( + "topic/cross_project_submit", + new Description("Attempts at cross project topic submission").setRate()); + topicSubmissionsCompleted = + metrics.newCounter( + "topic/cross_project_submit_completed", + new Description("Cross project topic submissions that concluded successfully") + .setRate()); + } + } + private void integrateIntoHistory(ChangeSet cs) throws IntegrationException, RestApiException { checkArgument(!cs.furtherHiddenChanges(), "cannot integrate hidden changes into history"); logDebug("Beginning merge attempt on {}", cs); @@ -457,14 +483,25 @@ public class MergeOp implements AutoCloseable { throw new IntegrationException("Error reading changes to submit", e); } Set branches = cbb.keySet(); + + int projects = 0; for (Branch.NameKey branch : branches) { OpenRepo or = openRepo(branch.getParentKey()); if (or != null) { - toSubmit.put(branch, validateChangeList(or, cbb.get(branch))); + BranchBatch bb = validateChangeList(or, cbb.get(branch)); + toSubmit.put(branch, bb); + if (!bb.commits().isEmpty()) { + projects++; + } } } + // Done checks that don't involve running submit strategies. commitStatus.maybeFailVerbose(); + + if (projects > 1) { + topicMetrics.topicSubmissions.increment(); + } try { SubmoduleOp submoduleOp = subOpFactory.create(branches, orm); List strategies = getSubmitStrategies(toSubmit, submoduleOp, dryrun); @@ -494,6 +531,10 @@ public class MergeOp implements AutoCloseable { } throw new IntegrationException(msg, e); } + + if (projects > 1) { + topicMetrics.topicSubmissionsCompleted.increment(); + } } public Set getAllProjects() {