Revert "JGitMetricModule: Replace anonymous Supplier instances with method references"

This reverts commit 9ec9fee57f.

This commit broke reporting JGit metrics. All metrics affected by this
reported value 0.

When debugging this problem it turned out the static method
WindowCacheStats#getStats was evaluated too early when the
JGitMetricModule#configure method was run.

Instead it should be evaluated when the supplier's get method is called.
Gerrit reconfigures the WindowCache using the configuration given in
etc/gerrit.config. During this reconfiguration a new WindowCache
instance and consequently also a new StatsRecorderImpl instance is
created. Though the JGitMetricModule still had a reference to the old
WindowCache's StatsRecorderImpl which never saw any metric data since
the new WindowCache was using the new StatsRecorderImpl instance after
the WindowCache reconfiguration.

Change-Id: I9818eae94caccf330f914fd49e4d875b51cf18fd
This commit is contained in:
Matthias Sohn
2020-02-24 15:34:27 +01:00
parent 281e7b6d8d
commit 6074ab0a34

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.metrics.proc;
import com.google.common.base.Supplier;
import com.google.gerrit.metrics.CallbackMetric1;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.Description.Units;
@@ -33,13 +34,23 @@ public class JGitMetricModule extends MetricModule {
new Description("Bytes of memory retained in JGit block cache.")
.setGauge()
.setUnit(Units.BYTES),
WindowCacheStats.getStats()::getOpenByteCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getOpenByteCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/open_files",
Long.class,
new Description("File handles held open by JGit block cache.").setGauge().setUnit("fds"),
WindowCacheStats.getStats()::getOpenFileCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getOpenFileCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/avg_load_time",
@@ -47,55 +58,99 @@ public class JGitMetricModule extends MetricModule {
new Description("Average time to load a cache entry for JGit block cache.")
.setGauge()
.setUnit(Units.NANOSECONDS),
WindowCacheStats.getStats()::getAverageLoadTime);
new Supplier<Double>() {
@Override
public Double get() {
return WindowCacheStats.getStats().getAverageLoadTime();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/eviction_count",
Long.class,
new Description("Cache evictions for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getEvictionCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getEvictionCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/eviction_ratio",
Double.class,
new Description("Cache eviction ratio for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getEvictionRatio);
new Supplier<Double>() {
@Override
public Double get() {
return WindowCacheStats.getStats().getEvictionRatio();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/hit_count",
Long.class,
new Description("Cache hits for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getHitCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getHitCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/hit_ratio",
Double.class,
new Description("Cache hit ratio for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getHitRatio);
new Supplier<Double>() {
@Override
public Double get() {
return WindowCacheStats.getStats().getHitRatio();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/load_failure_count",
Long.class,
new Description("Failed cache loads for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getLoadFailureCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getLoadFailureCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/load_failure_ratio",
Double.class,
new Description("Failed cache load ratio for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getLoadFailureRatio);
new Supplier<Double>() {
@Override
public Double get() {
return WindowCacheStats.getStats().getLoadFailureRatio();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/load_success_count",
Long.class,
new Description("Successfull cache loads for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getLoadSuccessCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getLoadSuccessCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/miss_count",
Long.class,
new Description("Cache misses for JGit block cache.").setGauge(),
WindowCacheStats.getStats()::getMissCount);
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getStats().getMissCount();
}
});
metrics.newCallbackMetric(
"jgit/block_cache/miss_ratio",