11package org .hypertrace .core .kafkastreams .framework ;
22
3+ import static io .grpc .Deadline .after ;
4+ import static java .util .concurrent .TimeUnit .SECONDS ;
35import static org .apache .kafka .clients .consumer .ConsumerConfig .AUTO_OFFSET_RESET_CONFIG ;
46import static org .apache .kafka .clients .producer .ProducerConfig .ACKS_CONFIG ;
57import static org .apache .kafka .clients .producer .ProducerConfig .BATCH_SIZE_CONFIG ;
2325import io .confluent .kafka .streams .serdes .avro .SpecificAvroSerde ;
2426import io .micrometer .core .instrument .Tag ;
2527import io .micrometer .core .instrument .Tags ;
28+ import io .micrometer .core .instrument .binder .grpc .MetricCollectingClientInterceptor ;
2629import io .micrometer .core .instrument .binder .kafka .KafkaStreamsMetrics ;
2730import java .time .Duration ;
2831import java .util .ArrayList ;
3942import org .apache .kafka .streams .Topology ;
4043import org .apache .kafka .streams .errors .LogAndContinueExceptionHandler ;
4144import org .apache .kafka .streams .kstream .KStream ;
45+ import org .hypertrace .core .grpcutils .client .GrpcChannelRegistry ;
46+ import org .hypertrace .core .grpcutils .client .GrpcRegistryConfig ;
4247import org .hypertrace .core .kafkastreams .framework .listeners .LoggingStateListener ;
4348import org .hypertrace .core .kafkastreams .framework .listeners .LoggingStateRestoreListener ;
4449import org .hypertrace .core .kafkastreams .framework .rocksdb .BoundedMemoryConfigSetter ;
@@ -58,6 +63,9 @@ public abstract class KafkaStreamsApp extends PlatformService {
5863 public static final String PRE_CREATE_TOPICS = "precreate.topics" ;
5964 public static final String KAFKA_STREAMS_CONFIG_KEY = "kafka.streams.config" ;
6065 private static final Logger logger = LoggerFactory .getLogger (KafkaStreamsApp .class );
66+
67+ private final GrpcChannelRegistry grpcChannelRegistry ;
68+
6169 protected KafkaStreams app ;
6270 private KafkaStreamsMetrics metrics ;
6371
@@ -67,6 +75,17 @@ public abstract class KafkaStreamsApp extends PlatformService {
6775
6876 public KafkaStreamsApp (ConfigClient configClient ) {
6977 super (configClient );
78+ this .grpcChannelRegistry =
79+ new GrpcChannelRegistry (
80+ GrpcRegistryConfig .builder ()
81+ .defaultInterceptor (
82+ new MetricCollectingClientInterceptor (
83+ PlatformMetricsRegistry .getMeterRegistry ()))
84+ .build ());
85+ }
86+
87+ protected GrpcChannelRegistry getGrpcChannelRegistry () {
88+ return grpcChannelRegistry ;
7089 }
7190
7291 @ Override
@@ -147,6 +166,7 @@ protected void doStop() {
147166 metrics .close ();
148167 }
149168 app .close (Duration .ofSeconds (30 ));
169+ grpcChannelRegistry .shutdown (after (10 , SECONDS ));
150170 }
151171
152172 /**
0 commit comments