Skip to content

Commit e8f5824

Browse files
author
Rishabh Kumar
committed
OAK-11452 : exported full gc OSGi configs as metrics
1 parent 7d24112 commit e8f5824

File tree

4 files changed

+216
-1
lines changed

4 files changed

+216
-1
lines changed

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,65 @@ public interface FullGCStatsCollector {
101101
* @param stats {@link VersionGCStats} containing FullGC phases timer
102102
*/
103103
void finished(VersionGCStats stats);
104+
105+
// FullGC OSGi config stats
106+
/**
107+
* Indicates that the FullGC process is enabled.
108+
* <p>
109+
* This method is called to signal that the FullGC process is active and ready to perform garbage collection.
110+
*/
111+
void enabled();
112+
113+
/**
114+
* Sets the mode for the FullGC process.
115+
* <p>
116+
* This method is called to specify the mode in which the FullGC process should operate.
117+
*
118+
* @param mode the mode to set for the FullGC process
119+
*/
120+
void mode(int mode);
121+
122+
/**
123+
* Indicates that the embedded verification process is enabled for FullGC.
124+
* <p>
125+
* This method is called to signal that the verification process is active and ready to perform embedded verification
126+
* during the FullGC process.
127+
*/
128+
void verificationEnabled();
129+
130+
/**
131+
* Sets the delay factor for the FullGC process.
132+
* <p>
133+
* This method is called to specify the delay factor that should be used during the FullGC process.
134+
*
135+
* @param delayFactor the delay factor to set for the FullGC process
136+
*/
137+
void delayFactor(double delayFactor);
138+
139+
/**
140+
* Sets the batch size for the FullGC process.
141+
* <p>
142+
* This method is called to specify the batch size that should be used during the FullGC process.
143+
*
144+
* @param batchSize the batch size to set for the FullGC process
145+
*/
146+
void batchSize(long batchSize);
147+
148+
/**
149+
* Sets the progress size for the FullGC process.
150+
* <p>
151+
* This method is called to specify the progress size that should be used during the FullGC process.
152+
*
153+
* @param progressSize the progress size to set for the FullGC process
154+
*/
155+
void progressSize(long progressSize);
156+
157+
/**
158+
* Sets the maximum age for the FullGC process (in millis).
159+
* <p>
160+
* This method is called to specify the maximum age that should be used during the FullGC process.
161+
*
162+
* @param maxAge the maximum age to set for the FullGC process
163+
*/
164+
void maxAge(long maxAge);
104165
}

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class FullGCStatsCollectorImpl implements FullGCStatsCollector {
5858
static final String COUNTER = "COUNTER";
5959
static final String FAILURE_COUNTER = "FAILURE";
6060

61+
static final String ENABLED = "ENABLED";
62+
static final String MODE = "MODE";
63+
static final String DELAY_FACTOR = "DELAY_FACTOR";
64+
static final String BATCH_SIZE = "BATCH_SIZE";
65+
static final String PROGRESS_SIZE = "PROGRESS_SIZE";
66+
static final String EMBEDDED_VERIFICATION_ENABLED = "EMBEDDED_VERIFICATION_ENABLED";
67+
static final String MAX_AGE = "MAX_AGE";
68+
6169
private final StatisticsProvider provider;
6270

6371
private final MeterStats readDoc;
@@ -84,6 +92,15 @@ class FullGCStatsCollectorImpl implements FullGCStatsCollector {
8492
private final CounterStats counter;
8593
private final CounterStats failureCounter;
8694

95+
// FullGC OSGi config stats
96+
private final CounterStats enabled;
97+
private final CounterStats mode;
98+
private final CounterStats delayFactor;
99+
private final CounterStats batchSize;
100+
private final CounterStats progressSize;
101+
private final CounterStats embeddedVerificationEnabled;
102+
private final CounterStats maxAge;
103+
87104
FullGCStatsCollectorImpl(StatisticsProvider provider) {
88105
this.provider = provider;
89106

@@ -110,6 +127,15 @@ class FullGCStatsCollectorImpl implements FullGCStatsCollector {
110127

111128
counter = counter(provider, COUNTER);
112129
failureCounter = counter(provider, FAILURE_COUNTER);
130+
131+
// FullGC OSGi config stats
132+
enabled = counter(provider, ENABLED);
133+
mode = counter(provider, MODE);
134+
delayFactor = counter(provider, DELAY_FACTOR);
135+
batchSize = counter(provider, BATCH_SIZE);
136+
progressSize = counter(provider, PROGRESS_SIZE);
137+
embeddedVerificationEnabled = counter(provider, EMBEDDED_VERIFICATION_ENABLED);
138+
maxAge = counter(provider, MAX_AGE);
113139
}
114140

115141
//---------------------< FullGCStatsCollector >-------------------------
@@ -184,11 +210,53 @@ public void finished(VersionGCStats stats) {
184210
}
185211
}
186212

213+
@Override
214+
public void enabled() {
215+
enabled.inc();
216+
}
217+
218+
@Override
219+
public void mode(int mode) {
220+
this.mode.inc(mode);
221+
}
222+
223+
@Override
224+
public void verificationEnabled() {
225+
embeddedVerificationEnabled.inc();
226+
}
227+
228+
@Override
229+
public void delayFactor(double delayFactor) {
230+
this.delayFactor.inc((long) delayFactor);
231+
}
232+
233+
@Override
234+
public void batchSize(long batchSize) {
235+
this.batchSize.inc(batchSize);
236+
}
237+
238+
@Override
239+
public void progressSize(long progressSize) {
240+
this.progressSize.inc(progressSize);
241+
}
242+
243+
@Override
244+
public void maxAge(long maxAge) {
245+
this.maxAge.inc(maxAge);
246+
}
247+
187248
@Override
188249
public String toString() {
189250
StringBuilder sb = new StringBuilder();
190251
sb.append("FullGCStatsCollectorImpl{");
191-
sb.append("readDoc=").append(readDoc.getCount());
252+
sb.append("enabled=").append(enabled.getCount());
253+
sb.append(", mode=").append(mode.getCount());
254+
sb.append(", delayFactor=").append(delayFactor.getCount());
255+
sb.append(", batchSize=").append(batchSize.getCount());
256+
sb.append(", progressSize=").append(progressSize.getCount());
257+
sb.append(", embeddedVerificationEnabled=").append(embeddedVerificationEnabled.getCount());
258+
sb.append(", maxAge=").append(maxAge.getCount());
259+
sb.append(", readDoc=").append(readDoc.getCount());
192260
sb.append(", candidateRevisions=").append(mapToString(candidateRevisions));
193261
sb.append(", candidateInternalRevisions=").append(mapToString(candidateInternalRevisions));
194262
sb.append(", candidateProperties=").append(mapToString(candidateProperties));

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,19 @@ void setFullGcMaxAge(final long fullGcMaxAge, final TimeUnit unit) {
250250
public void setStatisticsProvider(StatisticsProvider provider) {
251251
this.gcStats = new RevisionGCStats(provider);
252252
this.fullGCStats = new FullGCStatsCollectorImpl(provider);
253+
254+
// save OSGi configuration metrics
255+
if (fullGCEnabled) {
256+
this.fullGCStats.enabled();
257+
this.fullGCStats.mode(fullGcMode.ordinal());
258+
this.fullGCStats.delayFactor(fullGCDelayFactor);
259+
this.fullGCStats.batchSize(fullGCBatchSize);
260+
this.fullGCStats.progressSize(fullGCProgressSize);
261+
this.fullGCStats.maxAge(fullGcMaxAgeInMillis);
262+
if (embeddedVerification) {
263+
this.fullGCStats.verificationEnabled();
264+
}
265+
}
253266
}
254267

255268
@NotNull

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.codahale.metrics.Timer;
2424
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
2525
import org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider;
26+
import org.apache.jackrabbit.oak.stats.CounterStats;
2627
import org.apache.jackrabbit.oak.stats.MeterStats;
2728
import org.junit.After;
2829
import org.junit.Test;
@@ -34,20 +35,27 @@
3435
import static java.util.concurrent.TimeUnit.MILLISECONDS;
3536
import static java.util.concurrent.TimeUnit.NANOSECONDS;
3637
import static org.apache.commons.lang3.reflect.FieldUtils.readField;
38+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.BATCH_SIZE;
3739
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_DELETED_OLD_REVS_TIMER;
3840
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_DELETED_PROPS_TIMER;
3941
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_FULL_GC_TIMER;
4042
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_ORPHAN_NODES_TIMER;
4143
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COLLECT_UNMERGED_BC_TIMER;
4244
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.COUNTER;
45+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELAY_FACTOR;
4346
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_ORPHAN_NODE;
4447
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_PROPERTY;
4548
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETED_UNMERGED_BC;
4649
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.DELETE_FULL_GC_DOCS_TIMER;
50+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.EMBEDDED_VERIFICATION_ENABLED;
51+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.ENABLED;
4752
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC;
4853
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_ACTIVE_TIMER;
4954
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_TIMER;
5055
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FAILURE_COUNTER;
56+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.MAX_AGE;
57+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.MODE;
58+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.PROGRESS_SIZE;
5159
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.READ_DOC;
5260
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.SKIPPED_DOC;
5361
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.UPDATED_DOC;
@@ -164,6 +172,71 @@ public void counters() {
164172
assertEquals(1, failureCounter.getCount());
165173
}
166174

175+
@Test
176+
public void getEnabled() throws IllegalAccessException {
177+
final Counter c = getCounter(ENABLED);
178+
long count = c.getCount();
179+
stats.enabled();
180+
assertEquals(count + 1, c.getCount());
181+
assertEquals(count + 1, ((CounterStats) readField(stats, "enabled", true)).getCount());
182+
}
183+
184+
@Test
185+
public void getMode() throws IllegalAccessException {
186+
final Counter c = getCounter(MODE);
187+
long count = c.getCount();
188+
stats.mode(4);
189+
assertEquals(count + 4, c.getCount());
190+
assertEquals(count + 4, ((CounterStats) readField(stats, "mode", true)).getCount());
191+
}
192+
193+
@Test
194+
public void getDelayFactor() throws IllegalAccessException {
195+
final Counter c = getCounter(DELAY_FACTOR);
196+
long count = c.getCount();
197+
stats.delayFactor(4.0);
198+
assertEquals(count + 4, c.getCount());
199+
assertEquals(count + 4, ((CounterStats) readField(stats, "delayFactor", true)).getCount());
200+
}
201+
202+
@Test
203+
public void getBatchSize() throws IllegalAccessException {
204+
final Counter c = getCounter(BATCH_SIZE);
205+
long count = c.getCount();
206+
stats.batchSize(400);
207+
assertEquals(count + 400, c.getCount());
208+
assertEquals(count + 400, ((CounterStats) readField(stats, "batchSize", true)).getCount());
209+
}
210+
211+
@Test
212+
public void getProgressSize() throws IllegalAccessException {
213+
final Counter c = getCounter(PROGRESS_SIZE);
214+
long count = c.getCount();
215+
stats.progressSize(4000);
216+
assertEquals(count + 4000, c.getCount());
217+
assertEquals(count + 4000, ((CounterStats) readField(stats, "progressSize", true)).getCount());
218+
}
219+
220+
@Test
221+
public void getEmbeddedVerificationEnabled() throws IllegalAccessException {
222+
final Counter c = getCounter(EMBEDDED_VERIFICATION_ENABLED);
223+
long count = c.getCount();
224+
stats.verificationEnabled();
225+
assertEquals(count + 1, c.getCount());
226+
assertEquals(count + 1, ((CounterStats) readField(stats, "embeddedVerificationEnabled", true)).getCount());
227+
}
228+
229+
@Test
230+
public void getMaxAge() throws IllegalAccessException {
231+
final Counter c = getCounter(MAX_AGE);
232+
long count = c.getCount();
233+
stats.maxAge(86400);
234+
assertEquals(count + 86400, c.getCount());
235+
assertEquals(count + 86400, ((CounterStats) readField(stats, "maxAge", true)).getCount());
236+
}
237+
238+
// helper methods
239+
167240
private void assertTimer(long expected, String name) {
168241
assertEquals(expected, NANOSECONDS.toMillis(getTimer(name).getSnapshot().getMax()));
169242
}

0 commit comments

Comments
 (0)