Skip to content

Commit da86eea

Browse files
committed
rls: fix rls oobChannel grpclb config service name
The serviceName field in oobChannel grpclb config should not be null, otherwise it will default to the lbHelper.getAuthority(), which perviously defaulted to the lookup service before #7852, but has been overridden to the backend service for authentication in #7852.
1 parent f60a072 commit da86eea

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

rls/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
guavaDependency 'implementation'
1818
compileOnly libraries.javax_annotation
1919
testImplementation libraries.truth,
20+
project(':grpc-grpclb'),
2021
project(':grpc-testing'),
2122
project(':grpc-testing-proto'),
2223
project(':grpc-core').sourceSets.test.output // for FakeClock

rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ private CachingRlsLbClient(Builder builder) {
162162
rlsConfig.getLookupService(), helper.getUnsafeChannelCredentials());
163163
rlsChannelBuilder.overrideAuthority(helper.getAuthority());
164164
if (enableOobChannelDirectPath) {
165+
Map<String, ?> directPathServiceConfig =
166+
getDirectPathServiceConfig(rlsConfig.getLookupService());
165167
logger.log(
166168
ChannelLogLevel.DEBUG,
167169
"RLS channel direct path enabled. RLS channel service config: {0}",
168-
getDirectpathServiceConfig());
169-
rlsChannelBuilder.defaultServiceConfig(getDirectpathServiceConfig());
170+
directPathServiceConfig);
171+
rlsChannelBuilder.defaultServiceConfig(directPathServiceConfig);
170172
rlsChannelBuilder.disableServiceConfigLookUp();
171173
}
172174
rlsChannel = rlsChannelBuilder.build();
@@ -183,12 +185,14 @@ private CachingRlsLbClient(Builder builder) {
183185
logger.log(ChannelLogLevel.DEBUG, "CachingRlsLbClient created");
184186
}
185187

186-
private static ImmutableMap<String, Object> getDirectpathServiceConfig() {
188+
private static ImmutableMap<String, Object> getDirectPathServiceConfig(String serviceName) {
187189
ImmutableMap<String, Object> pickFirstStrategy =
188190
ImmutableMap.<String, Object>of("pick_first", ImmutableMap.of());
189191

190192
ImmutableMap<String, Object> childPolicy =
191-
ImmutableMap.<String, Object>of("childPolicy", ImmutableList.of(pickFirstStrategy));
193+
ImmutableMap.<String, Object>of(
194+
"childPolicy", ImmutableList.of(pickFirstStrategy),
195+
"serviceName", serviceName);
192196

193197
ImmutableMap<String, Object> grpcLbPolicy =
194198
ImmutableMap.<String, Object>of("grpclb", childPolicy);

rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ public void uncaughtException(Thread t, Throwable e) {
145145

146146
private CachingRlsLbClient rlsLbClient;
147147
private boolean existingEnableOobChannelDirectPath;
148+
private Map<String, ?> rlsChannelServiceConfig;
149+
private String rlsChannelOverriddenAuthority;
148150

149151
@Before
150152
public void setUp() throws Exception {
151153
existingEnableOobChannelDirectPath = CachingRlsLbClient.enableOobChannelDirectPath;
152154
CachingRlsLbClient.enableOobChannelDirectPath = false;
155+
}
153156

157+
private void setUpRlsLbClient() {
154158
rlsLbClient =
155159
CachingRlsLbClient.newBuilder()
156160
.setBackoffProvider(fakeBackoffProvider)
@@ -185,6 +189,7 @@ public void run() {
185189

186190
@Test
187191
public void get_noError_lifeCycle() throws Exception {
192+
setUpRlsLbClient();
188193
InOrder inOrder = inOrder(evictionListener);
189194
RouteLookupRequest routeLookupRequest =
190195
new RouteLookupRequest(
@@ -233,8 +238,44 @@ public void get_noError_lifeCycle() throws Exception {
233238
inOrder.verifyNoMoreInteractions();
234239
}
235240

241+
@Test
242+
public void rls_overDirectPath() throws Exception {
243+
CachingRlsLbClient.enableOobChannelDirectPath = true;
244+
setUpRlsLbClient();
245+
RouteLookupRequest routeLookupRequest =
246+
new RouteLookupRequest(
247+
"bigtable.googleapis.com", "/foo/bar", "grpc", ImmutableMap.<String, String>of());
248+
rlsServerImpl.setLookupTable(
249+
ImmutableMap.of(
250+
routeLookupRequest,
251+
new RouteLookupResponse(ImmutableList.of("target"), "header")));
252+
253+
// initial request
254+
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
255+
assertThat(resp.isPending()).isTrue();
256+
257+
// server response
258+
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
259+
260+
resp = getInSyncContext(routeLookupRequest);
261+
assertThat(resp.hasData()).isTrue();
262+
263+
assertThat(rlsChannelOverriddenAuthority).isEqualTo("bigtable.googleapis.com:443");
264+
assertThat(rlsChannelServiceConfig).isEqualTo(
265+
ImmutableMap.of(
266+
"loadBalancingConfig",
267+
ImmutableList.of(ImmutableMap.of(
268+
"grpclb",
269+
ImmutableMap.of(
270+
"childPolicy",
271+
ImmutableList.of(ImmutableMap.of("pick_first", ImmutableMap.of())),
272+
"serviceName",
273+
"service1")))));
274+
}
275+
236276
@Test
237277
public void get_throttledAndRecover() throws Exception {
278+
setUpRlsLbClient();
238279
RouteLookupRequest routeLookupRequest =
239280
new RouteLookupRequest("server", "/foo/bar", "grpc", ImmutableMap.<String, String>of());
240281
rlsServerImpl.setLookupTable(
@@ -276,6 +317,7 @@ public void get_throttledAndRecover() throws Exception {
276317

277318
@Test
278319
public void get_updatesLbState() throws Exception {
320+
setUpRlsLbClient();
279321
InOrder inOrder = inOrder(helper);
280322
RouteLookupRequest routeLookupRequest =
281323
new RouteLookupRequest(
@@ -344,6 +386,7 @@ public void get_updatesLbState() throws Exception {
344386

345387
@Test
346388
public void get_childPolicyWrapper_reusedForSameTarget() throws Exception {
389+
setUpRlsLbClient();
347390
RouteLookupRequest routeLookupRequest =
348391
new RouteLookupRequest("server", "/foo/bar", "grpc", ImmutableMap.<String, String>of());
349392
RouteLookupRequest routeLookupRequest2 =
@@ -565,6 +608,20 @@ protected ManagedChannelBuilder<?> delegate() {
565608
public ManagedChannel build() {
566609
return grpcCleanupRule.register(super.build());
567610
}
611+
612+
@Override
613+
public CleaningChannelBuilder defaultServiceConfig(Map<String, ?> serviceConfig) {
614+
rlsChannelServiceConfig = serviceConfig;
615+
delegate().defaultServiceConfig(serviceConfig);
616+
return this;
617+
}
618+
619+
@Override
620+
public CleaningChannelBuilder overrideAuthority(String authority) {
621+
rlsChannelOverriddenAuthority = authority;
622+
delegate().overrideAuthority(authority);
623+
return this;
624+
}
568625
}
569626

570627
return new CleaningChannelBuilder();

0 commit comments

Comments
 (0)