Record the execution time of TopicValidator with a TraceTimer At Google this query frequently fails with a deadline exceeded exception, so we are interested to know how much latency it adds to git push in general. We also intent to do stale reads from the index to see if this improves the performance. Having the execution time recorded with a TraceTimer allows us to see the impact. Release-Notes: skip Bug: Google b/465110411 Change-Id: I4f5ec162dd423028496e8ac1d0951a232699c648 Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/server/git/validators/TopicValidator.java b/java/com/google/gerrit/server/git/validators/TopicValidator.java index d9881af..d51e102 100644 --- a/java/com/google/gerrit/server/git/validators/TopicValidator.java +++ b/java/com/google/gerrit/server/git/validators/TopicValidator.java
@@ -17,6 +17,9 @@ import com.google.common.base.Strings; import com.google.gerrit.common.Nullable; import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.logging.Metadata; +import com.google.gerrit.server.logging.TraceContext; +import com.google.gerrit.server.logging.TraceContext.TraceTimer; import com.google.gerrit.server.query.change.InternalChangeQuery; import com.google.gerrit.server.validators.ValidationException; import com.google.inject.Inject; @@ -43,14 +46,16 @@ if (Strings.isNullOrEmpty(topic)) { return; } - int topicSize = - queryProvider.get().noFields().setLimit(topicLimit + 1).byTopicOpen(topic).size(); - if (topicSize >= topicLimit) { - throw new ValidationException( - String.format( - "Topic '%s' already contains maximum number of allowed changes per 'topicLimit'" - + " server config value %d.", - topic, topicLimit)); + try (TraceTimer ignored = TraceContext.newTimer("Validate Topic Size", Metadata.empty())) { + int topicSize = + queryProvider.get().noFields().setLimit(topicLimit + 1).byTopicOpen(topic).size(); + if (topicSize >= topicLimit) { + throw new ValidationException( + String.format( + "Topic '%s' already contains maximum number of allowed changes per 'topicLimit'" + + " server config value %d.", + topic, topicLimit)); + } } } }