Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-15242: add client side metrics for timeout and remote exceptions. #5023

Merged
merged 5 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.ipc.CallTimeoutException;
import org.apache.hadoop.hbase.ipc.RemoteWithExtrasException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;

Expand Down Expand Up @@ -118,6 +120,9 @@ 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 TIMEOUT_CNT_BASE = "rpcExceptionCallTimeout_";
private static final String REMOTE_CNT_BASE = "rpcExceptionRemote_";
vli02 marked this conversation as resolved.
Show resolved Hide resolved
private static final String OTHERS_CNT_BASE = "rpcExceptionOthers_";
vli02 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -638,16 +643,23 @@ private void shutdown() {
}

/** Report RPC context to metrics system. */
public void updateRpc(MethodDescriptor method, Message param, CallStats stats, boolean failed) {
public void updateRpc(MethodDescriptor method, Message param, CallStats stats, Throwable e) {
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) {
if (e != null) {
getMetric(FAILURE_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
if (e instanceof CallTimeoutException) {
getMetric(TIMEOUT_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
} else if (e instanceof RemoteWithExtrasException) {
getMetric(REMOTE_CNT_BASE + methodName, rpcCounters, counterFactory).inc();
} else {
getMetric(OTHERS_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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,15 @@ 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, failed);
metrics.updateRpc(call.md, call.param, call.callStats, call.error);
}
if (LOG.isTraceEnabled()) {
LOG.trace("CallId: {}, call: {}, startTime: {}ms, callTime: {}ms, status: {}", call.id,
call.md.getName(), call.getStartTime(), call.callStats.getCallTimeMs(),
failed ? "failed" : "successful");
call.error != null ? "failed" : "successful");
}
if (failed) {
if (call.error != null) {
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 @@ -31,6 +31,8 @@
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.ipc.CallTimeoutException;
import org.apache.hadoop.hbase.ipc.RemoteWithExtrasException;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MetricsTests;
Expand Down Expand Up @@ -150,51 +152,98 @@ public void testStaticMetrics() throws IOException {

for (int i = 0; i < loop; i++) {
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Get"),
GetRequest.getDefaultInstance(), MetricsConnection.newCallStats(), false);
GetRequest.getDefaultInstance(), MetricsConnection.newCallStats(), null);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Scan"),
ScanRequest.getDefaultInstance(), MetricsConnection.newCallStats(), false);
ScanRequest.getDefaultInstance(), MetricsConnection.newCallStats(),
new RemoteWithExtrasException("IOException", null, false, false));
vli02 marked this conversation as resolved.
Show resolved Hide resolved
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Multi"),
MultiRequest.getDefaultInstance(), MetricsConnection.newCallStats(), true);
MultiRequest.getDefaultInstance(), MetricsConnection.newCallStats(),
new CallTimeoutException("test with CallTimeoutException"));
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.APPEND, new Append(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats(), false);
MetricsConnection.newCallStats(), null);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, new Delete(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats(), false);
MetricsConnection.newCallStats(), null);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.INCREMENT, new Increment(foo)))
.setRegion(region).build(),
MetricsConnection.newCallStats(), false);
MetricsConnection.newCallStats(), null);
METRICS.updateRpc(ClientService.getDescriptor().findMethodByName("Mutate"),
MutateRequest.newBuilder()
.setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))).setRegion(region)
.build(),
MetricsConnection.newCallStats(), false);
MetricsConnection.newCallStats(), null);
}

final String rpcCountPrefix = "rpcCount_" + ClientService.getDescriptor().getName() + "_";
final String rpcFailureCountPrefix =
"rpcFailureCount_" + ClientService.getDescriptor().getName() + "_";
final String rpcTimeoutCountPrefix =
"rpcExceptionCallTimeout_" + ClientService.getDescriptor().getName() + "_";
final String rpcRemoteCountPrefix =
"rpcExceptionRemote_" + ClientService.getDescriptor().getName() + "_";
String metricKey;
long metricVal;
Counter counter;
for (String method : new String[] { "Get", "Scan", "Mutate" }) {

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

// no failure
metricKey = rpcFailureCountPrefix + method;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
}
metricKey = rpcFailureCountPrefix + "Multi";

final String scanMethod = "Scan";
metricKey = rpcCountPrefix + scanMethod;
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop);
// has failure
metricKey = rpcFailureCountPrefix + scanMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
// no timeout
metricKey = rpcTimeoutCountPrefix + scanMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);
// has remote
metricKey = rpcRemoteCountPrefix + scanMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);

final String multiMethod = "Multi";
metricKey = rpcCountPrefix + multiMethod;
metricVal = METRICS.getRpcCounters().get(metricKey).getCount();
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop);
// has failure
metricKey = rpcFailureCountPrefix + multiMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
// has timeout
metricKey = rpcTimeoutCountPrefix + multiMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop);
// no remote
metricKey = rpcRemoteCountPrefix + multiMethod;
counter = METRICS.getRpcCounters().get(metricKey);
metricVal = (counter != null) ? counter.getCount() : 0;
assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0);

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