cherry pick #183 to release-3.1 (#184)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: birdstorm <samuelwyf@hotmail.com>
This commit is contained in:
ti-srebot 2021-06-07 10:02:41 +08:00 committed by GitHub
parent 01b391ff2f
commit 6a5ea6fb8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -17,6 +17,7 @@ package org.tikv.common.policy;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import io.grpc.Status; import io.grpc.Status;
import io.prometheus.client.Counter;
import io.prometheus.client.Histogram; import io.prometheus.client.Histogram;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.tikv.common.exception.GrpcException; import org.tikv.common.exception.GrpcException;
@ -32,6 +33,12 @@ public abstract class RetryPolicy<RespT> {
.help("grpc request latency.") .help("grpc request latency.")
.labelNames("type") .labelNames("type")
.register(); .register();
public static final Counter GRPC_REQUEST_RETRY_NUM =
Counter.build()
.name("client_java_grpc_requests_retry_num")
.help("grpc request retry num.")
.labelNames("type")
.register();
// handles PD and TiKV's error. // handles PD and TiKV's error.
private ErrorHandler<RespT> handler; private ErrorHandler<RespT> handler;
@ -70,6 +77,7 @@ public abstract class RetryPolicy<RespT> {
// Handle request call error // Handle request call error
boolean retry = handler.handleRequestError(backOffer, e); boolean retry = handler.handleRequestError(backOffer, e);
if (retry) { if (retry) {
GRPC_REQUEST_RETRY_NUM.labels(methodName).inc();
continue; continue;
} }
} }
@ -78,7 +86,7 @@ public abstract class RetryPolicy<RespT> {
if (handler != null) { if (handler != null) {
boolean retry = handler.handleResponseError(backOffer, result); boolean retry = handler.handleResponseError(backOffer, result);
if (retry) { if (retry) {
// add retry counter GRPC_REQUEST_RETRY_NUM.labels(methodName).inc();
continue; continue;
} }
} }