Add config load related metrics to prolog rules evaluation
These two metrics are also emitted when prolog is evaluated:
* plugins/owners/count_configuration_loads: config loads counter
* plugins/owners/load_configuration_latency: latency for config load
Bug: Issue 15556
Change-Id: Ib685f7528d5d14eb65baa7ed4352942c6c027ed8
diff --git a/owners/BUILD b/owners/BUILD
index d04d83d..402bd34 100644
--- a/owners/BUILD
+++ b/owners/BUILD
@@ -4,6 +4,7 @@
load("//tools/bzl:junit.bzl", "junit_tests")
PROLOG_PREDICATES = glob(["src/main/java/gerrit_owners/**/*.java"]) + [
+ "src/main/java/com/googlesource/gerrit/owners/OwnersMetrics.java",
"src/main/java/com/googlesource/gerrit/owners/OwnersStoredValues.java",
]
diff --git a/owners/src/main/java/com/googlesource/gerrit/owners/OwnerPredicateProvider.java b/owners/src/main/java/com/googlesource/gerrit/owners/OwnerPredicateProvider.java
index 7b1399a..119f1bd 100644
--- a/owners/src/main/java/com/googlesource/gerrit/owners/OwnerPredicateProvider.java
+++ b/owners/src/main/java/com/googlesource/gerrit/owners/OwnerPredicateProvider.java
@@ -27,8 +27,8 @@
@Listen
public class OwnerPredicateProvider implements PredicateProvider {
@Inject
- public OwnerPredicateProvider(Accounts accounts, PluginSettings config) {
- OwnersStoredValues.initialize(accounts, config);
+ public OwnerPredicateProvider(Accounts accounts, PluginSettings config, OwnersMetrics metrics) {
+ OwnersStoredValues.initialize(accounts, config, metrics);
}
@Override
diff --git a/owners/src/main/java/com/googlesource/gerrit/owners/OwnersStoredValues.java b/owners/src/main/java/com/googlesource/gerrit/owners/OwnersStoredValues.java
index 562d7cb..fb1de16 100644
--- a/owners/src/main/java/com/googlesource/gerrit/owners/OwnersStoredValues.java
+++ b/owners/src/main/java/com/googlesource/gerrit/owners/OwnersStoredValues.java
@@ -17,6 +17,7 @@
package com.googlesource.gerrit.owners;
import com.google.gerrit.entities.Project;
+import com.google.gerrit.metrics.Timer0;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.patch.filediff.FileDiffOutput;
import com.google.gerrit.server.project.ProjectState;
@@ -41,7 +42,8 @@
public static StoredValue<PathOwners> PATH_OWNERS;
- public static synchronized void initialize(Accounts accounts, PluginSettings settings) {
+ public static synchronized void initialize(
+ Accounts accounts, PluginSettings settings, OwnersMetrics metrics) {
if (PATH_OWNERS != null) {
return;
}
@@ -55,20 +57,23 @@
ProjectState projectState = StoredValues.PROJECT_STATE.get(engine);
GitRepositoryManager gitRepositoryManager = StoredValues.REPO_MANAGER.get(engine);
- List<Project.NameKey> maybeParentProjectNameKey =
- Optional.ofNullable(projectState.getProject().getParent())
- .map(Arrays::asList)
- .orElse(Collections.emptyList());
+ metrics.countConfigLoads.increment();
+ try (Timer0.Context ctx = metrics.loadConfig.start()) {
+ List<Project.NameKey> maybeParentProjectNameKey =
+ Optional.ofNullable(projectState.getProject().getParent())
+ .map(Arrays::asList)
+ .orElse(Collections.emptyList());
- String branch = StoredValues.getChange(engine).getDest().branch();
- return new PathOwners(
- accounts,
- gitRepositoryManager,
- repository,
- maybeParentProjectNameKey,
- settings.isBranchDisabled(branch) ? Optional.empty() : Optional.of(branch),
- patchList,
- settings.expandGroups());
+ String branch = StoredValues.getChange(engine).getDest().branch();
+ return new PathOwners(
+ accounts,
+ gitRepositoryManager,
+ repository,
+ maybeParentProjectNameKey,
+ settings.isBranchDisabled(branch) ? Optional.empty() : Optional.of(branch),
+ patchList,
+ settings.expandGroups());
+ }
}
};
}
diff --git a/owners/src/main/resources/Documentation/metrcis.md b/owners/src/main/resources/Documentation/metrcis.md
index c1927b7..8f3c9f6 100644
--- a/owners/src/main/resources/Documentation/metrcis.md
+++ b/owners/src/main/resources/Documentation/metrcis.md
@@ -1,8 +1,7 @@
Metrics
=============
-The following metrics are emitted when submit requirements are enabled
-(`owners.enableSubmitRequirement = true`):
+The following metrics are always emitted:
* plugins/owners/count_configuration_loads
: the total number of owners configuration loads.
@@ -10,6 +9,9 @@
* plugins/owners/load_configuration_latency
: the latency for loading owners configuration for a change.
+When submit requirements are enabled (`owners.enableSubmitRequirement = true`)
+these are additionally emitted:
+
* plugins/owners/count_submit_rule_runs
: the total number of owners submit rule runs.