Add metric to measure the time for computing patch set approvals

Besides computing the changed files, computing the approvals of the
current patch set is the other operation that can cause latency in the
prepare file status computation step. To know better let's measure the
latency of this operation.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I5126901a6d605648852b770bc1999c7db6c6366c
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
index 5ab28b4..a70fc53 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
@@ -928,14 +928,16 @@
   }
 
   private ImmutableList<PatchSetApproval> getCurrentPatchSetApprovals(ChangeNotes changeNotes) {
-    return ImmutableList.copyOf(
-        approvalsUtil.byPatchSet(
-            changeNotes,
-            changeNotes.getCurrentPatchSet().id(),
-            /** revWalk */
-            null,
-            /** repoConfig */
-            null));
+    try (Timer0.Context ctx = codeOwnerMetrics.computePatchSetApprovals.start()) {
+      return ImmutableList.copyOf(
+          approvalsUtil.byPatchSet(
+              changeNotes,
+              changeNotes.getCurrentPatchSet().id(),
+              /** revWalk */
+              null,
+              /** repoConfig */
+              null));
+    }
   }
 
   private ImmutableSet<Account.Id> filterOutAccount(
diff --git a/java/com/google/gerrit/plugins/codeowners/metrics/CodeOwnerMetrics.java b/java/com/google/gerrit/plugins/codeowners/metrics/CodeOwnerMetrics.java
index a04a078..f3cc516 100644
--- a/java/com/google/gerrit/plugins/codeowners/metrics/CodeOwnerMetrics.java
+++ b/java/com/google/gerrit/plugins/codeowners/metrics/CodeOwnerMetrics.java
@@ -34,6 +34,7 @@
   public final Timer0 computeFileStatus;
   public final Timer0 computeFileStatuses;
   public final Timer0 computeOwnedPaths;
+  public final Timer0 computePatchSetApprovals;
   public final Timer0 extendChangeMessageOnPostReview;
   public final Timer0 getAutoMerge;
   public final Timer0 prepareFileStatusComputation;
@@ -81,6 +82,10 @@
         createLatencyTimer(
             "compute_owned_paths",
             "Latency for computing the files in a change that are owned by a user");
+    this.computePatchSetApprovals =
+        createLatencyTimer(
+            "compute_patch_set_approvals",
+            "Latency for computing the approvals of the current patch set");
     this.extendChangeMessageOnPostReview =
         createLatencyTimer(
             "extend_change_message_on_post_review",
diff --git a/resources/Documentation/metrics.md b/resources/Documentation/metrics.md
index 1c565f0..565ca67 100644
--- a/resources/Documentation/metrics.md
+++ b/resources/Documentation/metrics.md
@@ -18,6 +18,8 @@
   Latency for computing file statuses.
 * `compute_owned_paths`:
   Latency for computing the files in a change that are owned by a user.
+* `compute_patch_set_approvals`:
+  Latency for computing the approvals of the current patch set.
 * `extend_change_message_on_post_review`:
   Latency for extending the change message with the owned path when a code owner
   approval is applied.