Skip to content

Commit 4fe9c35

Browse files
ASP-2043: Add serviceConfig support to GrpcChannelConfig for gRPC built-in retry
- Add optional serviceConfig field to GrpcChannelConfig - Wire defaultServiceConfig() + enableRetry() in GrpcChannelRegistry when serviceConfig is set - Add test verifying channels with different service configs are cached independently Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> AI-Session-Id: 75f3864c-dc2c-4e44-b4f3-b23c980f2ea6 AI-Tool: claude-code AI-Model: unknown
1 parent f236b97 commit 4fe9c35

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/GrpcChannelConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.grpc.ClientInterceptor;
44
import java.util.List;
5+
import java.util.Map;
56
import lombok.Builder;
67
import lombok.Singular;
78
import lombok.Value;
@@ -12,4 +13,6 @@ public class GrpcChannelConfig {
1213
Integer maxInboundMessageSize;
1314

1415
@Singular List<ClientInterceptor> clientInterceptors;
16+
17+
Map<String, Object> serviceConfig;
1518
}

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/GrpcChannelRegistry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ protected ManagedChannel configureAndBuildChannel(
9090
if (config.getMaxInboundMessageSize() != null) {
9191
builder.maxInboundMessageSize(config.getMaxInboundMessageSize());
9292
}
93+
if (config.getServiceConfig() != null) {
94+
builder.defaultServiceConfig(config.getServiceConfig()).enableRetry();
95+
}
9396
this.registryConfig.getDefaultInterceptors().forEach(builder::intercept);
9497
return builder.intercept(config.getClientInterceptors()).build();
9598
}

grpc-client-utils/src/test/java/org/hypertrace/core/grpcutils/client/GrpcChannelRegistryTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.grpc.ManagedChannel;
2424
import io.grpc.ManagedChannelBuilder;
2525
import java.util.List;
26+
import java.util.Map;
2627
import java.util.concurrent.TimeUnit;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.Test;
@@ -145,6 +146,21 @@ void copyConstructorReusesExistingChannels() {
145146
assertSame(firstChannel, new GrpcChannelRegistry(firstRegistry).forSecureAddress("foo", 1000));
146147
}
147148

149+
@Test
150+
void createsDistinctChannelsForDifferentServiceConfigs() {
151+
Map<String, Object> serviceConfig = Map.of("methodConfig", List.of());
152+
Channel channelWithServiceConfig =
153+
this.channelRegistry.forSecureAddress(
154+
"foo", 1000, GrpcChannelConfig.builder().serviceConfig(serviceConfig).build());
155+
156+
assertNotNull(channelWithServiceConfig);
157+
assertNotSame(channelWithServiceConfig, this.channelRegistry.forSecureAddress("foo", 1000));
158+
assertSame(
159+
channelWithServiceConfig,
160+
this.channelRegistry.forSecureAddress(
161+
"foo", 1000, GrpcChannelConfig.builder().serviceConfig(serviceConfig).build()));
162+
}
163+
148164
@Test
149165
void registersRegistryInterceptors() {
150166
try (MockedStatic<ManagedChannelBuilder> mockedBuilderStatic =

0 commit comments

Comments
 (0)