Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,27 @@ public void updateRpc(MethodDescriptor method, Message param, CallStats stats, T
concurrentCallsPerServerHist.update(callsPerServer);
}
// Update the counter that tracks RPCs by type.
final String methodName = method.getService().getName() + "_" + method.getName();
String methodName = method.getService().getName() + "_" + method.getName();
// Distinguish mutate types.
if ("Mutate".equals(method.getName())) {
final MutationType type = ((MutateRequest) param).getMutation().getMutateType();
switch (type) {
case APPEND:
methodName += "(Append)";
break;
case DELETE:
methodName += "(Delete)";
break;
case INCREMENT:
methodName += "(Increment)";
break;
case PUT:
methodName += "(Put)";
break;
default:
throw new RuntimeException("Unrecognized mutation type " + type);
}
}
getMetric(CNT_BASE + methodName, rpcCounters, counterFactory).inc();
if (e != null) {
getMetric(FAILURE_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public void testStaticMetrics() throws IOException {
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))).setRegion(region)
.build(),
MetricsConnection.newCallStats(), null);
MetricsConnection.newCallStats(),
new CallTimeoutException("test with CallTimeoutException"));
}

final String rpcCountPrefix = "rpcCount_" + ClientService.getDescriptor().getName() + "_";
Expand All @@ -188,15 +189,15 @@ public void testStaticMetrics() throws IOException {
long metricVal;
Counter counter;

for (String method : new String[] { "Get", "Scan", "Multi", "Mutate" }) {
for (String method : new String[] { "Get", "Scan", "Multi" }) {
metricKey = rpcCountPrefix + method;
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop);
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);

metricKey = rpcFailureCountPrefix + method;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
if (method.equals("Get") || method.equals("Mutate")) {
if (method.equals("Get")) {
// no failure
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
} else {
Expand All @@ -205,6 +206,24 @@ public void testStaticMetrics() throws IOException {
}
}

String method = "Mutate";
for (String mutationType : new String[] { "Append", "Delete", "Increment", "Put" }) {
metricKey = rpcCountPrefix + method + "(" + mutationType + ")";
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);

metricKey = rpcFailureCountPrefix + method + "(" + mutationType + ")";
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
if (mutationType.equals("Put")) {
// no failure
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
} else {
// has failure
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
}
}

// remote exception
metricKey = "rpcRemoteExceptions_IOException";
counter = METRICS.getRpcCounters().get(metricKey);
Expand All @@ -215,13 +234,13 @@ public void testStaticMetrics() throws IOException {
metricKey = "rpcLocalExceptions_CallTimeoutException";
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop * 2);

// total exception
metricKey = "rpcTotalExceptions";
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop * 2);
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop * 3);

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