Add metric to count when ref size is larger that maxApiPayloadSize maxApiPayloadSize param define the size of the payload to send via apply object. If ref size is greater than maxApiPayloadSize apply object is be skipped and ref is transfer via git fetch. Counting how many time apply object is skipped is helpful to tune the configuration. Change-Id: I40ce0f9d8aaf37ca95527bc5f6528fabea42e362
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ApplyObjectMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ApplyObjectMetrics.java index 78745bb..d41dd8f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ApplyObjectMetrics.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ApplyObjectMetrics.java
@@ -15,6 +15,7 @@ package com.googlesource.gerrit.plugins.replication.pull; import com.google.gerrit.extensions.annotations.PluginName; +import com.google.gerrit.metrics.Counter0; import com.google.gerrit.metrics.Description; import com.google.gerrit.metrics.Field; import com.google.gerrit.metrics.MetricMaker; @@ -28,6 +29,8 @@ private final Timer1<String> executionTime; private final Timer1<String> end2EndTime; + private final Counter0 maxApiPayloadSizeReachedCounter; + @Inject ApplyObjectMetrics(@PluginName String pluginName, MetricMaker metricMaker) { Field<String> field = @@ -53,6 +56,13 @@ .setCumulative() .setUnit(Description.Units.MILLISECONDS), field); + maxApiPayloadSizeReachedCounter = + metricMaker.newCounter( + "apply_object_max_api_payload_reached", + new Description( + "Number of apply object operation with payload larger than maxApiPayloadSize") + .setRate() + .setUnit("errors")); } /** @@ -74,4 +84,9 @@ public Timer1.Context<String> startEnd2End(String name) { return end2EndTime.start(name); } + + /** Increment metric when ref size is larger than maxApiPayloadSize. */ + public void incrementMaxPayloadSizeReached() { + maxApiPayloadSizeReachedCounter.increment(); + } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java index db46b23..cd6a0ea 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java
@@ -55,9 +55,13 @@ private GitRepositoryManager gitRepositoryManager; private Long maxRefSize; private final int maxDepth; + private ApplyObjectMetrics metrics; @Inject - public RevisionReader(GitRepositoryManager gitRepositoryManager, ReplicationConfig cfg) { + public RevisionReader( + GitRepositoryManager gitRepositoryManager, + ReplicationConfig cfg, + ApplyObjectMetrics metrics) { this.gitRepositoryManager = gitRepositoryManager; this.maxRefSize = cfg.getConfig() @@ -65,6 +69,7 @@ this.maxDepth = cfg.getConfig() .getInt("replication", CONFIG_MAX_API_HISTORY_DEPTH, DEFAULT_MAX_API_HISTORY_DEPTH); + this.metrics = metrics; } public Optional<RevisionData> read( @@ -146,6 +151,7 @@ return Optional.of(new RevisionData(parentObjectIds, commitRev, treeRev, blobs)); } catch (LargeObjectException e) { + metrics.incrementMaxPayloadSizeReached(); repLog.trace( "Ref {} size for project {} is greater than configured '{}'", refName,