Skip to content

Commit

Permalink
HBASE-14082 Add replica id to JMX metrics names (Lei Chen)
Browse files Browse the repository at this point in the history
  • Loading branch information
enis committed Sep 17, 2015
1 parent c1ac4bb commit 17bdf9f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface MetricsRegionSource extends Comparable<MetricsRegionSource> {
"Number of files that were input for finished, successful or aborted, compactions";
String COPROCESSOR_EXECUTION_STATISTICS = "coprocessorExecutionStatistics";
String COPROCESSOR_EXECUTION_STATISTICS_DESC = "Statistics for coprocessor execution times";
String REPLICA_ID = "replicaid";
String REPLICA_ID_DESC = "The replica ID of a region. 0 is primary, otherwise is secondary";

/**
* Close the region's metrics as this region is closing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public interface MetricsRegionWrapper {
* Get the time spent by coprocessors in this region.
*/
Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics();

/**
* Get the replica id of this region.
*/
int getReplicaId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
regionNamePrefix + MetricsRegionServerSource.WRITE_REQUEST_COUNT,
MetricsRegionServerSource.WRITE_REQUEST_COUNT_DESC),
this.regionWrapper.getWriteRequestCount());
mrb.addCounter(Interns.info(regionNamePrefix + MetricsRegionSource.REPLICA_ID,
MetricsRegionSource.REPLICA_ID_DESC),
this.regionWrapper.getReplicaId());

for (Map.Entry<String, DescriptiveStatistics> entry : this.regionWrapper
.getCoprocessorExecutionStatistics()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,13 @@ public int getRegionHashCode() {
public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
return null;
}

/**
* Always return 0 for testing
*/
@Override
public int getReplicaId() {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@ public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
return coprocessorTimes;
}

/**
* Get the replica id of this region.
*/
@Override
public int getReplicaId() {
return region.getRegionInfo().getReplicaId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;

public class MetricsRegionWrapperStub implements MetricsRegionWrapper {
int replicaid = 0;

/**
* Replica ID set to 0
*/
public MetricsRegionWrapperStub() {
this.replicaid = 0;
}

/**
* Pass in replica ID
*/
public MetricsRegionWrapperStub(int replicaid) {
this.replicaid = replicaid;
}

@Override
public String getTableName() {
Expand Down Expand Up @@ -94,4 +109,12 @@ public int getRegionHashCode() {
public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
return new HashMap<String, DescriptiveStatistics>();
}

/**
* Get the replica id of this region.
*/
@Override
public int getReplicaId() {
return replicaid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,35 @@ public void testRegionWrapperMetrics() {
MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub());
MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource();

HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, agg);
HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 102, agg);
HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount",
101, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount",
102, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize",
103, agg);
HELPER.assertCounter(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid",
0, agg);
mr.close();

// test region with replica id > 0
mr = new MetricsRegion(new MetricsRegionWrapperStub(1));
agg = mr.getSource().getAggregateSource();
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount",
101, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount",
102, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize",
103, agg);
HELPER.assertCounter(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid",
1, agg);
mr.close();
}
}

0 comments on commit 17bdf9f

Please sign in to comment.