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

grpc-core: use retryThrottling from defaultServiceConfig #11290

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ ClientStream newSubstream(
parsedDefaultServiceConfig.getError());
this.defaultServiceConfig =
(ManagedChannelServiceConfig) parsedDefaultServiceConfig.getConfig();
this.lastServiceConfig = this.defaultServiceConfig;
this.transportProvider.throttle = this.defaultServiceConfig.getRetryThrottling();
} else {
this.defaultServiceConfig = null;
}
Expand Down Expand Up @@ -708,6 +708,11 @@ public String getServiceAuthority() {
InternalConfigSelector getConfigSelector() {
return realChannel.configSelector.get();
}

@VisibleForTesting
boolean hasThrottle() {
return this.transportProvider.throttle != null;
}

/**
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
Expand Down
67 changes: 67 additions & 0 deletions core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,40 @@ public void disableServiceConfigLookUp_withDefaultConfig() throws Exception {
}
}

@Test
public void disableServiceConfigLookUp_withDefaultConfig_withRetryThrottle() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
try {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri)
.setServers(ImmutableList.of(addressGroup)).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
channelBuilder.disableServiceConfigLookUp();
channelBuilder.enableRetry();
Map<String, Object> defaultServiceConfig =
parseConfig("{"
+ "\"retryThrottling\":{\"maxTokens\": 1, \"tokenRatio\": 1},"
+ "\"methodConfig\":[{"
+ "\"name\":[{\"service\":\"SimpleService1\"}],"
+ "\"waitForReady\":true"
+ "}]}");
channelBuilder.defaultServiceConfig(defaultServiceConfig);

createChannel();

ArgumentCaptor<ResolvedAddresses> resultCaptor =
ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).acceptResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).containsExactly(addressGroup);
assertThat(resultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY)).isNull();
verify(mockLoadBalancer, never()).handleNameResolutionError(any(Status.class));
assertThat(channel.hasThrottle()).isTrue();

} finally {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
}

@Test
public void enableServiceConfigLookUp_noDefaultConfig() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
Expand Down Expand Up @@ -4165,6 +4199,39 @@ public void enableServiceConfigLookUp_resolverReturnsNoConfig_withDefaultConfig(
}
}


@Test
public void enableServiceConfigLookUp_usingDefaultConfig_withRetryThrottling() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
try {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri)
.setServers(ImmutableList.of(addressGroup)).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
channelBuilder.enableRetry();
Map<String, Object> defaultServiceConfig =
parseConfig("{"
+ "\"retryThrottling\":{\"maxTokens\": 1, \"tokenRatio\": 1},"
+ "\"methodConfig\":[{"
+ "\"name\":[{\"service\":\"SimpleService1\"}],"
+ "\"waitForReady\":true"
+ "}]}");
channelBuilder.defaultServiceConfig(defaultServiceConfig);

createChannel();

ArgumentCaptor<ResolvedAddresses> resultCaptor =
ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).acceptResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).containsExactly(addressGroup);
assertThat(resultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY)).isNull();
verify(mockLoadBalancer, never()).handleNameResolutionError(any(Status.class));
assertThat(channel.hasThrottle()).isTrue();
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
} finally {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
}

@Test
public void enableServiceConfigLookUp_resolverReturnsNoConfig_noDefaultConfig() {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
Expand Down
Loading