Skip to content

Commit e076181

Browse files
author
Vladimir Kotal
authored
add FileHistoryCache.get() counters for hits/misses (#3511)
fixes #3509
1 parent df71298 commit e076181

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
import java.util.zip.GZIPInputStream;
5656
import java.util.zip.GZIPOutputStream;
5757

58+
import io.micrometer.core.instrument.Counter;
59+
import io.micrometer.core.instrument.MeterRegistry;
60+
import org.opengrok.indexer.Metrics;
5861
import org.opengrok.indexer.configuration.PathAccepter;
5962
import org.opengrok.indexer.configuration.RuntimeEnvironment;
6063
import org.opengrok.indexer.logger.LoggerFactory;
@@ -80,6 +83,9 @@ class FileHistoryCache implements HistoryCache {
8083
private final PathAccepter pathAccepter = env.getPathAccepter();
8184
private boolean historyIndexDone = false;
8285

86+
private Counter fileHistoryCacheHits;
87+
private Counter fileHistoryCacheMisses;
88+
8389
@Override
8490
public void setHistoryIndexDone() {
8591
historyIndexDone = true;
@@ -144,7 +150,7 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
144150

145151
statRepoHist.report(LOGGER, Level.FINER,
146152
String.format("Done storing history cache for '%s'", filename),
147-
"filehistorycache.history");
153+
"filehistorycache.history.store");
148154
}
149155

150156
private boolean isRenamedFile(String filename, Repository repository, History history)
@@ -174,7 +180,17 @@ protected Expression instantiate(Object oldInstance, Encoder out) {
174180

175181
@Override
176182
public void initialize() {
177-
// nothing to do
183+
MeterRegistry meterRegistry = Metrics.getRegistry();
184+
if (meterRegistry != null) {
185+
fileHistoryCacheHits = Counter.builder("filehistorycache.history.get").
186+
description("file history cache hits").
187+
tag("what", "hits").
188+
register(meterRegistry);
189+
fileHistoryCacheMisses = Counter.builder("filehistorycache.history.get").
190+
description("file history cache misses").
191+
tag("what", "miss").
192+
register(meterRegistry);
193+
}
178194
}
179195

180196
@Override
@@ -568,13 +584,19 @@ public History get(File file, Repository repository, boolean withFiles)
568584
File cache = getCachedFile(file);
569585
if (isUpToDate(file, cache)) {
570586
try {
587+
if (fileHistoryCacheHits != null) {
588+
fileHistoryCacheHits.increment();
589+
}
571590
return readCache(cache);
572591
} catch (Exception e) {
573592
LOGGER.log(Level.WARNING,
574593
"Error when reading cache file '" + cache, e);
575594
}
576595
}
577596

597+
if (fileHistoryCacheMisses != null) {
598+
fileHistoryCacheMisses.increment();
599+
}
578600
/*
579601
* Some mirrors of repositories which are capable of fetching history
580602
* for directories may contain lots of files untracked by given SCM.

0 commit comments

Comments
 (0)