Skip to content

Commit

Permalink
HBASE-28845 table level wal appendSize and replication source metrics…
Browse files Browse the repository at this point in the history
… not correctly shown in /jmx response
  • Loading branch information
terrytlu committed Sep 19, 2024
1 parent 5cf9170 commit c96894c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ public String getQualifierAsString() {
return qualifierAsString;
}

public String getMetricPrefixTableName() {
return "Namespace_" + this.getNamespaceAsString() + "table_" + this.getQualifierAsString();
}

/** Returns A pointer to TableName as String bytes. */
public byte[] toBytes() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void incrementAppendSize(TableName tableName, long size) {
if (tableAppendSizeCounter == null) {
// Ideally putIfAbsent is atomic and we don't need a branch check but we still do it to avoid
// expensive string construction for every append.
String metricsKey = String.format("%s.%s", tableName, APPEND_SIZE);
String metricsKey = String.format("%s.%s", tableName.getMetricPrefixTableName(), APPEND_SIZE);
perTableAppendSize.putIfAbsent(tableName,
getMetricsRegistry().newCounter(metricsKey, APPEND_SIZE_DESC, 0L));
tableAppendSizeCounter = perTableAppendSize.get(tableName);
Expand All @@ -106,7 +106,8 @@ public void incrementAppendCount(TableName tableName) {
appendCount.incr();
MutableFastCounter tableAppendCounter = perTableAppendCount.get(tableName);
if (tableAppendCounter == null) {
String metricsKey = String.format("%s.%s", tableName, APPEND_COUNT);
String metricsKey =
String.format("%s.%s", tableName.getMetricPrefixTableName(), APPEND_COUNT);
perTableAppendCount.putIfAbsent(tableName,
getMetricsRegistry().newCounter(metricsKey, APPEND_COUNT_DESC, 0L));
tableAppendCounter = perTableAppendCount.get(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void updateTableLevelMetrics(List<Pair<Entry, Long>> walEntries) {
for (Pair<Entry, Long> walEntryWithSize : walEntries) {
Entry entry = walEntryWithSize.getFirst();
long entrySize = walEntryWithSize.getSecond();
String tableName = entry.getKey().getTableName().getNameAsString();
String tableName = entry.getKey().getTableName().getMetricPrefixTableName();
long writeTime = entry.getKey().getWriteTime();
long age = EnvironmentEdgeManager.currentTime() - writeTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ public void testPerTableWALMetrics() throws Exception {
// Validate the metrics
for (int i = 0; i < numThreads; i++) {
TableName tableName = TableName.valueOf("tab_" + i);
long tableAppendCount =
registry.getCounter(tableName + "." + MetricsWALSource.APPEND_COUNT, -1).value();
long tableAppendCount = registry
.getCounter(tableName.getMetricPrefixTableName() + "." + MetricsWALSource.APPEND_COUNT, -1)
.value();
assertEquals(numIters, tableAppendCount);
long tableAppendSize =
registry.getCounter(tableName + "." + MetricsWALSource.APPEND_SIZE, -1).value();
long tableAppendSize = registry
.getCounter(tableName.getMetricPrefixTableName() + "." + MetricsWALSource.APPEND_SIZE, -1)
.value();
assertEquals(i * numIters, tableAppendSize);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ public void testMetricsSourceBaseSourcePassThrough() {
source.getSingleSourceSourceByTable().containsKey("RandomNewTable");
Assert.assertEquals(false, containsRandomNewTable);
source.updateTableLevelMetrics(createWALEntriesWithSize("RandomNewTable"));
containsRandomNewTable = source.getSingleSourceSourceByTable().containsKey("RandomNewTable");
TableName tableName1 = TableName.valueOf("RandomNewTable");
containsRandomNewTable = source.getSingleSourceSourceByTable().containsKey(tableName1.getMetricPrefixTableName());
Assert.assertEquals(true, containsRandomNewTable);
MetricsReplicationTableSource msr = source.getSingleSourceSourceByTable().get("RandomNewTable");
MetricsReplicationTableSource msr = source.getSingleSourceSourceByTable().get(tableName1.getMetricPrefixTableName());

// age should be greater than zero we created the entry with time in the past
Assert.assertTrue(msr.getLastShippedAge() > 0);
Expand Down

0 comments on commit c96894c

Please sign in to comment.