Skip to content

Commit

Permalink
all: implement retry stats (#8362)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Aug 12, 2021
1 parent f07e1e5 commit 1680a99
Show file tree
Hide file tree
Showing 16 changed files with 979 additions and 146 deletions.
30 changes: 28 additions & 2 deletions api/src/main/java/io/grpc/ClientStreamTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ public abstract static class InternalLimitedInfoFactory extends Factory {}
public static final class StreamInfo {
private final Attributes transportAttrs;
private final CallOptions callOptions;
private final int previousAttempts;
private final boolean isTransparentRetry;

StreamInfo(Attributes transportAttrs, CallOptions callOptions, boolean isTransparentRetry) {
StreamInfo(
Attributes transportAttrs, CallOptions callOptions, int previousAttempts,
boolean isTransparentRetry) {
this.transportAttrs = checkNotNull(transportAttrs, "transportAttrs");
this.callOptions = checkNotNull(callOptions, "callOptions");
this.previousAttempts = previousAttempts;
this.isTransparentRetry = isTransparentRetry;
}

Expand All @@ -124,6 +128,15 @@ public CallOptions getCallOptions() {
return callOptions;
}

/**
* Returns the number of preceding attempts for the RPC.
*
* @since 1.40.0
*/
public int getPreviousAttempts() {
return previousAttempts;
}

/**
* Whether the stream is a transparent retry.
*
Expand All @@ -142,6 +155,7 @@ public Builder toBuilder() {
return new Builder()
.setCallOptions(callOptions)
.setTransportAttrs(transportAttrs)
.setPreviousAttempts(previousAttempts)
.setIsTransparentRetry(isTransparentRetry);
}

Expand All @@ -159,6 +173,7 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("transportAttrs", transportAttrs)
.add("callOptions", callOptions)
.add("previousAttempts", previousAttempts)
.add("isTransparentRetry", isTransparentRetry)
.toString();
}
Expand All @@ -171,6 +186,7 @@ public String toString() {
public static final class Builder {
private Attributes transportAttrs = Attributes.EMPTY;
private CallOptions callOptions = CallOptions.DEFAULT;
private int previousAttempts;
private boolean isTransparentRetry;

Builder() {
Expand All @@ -197,6 +213,16 @@ public Builder setCallOptions(CallOptions callOptions) {
return this;
}

/**
* Set the number of preceding attempts of the RPC.
*
* @since 1.40.0
*/
public Builder setPreviousAttempts(int previousAttempts) {
this.previousAttempts = previousAttempts;
return this;
}

/**
* Sets whether the stream is a transparent retry.
*
Expand All @@ -211,7 +237,7 @@ public Builder setIsTransparentRetry(boolean isTransparentRetry) {
* Builds a new StreamInfo.
*/
public StreamInfo build() {
return new StreamInfo(transportAttrs, callOptions, isTransparentRetry);
return new StreamInfo(transportAttrs, callOptions, previousAttempts, isTransparentRetry);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions api/src/main/java/io/grpc/ManagedChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ public T disableRetry() {
* transparent retries, which are safe for non-idempotent RPCs. Service config is ideally provided
* by the name resolver, but may also be specified via {@link #defaultServiceConfig}.
*
* <p>For the current release, this method may have a side effect that disables Census stats and
* tracing.
*
* @return this
* @since 1.11.0
*/
Expand Down

0 comments on commit 1680a99

Please sign in to comment.