HBASE-25189 [Metrics] Add checkAndPut and checkAndDelete latency metrics at table level (#2549)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Reid Chan 2020-10-25 17:46:14 +08:00
parent f7e6143f49
commit 70631e901f
6 changed files with 94 additions and 20 deletions

View File

@ -53,6 +53,9 @@ public interface MetricsTableLatencies {
String DELETE_BATCH_TIME = "deleteBatchTime";
String INCREMENT_TIME = "incrementTime";
String APPEND_TIME = "appendTime";
String CHECK_AND_DELETE_TIME = "checkAndDeleteTime";
String CHECK_AND_PUT_TIME = "checkAndPutTime";
String CHECK_AND_MUTATE_TIME = "checkAndMutateTime";
/**
* Update the Put time histogram
@ -125,4 +128,26 @@ public interface MetricsTableLatencies {
* @param t time it took
*/
void updateScanTime(String tableName, long t);
/**
* Update the CheckAndDelete time histogram.
* @param nameAsString The table the metric is for
* @param time time it took
*/
void updateCheckAndDelete(String nameAsString, long time);
/**
* Update the CheckAndPut time histogram.
* @param nameAsString The table the metric is for
* @param time time it took
*/
void updateCheckAndPut(String nameAsString, long time);
/**
* Update the CheckAndMutate time histogram.
* @param nameAsString The table the metric is for
* @param time time it took
*/
void updateCheckAndMutate(String nameAsString, long time);
}

View File

@ -47,6 +47,9 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics
final MetricHistogram deleteBatchTimeHisto;
final MetricHistogram scanTimeHisto;
final MetricHistogram scanSizeHisto;
final MetricHistogram checkAndDeleteTimeHisto;
final MetricHistogram checkAndPutTimeHisto;
final MetricHistogram checkAndMutateTimeHisto;
TableHistograms(DynamicMetricsRegistry registry, TableName tn) {
getTimeHisto = registry.newTimeHistogram(qualifyMetricsName(tn, GET_TIME));
@ -60,6 +63,12 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics
qualifyMetricsName(tn, DELETE_BATCH_TIME));
scanTimeHisto = registry.newTimeHistogram(qualifyMetricsName(tn, SCAN_TIME));
scanSizeHisto = registry.newSizeHistogram(qualifyMetricsName(tn, SCAN_SIZE));
checkAndDeleteTimeHisto =
registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_DELETE_TIME));
checkAndPutTimeHisto =
registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_PUT_TIME));
checkAndMutateTimeHisto =
registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_MUTATE_TIME));
}
public void updatePut(long time) {
@ -97,6 +106,18 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics
public void updateScanTime(long t) {
scanTimeHisto.add(t);
}
public void updateCheckAndDeleteTime(long t) {
checkAndDeleteTimeHisto.add(t);
}
public void updateCheckAndPutTime(long t) {
checkAndPutTimeHisto.add(t);
}
public void updateCheckAndMutateTime(long t) {
checkAndMutateTimeHisto.add(t);
}
}
@VisibleForTesting
@ -174,6 +195,21 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics
getOrCreateTableHistogram(tableName).updateScanTime(t);
}
@Override
public void updateCheckAndDelete(String tableName, long time) {
getOrCreateTableHistogram(tableName).updateCheckAndDeleteTime(time);
}
@Override
public void updateCheckAndPut(String tableName, long time) {
getOrCreateTableHistogram(tableName).updateCheckAndPutTime(time);
}
@Override
public void updateCheckAndMutate(String tableName, long time) {
getOrCreateTableHistogram(tableName).updateCheckAndMutateTime(time);
}
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);

View File

@ -145,15 +145,24 @@ public class MetricsRegionServer {
serverSource.updateDeleteBatch(t);
}
public void updateCheckAndDelete(long t) {
public void updateCheckAndDelete(TableName tn, long t) {
if (tableMetrics != null && tn != null) {
tableMetrics.updateCheckAndDelete(tn, t);
}
serverSource.updateCheckAndDelete(t);
}
public void updateCheckAndPut(long t) {
public void updateCheckAndPut(TableName tn, long t) {
if (tableMetrics != null && tn != null) {
tableMetrics.updateCheckAndPut(tn, t);
}
serverSource.updateCheckAndPut(t);
}
public void updateCheckAndMutate(long t) {
public void updateCheckAndMutate(TableName tn, long t) {
if (tableMetrics != null && tn != null) {
tableMetrics.updateCheckAndMutate(tn, t);
}
serverSource.updateCheckAndMutate(t);
}

View File

@ -2997,15 +2997,18 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
MetricsRegionServer metricsRegionServer = regionServer.getMetrics();
if (metricsRegionServer != null) {
long after = EnvironmentEdgeManager.currentTime();
metricsRegionServer.updateCheckAndMutate(after - before);
metricsRegionServer.updateCheckAndMutate(
region.getRegionInfo().getTable(), after - before);
MutationType type = mutation.getMutateType();
switch (type) {
case PUT:
metricsRegionServer.updateCheckAndPut(after - before);
metricsRegionServer.updateCheckAndPut(
region.getRegionInfo().getTable(), after - before);
break;
case DELETE:
metricsRegionServer.updateCheckAndDelete(after - before);
metricsRegionServer.updateCheckAndDelete(
region.getRegionInfo().getTable(), after - before);
break;
default:
break;

View File

@ -65,6 +65,18 @@ public class RegionServerTableMetrics {
latencies.updateDeleteBatch(table.getNameAsString(), time);
}
public void updateCheckAndDelete(TableName table, long time) {
latencies.updateCheckAndDelete(table.getNameAsString(), time);
}
public void updateCheckAndPut(TableName table, long time) {
latencies.updateCheckAndPut(table.getNameAsString(), time);
}
public void updateCheckAndMutate(TableName table, long time) {
latencies.updateCheckAndMutate(table.getNameAsString(), time);
}
public void updateScanTime(TableName table, long time) {
latencies.updateScanTime(table.getNameAsString(), time);
}

View File

@ -149,9 +149,9 @@ public class TestMetricsRegionServer {
for (int i=0; i < 17; i ++) {
rsm.updatePut(null, 17);
rsm.updateDelete(null, 17);
rsm.updateCheckAndDelete(17);
rsm.updateCheckAndPut(17);
rsm.updateCheckAndMutate(17);
rsm.updateCheckAndDelete(null, 17);
rsm.updateCheckAndPut(null, 17);
rsm.updateCheckAndMutate(null, 17);
}
HELPER.assertCounter("appendNumOps", 24, serverSource);
@ -172,17 +172,6 @@ public class TestMetricsRegionServer {
HELPER.assertCounter("slowPutCount", 16, serverSource);
}
String FLUSH_TIME = "flushTime";
String FLUSH_TIME_DESC = "Histogram for the time in millis for memstore flush";
String FLUSH_MEMSTORE_SIZE = "flushMemstoreSize";
String FLUSH_MEMSTORE_SIZE_DESC = "Histogram for number of bytes in the memstore for a flush";
String FLUSH_FILE_SIZE = "flushFileSize";
String FLUSH_FILE_SIZE_DESC = "Histogram for number of bytes in the resulting file for a flush";
String FLUSHED_OUTPUT_BYTES = "flushedOutputBytes";
String FLUSHED_OUTPUT_BYTES_DESC = "Total number of bytes written from flush";
String FLUSHED_MEMSTORE_BYTES = "flushedMemstoreBytes";
String FLUSHED_MEMSTORE_BYTES_DESC = "Total number of bytes of cells in memstore from flush";
@Test
public void testFlush() {
rsm.updateFlush(null, 1, 2, 3);