This is an automated email from the ASF dual-hosted git repository.

daim pushed a commit to branch OAK-11452
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit e8f58242462ba92b5c7c3d6865d4557d89d7fdd3
Author: Rishabh Kumar <[email protected]>
AuthorDate: Thu Feb 6 01:05:28 2025 +0530

    OAK-11452 : exported full gc OSGi configs as metrics
---
 .../oak/plugins/document/FullGCStatsCollector.java | 61 ++++++++++++++++++
 .../plugins/document/FullGCStatsCollectorImpl.java | 70 ++++++++++++++++++++-
 .../plugins/document/VersionGarbageCollector.java  | 13 ++++
 .../document/FullGCStatsCollectorImplTest.java     | 73 ++++++++++++++++++++++
 4 files changed, 216 insertions(+), 1 deletion(-)

diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java
index f730865109..f6a1eb4256 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java
@@ -101,4 +101,65 @@ public interface FullGCStatsCollector {
      * @param stats {@link VersionGCStats} containing FullGC phases timer
      */
     void finished(VersionGCStats stats);
+
+    // FullGC OSGi config stats
+    /**
+     * Indicates that the FullGC process is enabled.
+     * <p>
+     * This method is called to signal that the FullGC process is active and 
ready to perform garbage collection.
+     */
+    void enabled();
+
+    /**
+     * Sets the mode for the FullGC process.
+     * <p>
+     * This method is called to specify the mode in which the FullGC process 
should operate.
+     *
+     * @param mode the mode to set for the FullGC process
+     */
+    void mode(int mode);
+
+    /**
+     * Indicates that the embedded verification process is enabled for FullGC.
+     * <p>
+     * This method is called to signal that the verification process is active 
and ready to perform embedded verification
+     * during the FullGC process.
+     */
+    void verificationEnabled();
+
+    /**
+     * Sets the delay factor for the FullGC process.
+     * <p>
+     * This method is called to specify the delay factor that should be used 
during the FullGC process.
+     *
+     * @param delayFactor the delay factor to set for the FullGC process
+     */
+    void delayFactor(double delayFactor);
+
+    /**
+     * Sets the batch size for the FullGC process.
+     * <p>
+     * This method is called to specify the batch size that should be used 
during the FullGC process.
+     *
+     * @param batchSize the batch size to set for the FullGC process
+     */
+    void batchSize(long batchSize);
+
+    /**
+     * Sets the progress size for the FullGC process.
+     * <p>
+     * This method is called to specify the progress size that should be used 
during the FullGC process.
+     *
+     * @param progressSize the progress size to set for the FullGC process
+     */
+    void progressSize(long progressSize);
+
+    /**
+     * Sets the maximum age for the FullGC process (in millis).
+     * <p>
+     * This method is called to specify the maximum age that should be used 
during the FullGC process.
+     *
+     * @param maxAge the maximum age to set for the FullGC process
+     */
+    void maxAge(long maxAge);
 }
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java
index 8ff70733fa..9fd87a52ba 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java
@@ -58,6 +58,14 @@ class FullGCStatsCollectorImpl implements 
FullGCStatsCollector {
     static final String COUNTER = "COUNTER";
     static final String FAILURE_COUNTER = "FAILURE";
 
+    static final String ENABLED = "ENABLED";
+    static final String MODE = "MODE";
+    static final String DELAY_FACTOR = "DELAY_FACTOR";
+    static final String BATCH_SIZE = "BATCH_SIZE";
+    static final String PROGRESS_SIZE = "PROGRESS_SIZE";
+    static final String EMBEDDED_VERIFICATION_ENABLED = 
"EMBEDDED_VERIFICATION_ENABLED";
+    static final String MAX_AGE = "MAX_AGE";
+
     private final StatisticsProvider provider;
 
     private final MeterStats readDoc;
@@ -84,6 +92,15 @@ class FullGCStatsCollectorImpl implements 
FullGCStatsCollector {
     private final CounterStats counter;
     private final CounterStats failureCounter;
 
+    // FullGC OSGi config stats
+    private final CounterStats enabled;
+    private final CounterStats mode;
+    private final CounterStats delayFactor;
+    private final CounterStats batchSize;
+    private final CounterStats progressSize;
+    private final CounterStats embeddedVerificationEnabled;
+    private final CounterStats maxAge;
+
     FullGCStatsCollectorImpl(StatisticsProvider provider) {
         this.provider = provider;
 
@@ -110,6 +127,15 @@ class FullGCStatsCollectorImpl implements 
FullGCStatsCollector {
 
         counter = counter(provider, COUNTER);
         failureCounter = counter(provider, FAILURE_COUNTER);
+
+        // FullGC OSGi config stats
+        enabled = counter(provider, ENABLED);
+        mode = counter(provider, MODE);
+        delayFactor = counter(provider, DELAY_FACTOR);
+        batchSize = counter(provider, BATCH_SIZE);
+        progressSize = counter(provider, PROGRESS_SIZE);
+        embeddedVerificationEnabled = counter(provider, 
EMBEDDED_VERIFICATION_ENABLED);
+        maxAge = counter(provider, MAX_AGE);
     }
 
     //---------------------< FullGCStatsCollector >-------------------------
@@ -184,11 +210,53 @@ class FullGCStatsCollectorImpl implements 
FullGCStatsCollector {
         }
     }
 
+    @Override
+    public void enabled() {
+        enabled.inc();
+    }
+
+    @Override
+    public void mode(int mode) {
+        this.mode.inc(mode);
+    }
+
+    @Override
+    public void verificationEnabled() {
+        embeddedVerificationEnabled.inc();
+    }
+
+    @Override
+    public void delayFactor(double delayFactor) {
+        this.delayFactor.inc((long) delayFactor);
+    }
+
+    @Override
+    public void batchSize(long batchSize) {
+        this.batchSize.inc(batchSize);
+    }
+
+    @Override
+    public void progressSize(long progressSize) {
+        this.progressSize.inc(progressSize);
+    }
+
+    @Override
+    public void maxAge(long maxAge) {
+        this.maxAge.inc(maxAge);
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("FullGCStatsCollectorImpl{");
-        sb.append("readDoc=").append(readDoc.getCount());
+        sb.append("enabled=").append(enabled.getCount());
+        sb.append(", mode=").append(mode.getCount());
+        sb.append(", delayFactor=").append(delayFactor.getCount());
+        sb.append(", batchSize=").append(batchSize.getCount());
+        sb.append(", progressSize=").append(progressSize.getCount());
+        sb.append(", 
embeddedVerificationEnabled=").append(embeddedVerificationEnabled.getCount());
+        sb.append(", maxAge=").append(maxAge.getCount());
+        sb.append(", readDoc=").append(readDoc.getCount());
         sb.append(", 
candidateRevisions=").append(mapToString(candidateRevisions));
         sb.append(", 
candidateInternalRevisions=").append(mapToString(candidateInternalRevisions));
         sb.append(", 
candidateProperties=").append(mapToString(candidateProperties));
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
index 6fe93754e5..b4b5844e7e 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
@@ -250,6 +250,19 @@ public class VersionGarbageCollector {
     public void setStatisticsProvider(StatisticsProvider provider) {
         this.gcStats = new RevisionGCStats(provider);
         this.fullGCStats = new FullGCStatsCollectorImpl(provider);
+
+        // save OSGi configuration metrics
+        if (fullGCEnabled) {
+            this.fullGCStats.enabled();
+            this.fullGCStats.mode(fullGcMode.ordinal());
+            this.fullGCStats.delayFactor(fullGCDelayFactor);
+            this.fullGCStats.batchSize(fullGCBatchSize);
+            this.fullGCStats.progressSize(fullGCProgressSize);
+            this.fullGCStats.maxAge(fullGcMaxAgeInMillis);
+            if (embeddedVerification) {
+                this.fullGCStats.verificationEnabled();
+            }
+        }
     }
 
     @NotNull
diff --git 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java
 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java
index 6c46684749..e8da810f23 100644
--- 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java
+++ 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java
@@ -23,6 +23,7 @@ import com.codahale.metrics.Meter;
 import com.codahale.metrics.Timer;
 import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
 import org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.CounterStats;
 import org.apache.jackrabbit.oak.stats.MeterStats;
 import org.junit.After;
 import org.junit.Test;
@@ -34,20 +35,27 @@ import static 
java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import static org.apache.commons.lang3.reflect.FieldUtils.readField;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.BATCH_SIZE;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_DELETED_OLD_REVS_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_DELETED_PROPS_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_FULL_GC_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_ORPHAN_NODES_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_UNMERGED_BC_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COUNTER;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELAY_FACTOR;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_ORPHAN_NODE;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_PROPERTY;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_UNMERGED_BC;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETE_FULL_GC_DOCS_TIMER;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.EMBEDDED_VERIFICATION_ENABLED;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.ENABLED;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_ACTIVE_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_TIMER;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FAILURE_COUNTER;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.MAX_AGE;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.MODE;
+import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.PROGRESS_SIZE;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.READ_DOC;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.SKIPPED_DOC;
 import static 
org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.UPDATED_DOC;
@@ -164,6 +172,71 @@ public class FullGCStatsCollectorImplTest {
         assertEquals(1, failureCounter.getCount());
     }
 
+    @Test
+    public void getEnabled() throws IllegalAccessException {
+        final Counter c = getCounter(ENABLED);
+        long count = c.getCount();
+        stats.enabled();
+        assertEquals(count + 1, c.getCount());
+        assertEquals(count + 1, ((CounterStats) readField(stats, "enabled", 
true)).getCount());
+    }
+
+    @Test
+    public void getMode() throws IllegalAccessException {
+        final Counter c = getCounter(MODE);
+        long count = c.getCount();
+        stats.mode(4);
+        assertEquals(count + 4, c.getCount());
+        assertEquals(count + 4, ((CounterStats) readField(stats, "mode", 
true)).getCount());
+    }
+
+    @Test
+    public void getDelayFactor() throws IllegalAccessException {
+        final Counter c = getCounter(DELAY_FACTOR);
+        long count = c.getCount();
+        stats.delayFactor(4.0);
+        assertEquals(count + 4, c.getCount());
+        assertEquals(count + 4, ((CounterStats) readField(stats, 
"delayFactor", true)).getCount());
+    }
+
+    @Test
+    public void getBatchSize() throws IllegalAccessException {
+        final Counter c = getCounter(BATCH_SIZE);
+        long count = c.getCount();
+        stats.batchSize(400);
+        assertEquals(count + 400, c.getCount());
+        assertEquals(count + 400, ((CounterStats) readField(stats, 
"batchSize", true)).getCount());
+    }
+
+    @Test
+    public void getProgressSize() throws IllegalAccessException {
+        final Counter c = getCounter(PROGRESS_SIZE);
+        long count = c.getCount();
+        stats.progressSize(4000);
+        assertEquals(count + 4000, c.getCount());
+        assertEquals(count + 4000, ((CounterStats) readField(stats, 
"progressSize", true)).getCount());
+    }
+
+    @Test
+    public void getEmbeddedVerificationEnabled() throws IllegalAccessException 
{
+        final Counter c = getCounter(EMBEDDED_VERIFICATION_ENABLED);
+        long count = c.getCount();
+        stats.verificationEnabled();
+        assertEquals(count + 1, c.getCount());
+        assertEquals(count + 1, ((CounterStats) readField(stats, 
"embeddedVerificationEnabled", true)).getCount());
+    }
+
+    @Test
+    public void getMaxAge() throws IllegalAccessException {
+        final Counter c = getCounter(MAX_AGE);
+        long count = c.getCount();
+        stats.maxAge(86400);
+        assertEquals(count + 86400, c.getCount());
+        assertEquals(count + 86400, ((CounterStats) readField(stats, "maxAge", 
true)).getCount());
+    }
+
+    // helper methods
+
     private void assertTimer(long expected, String name) {
         assertEquals(expected, 
NANOSECONDS.toMillis(getTimer(name).getSnapshot().getMax()));
     }

Reply via email to