core: fix a bug in health check config propgation. (#6804)

The condition "effectiveServiceConfig != validServiceConfig" should
have been deleted in commit 2162ad0436.

The condition was there before that commit because
NAME_RESOLVER_SERVICE_CONFIG was already in "attrs", thus it needed to
be re-added only if "effectiveServiceConfig" differs from the original
"validServiceConfig".

In contrast, ATTR_HEALTH_CHECKING_CONFIG is not in the original
"attrs" and always needs to be added.
This commit is contained in:
Kun Zhang 2020-03-05 09:27:55 -08:00 committed by GitHub
parent 7be75a0bcb
commit 4a2c5d6e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 8 deletions

View File

@ -1399,14 +1399,12 @@ final class ManagedChannelImpl extends ManagedChannel implements
Attributes effectiveAttrs = resolutionResult.getAttributes();
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
if (NameResolverListener.this.helper == ManagedChannelImpl.this.lbHelper) {
if (effectiveServiceConfig != validServiceConfig) {
Map<String, ?> healthCheckingConfig =
effectiveServiceConfig.getHealthCheckingConfig();
if (healthCheckingConfig != null) {
effectiveAttrs = effectiveAttrs.toBuilder()
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig)
.build();
}
Map<String, ?> healthCheckingConfig =
effectiveServiceConfig.getHealthCheckingConfig();
if (healthCheckingConfig != null) {
effectiveAttrs = effectiveAttrs.toBuilder()
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig)
.build();
}
Status handleResult = helper.lb.tryHandleResolvedAddresses(

View File

@ -3918,6 +3918,36 @@ public class ManagedChannelImplTest {
.build());
}
@Test
public void healthCheckingConfigPropagated() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
try {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri)
.setServers(Collections.singletonList(new EquivalentAddressGroup(socketAddress)))
.build();
channelBuilder.nameResolverFactory(nameResolverFactory);
Map<String, Object> rawServiceConfig =
parseConfig("{\"healthCheckConfig\": {\"serviceName\": \"service1\"}}");
ManagedChannelServiceConfig managedChannelServiceConfig =
createManagedChannelServiceConfig(rawServiceConfig, null);
nameResolverFactory.nextConfigOrError.set(
ConfigOrError.fromConfig(managedChannelServiceConfig));
createChannel();
ArgumentCaptor<ResolvedAddresses> resultCaptor =
ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).handleResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAttributes()
.get(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG))
.containsExactly("serviceName", "service1");
} finally {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
}
private static final class ChannelBuilder
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {