1818
1919import java .io .IOException ;
2020import java .util .Arrays ;
21+ import java .util .Collections ;
2122import java .util .List ;
2223import java .util .Locale ;
2324import java .util .Optional ;
4243import org .apache .jackrabbit .oak .plugins .document .DocumentNodeStoreBuilder ;
4344import org .apache .jackrabbit .oak .plugins .document .DocumentStore ;
4445import org .apache .jackrabbit .oak .plugins .document .FormatVersion ;
46+ import org .apache .jackrabbit .oak .plugins .document .FullGCMetricsExporter ;
4547import org .apache .jackrabbit .oak .plugins .document .MissingLastRevSeeker ;
4648import org .apache .jackrabbit .oak .plugins .document .NodeDocument ;
4749import org .apache .jackrabbit .oak .plugins .document .RevisionContextWrapper ;
5052import org .apache .jackrabbit .oak .plugins .document .VersionGarbageCollector .VersionGCInfo ;
5153import org .apache .jackrabbit .oak .plugins .document .VersionGarbageCollector .VersionGCStats ;
5254import org .apache .jackrabbit .oak .plugins .document .util .MongoConnection ;
55+ import org .apache .jackrabbit .oak .run .cli .NodeStoreFixtureProvider ;
5356import org .apache .jackrabbit .oak .run .commons .Command ;
5457import org .apache .jackrabbit .oak .plugins .document .VersionGCOptions ;
5558import org .apache .jackrabbit .oak .plugins .document .VersionGarbageCollector ;
5659import org .apache .jackrabbit .oak .spi .blob .MemoryBlobStore ;
5760import org .apache .jackrabbit .oak .spi .gc .LoggingGCMonitor ;
61+ import org .apache .jackrabbit .oak .spi .whiteboard .DefaultWhiteboard ;
62+ import org .apache .jackrabbit .oak .spi .whiteboard .Whiteboard ;
5863import org .apache .jackrabbit .oak .stats .DefaultStatisticsProvider ;
64+ import org .apache .jackrabbit .oak .stats .StatisticsProvider ;
5965import org .bson .Document ;
6066import org .slf4j .Logger ;
6167import org .slf4j .LoggerFactory ;
7581import static org .apache .jackrabbit .oak .run .Utils .asCloseable ;
7682import static org .apache .jackrabbit .oak .run .Utils .createDocumentMKBuilder ;
7783import static org .apache .jackrabbit .oak .run .Utils .getMongoConnection ;
84+ import static org .apache .jackrabbit .oak .spi .whiteboard .WhiteboardUtils .getService ;
7885
7986/**
8087 * Gives information about current node revisions state.
@@ -118,7 +125,7 @@ public RevisionsCommand(boolean exitWhenDone) {
118125 this .exitWhenDone = exitWhenDone ;
119126 }
120127
121- private static class RevisionsOptions extends Utils .NodeStoreOptions {
128+ static class RevisionsOptions extends Utils .NodeStoreOptions {
122129
123130 static final String CMD_INFO = "info" ;
124131 static final String CMD_COLLECT = "collect" ;
@@ -148,6 +155,7 @@ private static class RevisionsOptions extends Utils.NodeStoreOptions {
148155 final OptionSpec <Boolean > embeddedVerification ;
149156 final OptionSpec <Integer > fullGcMode ;
150157 final OptionSpec <Boolean > fullGCAuditLoggingEnabled ;
158+ final OptionSpec <String > exportMetrics ;
151159
152160 RevisionsOptions (String usage ) {
153161 super (usage );
@@ -211,6 +219,8 @@ private static class RevisionsOptions extends Utils.NodeStoreOptions {
211219 .withOptionalArg ().ofType (Long .class ).defaultsTo (TimeUnit .DAYS .toSeconds (1 ));
212220 fullGCAuditLoggingEnabled = parser .accepts ("fullGCAuditLoggingEnabled" , "Enable audit logging for Full GC" )
213221 .withOptionalArg ().ofType (Boolean .class ).defaultsTo (FALSE );
222+ exportMetrics = parser .accepts ("exportMetrics" ,
223+ "type, URI to export the metrics and optional metadata all delimeted by semi-colon(;)" ).withRequiredArg ();
214224 }
215225
216226 public RevisionsOptions parse (String [] args ) {
@@ -313,6 +323,14 @@ boolean doCompaction() {
313323 Boolean isFullGCAuditLoggingEnabled () {
314324 return options .has (fullGCAuditLoggingEnabled );
315325 }
326+
327+ boolean exportMetrics () {
328+ return options .has (exportMetrics );
329+ }
330+
331+ String exportMetricsArgs () {
332+ return exportMetrics .value (options );
333+ }
316334 }
317335
318336 @ Override
@@ -382,7 +400,6 @@ private VersionGarbageCollector bootstrapVGC(RevisionsOptions options, Closer cl
382400 builder .setFullGCBatchSize (options .getFullGcBatchSize ());
383401 builder .setFullGCProgressSize (options .getFullGcProgressSize ());
384402 builder .setFullGcMaxAgeMillis (SECONDS .toMillis (options .getFullGcMaxAge ()));
385- builder .setFullGCAuditLoggingEnabled (options .isFullGCAuditLoggingEnabled ());
386403
387404 // create a VersionGCSupport while builder is read-write
388405 VersionGCSupport gcSupport = builder .createVersionGCSupport ();
@@ -416,7 +433,6 @@ private VersionGarbageCollector bootstrapVGC(RevisionsOptions options, Closer cl
416433 System .out .println ("FullGcProgressSize is : " + options .getFullGcProgressSize ());
417434 System .out .println ("FullGcMaxAgeInSecs is : " + options .getFullGcMaxAge ());
418435 System .out .println ("FullGcMaxAgeMillis is : " + builder .getFullGcMaxAgeMillis ());
419- System .out .println ("FullGCAuditLoggingEnabled is : " + options .isFullGCAuditLoggingEnabled ());
420436 VersionGarbageCollector gc = createVersionGC (builder .build (), gcSupport , options .isDryRun (), builder );
421437
422438 VersionGCOptions gcOptions = gc .getOptions ();
@@ -460,11 +476,22 @@ private void printInfo(VersionGarbageCollector gc, RevisionsOptions options) thr
460476
461477 private void collect (final RevisionsOptions options , Closer closer , boolean fullGCEnabled ) throws IOException {
462478 VersionGarbageCollector gc = bootstrapVGC (options , closer , fullGCEnabled );
463- // Set a default statistics provider
464- gc .setStatisticsProvider (new DefaultStatisticsProvider (Executors .newSingleThreadScheduledExecutor ()));
479+
480+ // setup metrics exporter
481+ Whiteboard whiteboard = new NodeStoreFixtureProvider .ClosingWhiteboard (new DefaultWhiteboard (), closer );
482+ StatisticsProvider statsProvider = NodeStoreFixtureProvider .createStatsProvider (whiteboard , closer );
483+ whiteboard .register (StatisticsProvider .class , statsProvider , Collections .emptyMap ());
484+ gc .setStatisticsProvider (statsProvider , true );
485+
486+ FullGCMetricsExporter metricsExporter = FullGCMetricsExporterFixtureProvider .create (options , whiteboard );
487+ gc .setFullGCMetricsExporter (metricsExporter );
488+
465489 ExecutorService executor = Executors .newSingleThreadExecutor ();
466490 final Semaphore finished = new Semaphore (0 );
467491 try {
492+ // register metrics exporter to closer
493+ closer .register (metricsExporter );
494+
468495 // collect until shutdown hook is called
469496 final AtomicBoolean running = new AtomicBoolean (true );
470497 Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
@@ -490,6 +517,7 @@ private void collect(final RevisionsOptions options, Closer closer, boolean full
490517 }
491518 System .out .println ("retrieving gc info" );
492519 printInfo (gc , options );
520+ } catch (Exception e ) {
493521 } finally {
494522 finished .release ();
495523 if (options .isDryRun ()) {
0 commit comments