Skip to content

Commit

Permalink
Merge pull request #112 from upserve/lookup_data_metrics
Browse files Browse the repository at this point in the history
add metrics for lookup data
  • Loading branch information
ls-nicholas-nassar authored Apr 30, 2021
2 parents 70967c6 + 8dd53a9 commit eedf4a1
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public class AppendOnlyStoreWithMetrics implements AppendOnlyStore {
public static final String SCAN_BYTES_METER_METRIC_NAME = "scanBytesMeter";
public static final String SCAN_KEYS_METER_METRIC_NAME = "scanKeysMeter";

public static final String FLUSHED_KEY_COUNT_GAUGE_METRIC_NAME = "flushedKeyCountGauge";
public static final String FLUSH_COUNT_GAUGE_METRIC_NAME = "flushCountGauge";
public static final String FLUSH_TIMER_GAUGE_METRIC_NAME = "flushTimerGauge";
public static final String LOOKUP_MISS_COUNT_GAUGE_METRIC_NAME = "lookupMissCountGauge";
public static final String LOOKUP_HIT_COUNT_GAUGE_METRIC_NAME = "lookupHitCountGauge";
public static final String CACHE_MISS_COUNT_GAUGE_METRIC_NAME = "cacheMissCountGauge";
public static final String CACHE_HIT_COUNT_GAUGE_METRIC_NAME = "cacheHitCountGauge";
public static final String FIND_KEY_TIMER_GAUGE_METRIC_NAME = "findKeyTimerGauge";
public static final String AVG_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME = "avgLookupDataSizeGauge";
public static final String MAX_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME = "maxLookupDataSizeGauge";
public static final String SUM_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME = "sumLookupDataSizeGauge";

public static final String UPPEND_APPEND_STORE = "uppendAppendStore";

private final AppendOnlyStore store;
Expand Down Expand Up @@ -66,6 +78,40 @@ public AppendOnlyStoreWithMetrics(AppendOnlyStore store, MetricRegistry metrics,
readBytesMeter = metrics.meter(MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), READ_BYTES_METER_METRIC_NAME));
scanBytesMeter = metrics.meter(MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), SCAN_BYTES_METER_METRIC_NAME));
scanKeysMeter = metrics.meter(MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), SCAN_KEYS_METER_METRIC_NAME));

metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), FLUSHED_KEY_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getFlushedKeyCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), FLUSH_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getFlushCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), FLUSH_TIMER_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getFlushTimer);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), LOOKUP_MISS_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getLookupMissCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), LOOKUP_HIT_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getLookupHitCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), CACHE_MISS_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getCacheMissCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), CACHE_HIT_COUNT_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getCacheHitCount);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), FIND_KEY_TIMER_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getFindKeyTimer);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), AVG_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME),
(Gauge<Double>) getLookupDataMetrics()::getAvgLookupDataSize);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), MAX_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getMaxLookupDataSize);
metrics.register(
MetricRegistry.name(rootName, UPPEND_APPEND_STORE, store.getName(), SUM_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME),
(Gauge<Long>) getLookupDataMetrics()::getSumLookupDataSize);
}

@Override
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/upserve/uppend/metrics/LookupDataMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,50 @@ private LookupDataMetrics(
this.sumLookupDataSize = sumLookupDataSize;
}

public long getFlushedKeyCount() {
return flushedKeyCount;
}

public long getFlushCount() {
return flushCount;
}

public long getFlushTimer() {
return flushTimer;
}

public long getLookupMissCount() {
return lookupMissCount;
}

public long getLookupHitCount() {
return lookupHitCount;
}

public long getCacheMissCount() {
return cacheMissCount;
}

public long getCacheHitCount() {
return cacheHitCount;
}

public long getFindKeyTimer() {
return findKeyTimer;
}

public double getAvgLookupDataSize() {
return avgLookupDataSize;
}

public long getMaxLookupDataSize() {
return maxLookupDataSize;
}

public long getSumLookupDataSize() {
return sumLookupDataSize;
}

@Override
public String toString() {
return "LookupDataMetrics{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class AppendOnlyStoreWithMetricsTest {
public void before() {
metrics = new MetricRegistry();
when(store.getName()).thenReturn("testStore");
LookupDataMetrics lookupDataMetrics = new LookupDataMetrics(new LookupDataMetrics.Adders(), new LongSummaryStatistics());
when(store.getLookupDataMetrics()).thenReturn(lookupDataMetrics);
instance = new AppendOnlyStoreWithMetrics(store, metrics, "MetricsRoot");
}

Expand Down Expand Up @@ -174,6 +176,22 @@ public void testGetBlockLongStats() {
assertEquals(v, instance.getBlockedLongMetrics());
}

@Test
public void testGaugeMetrics() {
// The underlying store is mocked, so just test that these are registered
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), FLUSHED_KEY_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), FLUSH_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), FLUSH_TIMER_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), LOOKUP_MISS_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), LOOKUP_HIT_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), CACHE_MISS_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), CACHE_HIT_COUNT_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), FIND_KEY_TIMER_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0.0, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), AVG_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), MAX_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME), null).getValue());
assertEquals(0L, metrics.gauge(MetricRegistry.name("MetricsRoot", UPPEND_APPEND_STORE, store.getName(), SUM_LOOKUP_DATA_SIZE_GAUGE_METRIC_NAME), null).getValue());
}

@Test
public void testKeyCount() {
when(store.keyCount()).thenReturn(5L);
Expand Down

0 comments on commit eedf4a1

Please sign in to comment.