55
55
import java .util .zip .GZIPInputStream ;
56
56
import java .util .zip .GZIPOutputStream ;
57
57
58
+ import io .micrometer .core .instrument .Counter ;
59
+ import io .micrometer .core .instrument .MeterRegistry ;
60
+ import org .opengrok .indexer .Metrics ;
58
61
import org .opengrok .indexer .configuration .PathAccepter ;
59
62
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
60
63
import org .opengrok .indexer .logger .LoggerFactory ;
@@ -80,6 +83,9 @@ class FileHistoryCache implements HistoryCache {
80
83
private final PathAccepter pathAccepter = env .getPathAccepter ();
81
84
private boolean historyIndexDone = false ;
82
85
86
+ private Counter fileHistoryCacheHits ;
87
+ private Counter fileHistoryCacheMisses ;
88
+
83
89
@ Override
84
90
public void setHistoryIndexDone () {
85
91
historyIndexDone = true ;
@@ -144,7 +150,7 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
144
150
145
151
statRepoHist .report (LOGGER , Level .FINER ,
146
152
String .format ("Done storing history cache for '%s'" , filename ),
147
- "filehistorycache.history" );
153
+ "filehistorycache.history.store " );
148
154
}
149
155
150
156
private boolean isRenamedFile (String filename , Repository repository , History history )
@@ -174,7 +180,17 @@ protected Expression instantiate(Object oldInstance, Encoder out) {
174
180
175
181
@ Override
176
182
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
+ }
178
194
}
179
195
180
196
@ Override
@@ -568,13 +584,19 @@ public History get(File file, Repository repository, boolean withFiles)
568
584
File cache = getCachedFile (file );
569
585
if (isUpToDate (file , cache )) {
570
586
try {
587
+ if (fileHistoryCacheHits != null ) {
588
+ fileHistoryCacheHits .increment ();
589
+ }
571
590
return readCache (cache );
572
591
} catch (Exception e ) {
573
592
LOGGER .log (Level .WARNING ,
574
593
"Error when reading cache file '" + cache , e );
575
594
}
576
595
}
577
596
597
+ if (fileHistoryCacheMisses != null ) {
598
+ fileHistoryCacheMisses .increment ();
599
+ }
578
600
/*
579
601
* Some mirrors of repositories which are capable of fetching history
580
602
* for directories may contain lots of files untracked by given SCM.
0 commit comments