Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11452 : exported full gc OSGi configs as metrics #2054

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 >-------------------------
Expand Down Expand Up @@ -184,11 +210,53 @@ public void finished(VersionGCStats stats) {
}
}

@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ void setFullGcMaxAge(final long fullGcMaxAge, final TimeUnit unit) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -34,20 +35,27 @@
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;
Expand Down Expand Up @@ -164,6 +172,71 @@ public void counters() {
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()));
}
Expand Down
Loading