Skip to content

Commit

Permalink
HBASE-27540 add client side counter metrics for failed rpc calls (#4929)
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Beaudreault <[email protected]>
  • Loading branch information
vli02 authored and bbeaudreault committed Dec 21, 2022
1 parent d10a44f commit b63e4b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static String getScope(Configuration conf, String clusterId, Object connectionOb
}

private static final String CNT_BASE = "rpcCount_";
private static final String FAILURE_CNT_BASE = "rpcFailureCount_";
private static final String DRTN_BASE = "rpcCallDurationMs_";
private static final String REQ_BASE = "rpcCallRequestSizeBytes_";
private static final String RESP_BASE = "rpcCallResponseSizeBytes_";
Expand Down Expand Up @@ -637,14 +638,17 @@ private void shutdown() {
}

/** Report RPC context to metrics system. */
public void updateRpc(MethodDescriptor method, Message param, CallStats stats) {
public void updateRpc(MethodDescriptor method, Message param, CallStats stats, boolean failed) {
int callsPerServer = stats.getConcurrentCallsPerServer();
if (callsPerServer > 0) {
concurrentCallsPerServerHist.update(callsPerServer);
}
// Update the counter that tracks RPCs by type.
final String methodName = method.getService().getName() + "_" + method.getName();
getMetric(CNT_BASE + methodName, rpcCounters, counterFactory).inc();
if (failed) {
getMetric(FAILURE_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
}
// this implementation is tied directly to protobuf implementation details. would be better
// if we could dispatch based on something static, ie, request Message type.
if (method.getService() == ClientService.getDescriptor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,16 @@ private T getConnection(ConnectionId remoteId) throws IOException {
private void onCallFinished(Call call, HBaseRpcController hrc, Address addr,
RpcCallback<Message> callback) {
call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.getStartTime());
final boolean failed = (call.error != null) ? true : false;
if (metrics != null) {
metrics.updateRpc(call.md, call.param, call.callStats);
metrics.updateRpc(call.md, call.param, call.callStats, failed);
}
if (LOG.isTraceEnabled()) {
LOG.trace("CallId: {}, call: {}, startTime: {}ms, callTime: {}ms", call.id, call.md.getName(),
call.getStartTime(), call.callStats.getCallTimeMs());
LOG.trace("CallId: {}, call: {}, startTime: {}ms, callTime: {}ms, status: {}", call.id,
call.md.getName(), call.getStartTime(), call.callStats.getCallTimeMs(),
failed ? "failed" : "successful");
}
if (call.error != null) {
if (failed) {
if (call.error instanceof RemoteException) {
call.error.fillInStackTrace();
hrc.setFailed(call.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.codahale.metrics.Counter;
import com.codahale.metrics.RatioGauge;
import com.codahale.metrics.RatioGauge.Ratio;
import java.io.IOException;
Expand Down Expand Up @@ -176,37 +177,51 @@ public void testStaticMetrics() throws IOException {

for (int i = 0; i < loop; i++) {
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Get"),
GetRequest.getDefaultInstance(), MetricsConnection.newCallStats());
GetRequest.getDefaultInstance(), MetricsConnection.newCallStats(), false);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Scan"),
ScanRequest.getDefaultInstance(), MetricsConnection.newCallStats());
ScanRequest.getDefaultInstance(), MetricsConnection.newCallStats(), false);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Multi"),
MultiRequest.getDefaultInstance(), MetricsConnection.newCallStats());
MultiRequest.getDefaultInstance(), MetricsConnection.newCallStats(), true);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.APPEND, new Append(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats());
MetricsConnection.newCallStats(), false);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, new Delete(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats());
MetricsConnection.newCallStats(), false);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.INCREMENT, new Increment(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats());
MetricsConnection.newCallStats(), false);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))).setRegion(region)
.build(),
MetricsConnection.newCallStats());
MetricsConnection.newCallStats(), false);
}
final String rpcCountPrefix = "rpcCount_" + ClientService.getDescriptor().getName() + "_";
final String rpcFailureCountPrefix =
"rpcFailureCount_" + ClientService.getDescriptor().getName() + "_";
String metricKey;
long metricVal;
Counter counter;
for (String method : new String[] { "Get", "Scan", "Mutate" }) {
final String metricKey = "rpcCount_" + ClientService.getDescriptor().getName() + "_" + method;
final long metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
metricKey = rpcCountPrefix + method;
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop);
metricKey = rpcFailureCountPrefix + method;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
}
metricKey = rpcFailureCountPrefix + "Multi";
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] {
METRICS.getGetTracker(), METRICS.getScanTracker(), METRICS.getMultiTracker(),
METRICS.getAppendTracker(), METRICS.getDeleteTracker(), METRICS.getIncrementTracker(),
Expand Down

0 comments on commit b63e4b7

Please sign in to comment.