Skip to content

Commit 047f077

Browse files
zhuyaogaifantasyjay.zhu
authored
HBASE-27845 Distinguish the mutate types of rpc error in MetricsConnection. (#5224)
Co-authored-by: fantasy <[email protected]> Co-authored-by: jay.zhu <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent d1f29d0 commit 047f077

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,28 @@ public void updateRpc(MethodDescriptor method, Message param, CallStats stats, T
652652
concurrentCallsPerServerHist.update(callsPerServer);
653653
}
654654
// Update the counter that tracks RPCs by type.
655-
final String methodName = method.getService().getName() + "_" + method.getName();
655+
StringBuilder methodName = new StringBuilder();
656+
methodName.append(method.getService().getName()).append("_").append(method.getName());
657+
// Distinguish mutate types.
658+
if ("Mutate".equals(method.getName())) {
659+
final MutationType type = ((MutateRequest) param).getMutation().getMutateType();
660+
switch (type) {
661+
case APPEND:
662+
methodName.append("(Append)");
663+
break;
664+
case DELETE:
665+
methodName.append("(Delete)");
666+
break;
667+
case INCREMENT:
668+
methodName.append("(Increment)");
669+
break;
670+
case PUT:
671+
methodName.append("(Put)");
672+
break;
673+
default:
674+
methodName.append("(Unknown)");
675+
}
676+
}
656677
getMetric(CNT_BASE + methodName, rpcCounters, counterFactory).inc();
657678
if (e != null) {
658679
getMetric(FAILURE_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
@@ -729,7 +750,7 @@ public void updateRpc(MethodDescriptor method, Message param, CallStats stats, T
729750
}
730751
}
731752
// Fallback to dynamic registry lookup for DDL methods.
732-
updateRpcGeneric(methodName, stats);
753+
updateRpcGeneric(methodName.toString(), stats);
733754
}
734755

735756
public void incrCacheDroppingExceptions(Object exception) {

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestMetricsConnection.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testMetricsConnectionScope() throws IOException {
9999
}
100100

101101
@Test
102-
public void testMetricsWithMutiConnections() throws IOException {
102+
public void testMetricsWithMultiConnections() throws IOException {
103103
Configuration conf = new Configuration();
104104
conf.setBoolean(MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY, true);
105105
conf.set(MetricsConnection.METRICS_SCOPE_KEY, "unit-test");
@@ -178,7 +178,8 @@ public void testStaticMetrics() throws IOException {
178178
MutateRequest.newBuilder()
179179
.setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))).setRegion(region)
180180
.build(),
181-
MetricsConnection.newCallStats(), null);
181+
MetricsConnection.newCallStats(),
182+
new CallTimeoutException("test with CallTimeoutException"));
182183
}
183184

184185
final String rpcCountPrefix = "rpcCount_" + ClientService.getDescriptor().getName() + "_";
@@ -188,40 +189,58 @@ public void testStaticMetrics() throws IOException {
188189
long metricVal;
189190
Counter counter;
190191

191-
for (String method : new String[] { "Get", "Scan", "Multi", "Mutate" }) {
192+
for (String method : new String[] { "Get", "Scan", "Multi" }) {
192193
metricKey = rpcCountPrefix + method;
193194
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
194-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop);
195+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop);
195196

196197
metricKey = rpcFailureCountPrefix + method;
197198
counter = METRICS.getRpcCounters().get(metricKey);
198199
metricVal = (counter != null) ? counter.getCount() : 0;
199-
if (method.equals("Get") || method.equals("Mutate")) {
200+
if (method.equals("Get")) {
200201
// no failure
201-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
202+
assertEquals("metric: " + metricKey + " val: " + metricVal, 0, metricVal);
202203
} else {
203204
// has failure
204-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
205+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop);
206+
}
207+
}
208+
209+
String method = "Mutate";
210+
for (String mutationType : new String[] { "Append", "Delete", "Increment", "Put" }) {
211+
metricKey = rpcCountPrefix + method + "(" + mutationType + ")";
212+
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
213+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop);
214+
215+
metricKey = rpcFailureCountPrefix + method + "(" + mutationType + ")";
216+
counter = METRICS.getRpcCounters().get(metricKey);
217+
metricVal = (counter != null) ? counter.getCount() : 0;
218+
if (mutationType.equals("Put")) {
219+
// has failure
220+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop);
221+
} else {
222+
// no failure
223+
assertEquals("metric: " + metricKey + " val: " + metricVal, 0, metricVal);
205224
}
206225
}
207226

208227
// remote exception
209228
metricKey = "rpcRemoteExceptions_IOException";
210229
counter = METRICS.getRpcCounters().get(metricKey);
211230
metricVal = (counter != null) ? counter.getCount() : 0;
212-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
231+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop);
213232

214233
// local exception
215234
metricKey = "rpcLocalExceptions_CallTimeoutException";
216235
counter = METRICS.getRpcCounters().get(metricKey);
217236
metricVal = (counter != null) ? counter.getCount() : 0;
218-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
237+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop * 2);
219238

220239
// total exception
221240
metricKey = "rpcTotalExceptions";
222241
counter = METRICS.getRpcCounters().get(metricKey);
223242
metricVal = (counter != null) ? counter.getCount() : 0;
224-
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop * 2);
243+
assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop * 3);
225244

226245
for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] {
227246
METRICS.getGetTracker(), METRICS.getScanTracker(), METRICS.getMultiTracker(),

0 commit comments

Comments
 (0)