-
Notifications
You must be signed in to change notification settings - Fork 4k
enable child channel plugins #12578
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
Open
AgraVator
wants to merge
12
commits into
grpc:master
Choose a base branch
from
AgraVator:child-channel-plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
enable child channel plugins #12578
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
476e5a8
enable child channel plugins
AgraVator 2554a04
add test cases
AgraVator cf4909e
remove unused field
AgraVator 4905f72
correct javadoc
AgraVator 36c2927
plumb child channel options through xDS server
AgraVator 3259d67
add test case for xDS server and others
AgraVator eab10a9
fix: pass the configurer
AgraVator d8398f5
expose APIs similar to internalConfigurator
AgraVator 374cbdf
Merge branch 'master' into child-channel-plugin
AgraVator 367640e
fix: refactor from ChildChannelConfigurer to ChannelConfigurer
AgraVator 0346e90
Merge branch 'master' into child-channel-plugin
AgraVator 3e38536
fix: merge conflict
AgraVator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright 2026 The gRPC Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.grpc; | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * A configurer for child channels created by gRPC's internal infrastructure. | ||
| * | ||
| * <p>This interface allows users to inject configuration (such as credentials, interceptors, | ||
| * or flow control settings) into channels created automatically by gRPC for control plane | ||
| * operations. Common use cases include: | ||
| * <ul> | ||
| * <li>xDS control plane connections</li> | ||
| * <li>Load Balancing helper channels (OOB channels)</li> | ||
| * </ul> | ||
| * | ||
| * <p><strong>Usage Example:</strong> | ||
| * <pre>{@code | ||
| * // 1. Define the configurer | ||
| * ChannelConfigurer configurer = builder -> { | ||
| * builder.maxInboundMessageSize(4 * 1024 * 1024); | ||
| * }; | ||
| * | ||
| * // 2. Apply to parent channel - automatically used for ALL child channels | ||
| * ManagedChannel channel = ManagedChannelBuilder | ||
| * .forTarget("xds:///my-service") | ||
| * .childChannelConfigurer(configurer) | ||
| * .build(); | ||
| * }</pre> | ||
| * | ||
| * <p>Implementations must be thread-safe as the configure methods may be invoked concurrently | ||
| * by multiple internal components. | ||
| * | ||
| * @since 1.81.0 | ||
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574") | ||
| public interface ChannelConfigurer { | ||
|
|
||
| /** | ||
| * Configures a builder for a new child channel. | ||
| * | ||
| * <p>This method is invoked synchronously during the creation of the child channel, | ||
| * before {@link ManagedChannelBuilder#build()} is called. | ||
| * | ||
| * @param builder the mutable channel builder for the new child channel | ||
| */ | ||
| default void configureChannelBuilder(ManagedChannelBuilder<?> builder) {} | ||
|
|
||
| /** | ||
| * Configures a builder for a new child server. | ||
| * | ||
| * <p>This method is invoked synchronously during the creation of the child server, | ||
| * before {@link ServerBuilder#build()} is called. | ||
| * | ||
| * @param builder the mutable server builder for the new child server | ||
| */ | ||
| default void configureServerBuilder(ServerBuilder<?> builder) {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,9 +168,7 @@ protected T interceptWithTarget(InterceptorFactory factory) { | |
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| /** Internal-only. */ | ||
| @Internal | ||
| protected interface InterceptorFactory { | ||
| public interface InterceptorFactory { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making InterceptorFactory public does not seem to be related to this PR which is about configuring child channels. |
||
| ClientInterceptor newInterceptor(String target); | ||
| } | ||
|
|
||
|
|
@@ -638,8 +636,7 @@ public T disableServiceConfigLookUp() { | |
| * @return this | ||
| * @since 1.64.0 | ||
| */ | ||
| @Internal | ||
| protected T addMetricSink(MetricSink metricSink) { | ||
| public T addMetricSink(MetricSink metricSink) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
|
|
@@ -661,6 +658,22 @@ public <X> T setNameResolverArg(NameResolver.Args.Key<X> key, X value) { | |
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Sets a configurer that will be applied to all internal child channels created by this channel. | ||
| * | ||
| * <p>This allows injecting configuration (like credentials, interceptors, or flow control) | ||
| * into auxiliary channels created by gRPC infrastructure, such as xDS control plane connections. | ||
| * | ||
| * @param channelConfigurer the configurer to apply. | ||
| * @return this | ||
| * @since 1.81.0 | ||
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574") | ||
| public T childChannelConfigurer(ChannelConfigurer channelConfigurer) { | ||
| throw new UnsupportedOperationException("Not implemented"); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a channel using the given parameters. | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,15 @@ | |
| */ | ||
| @Internal | ||
| public interface MetricRecorder { | ||
|
|
||
| /** | ||
| * Returns a {@link MetricRecorder} that performs no operations. | ||
| * The returned instance ignores all calls and skips all validation checks. | ||
| */ | ||
| static MetricRecorder noOp() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks unused. Delete? |
||
| return NoOpMetricRecorder.INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Adds a value for a double-precision counter metric instrument. | ||
| * | ||
|
|
@@ -176,4 +185,47 @@ interface Registration extends AutoCloseable { | |
| @Override | ||
| void close(); | ||
| } | ||
|
|
||
| /** | ||
| * No-Op implementation of MetricRecorder. | ||
| * Overrides all default methods to skip validation checks for maximum performance. | ||
| */ | ||
| final class NoOpMetricRecorder implements MetricRecorder { | ||
| private static final NoOpMetricRecorder INSTANCE = new NoOpMetricRecorder(); | ||
|
|
||
| @Override | ||
| public void addDoubleCounter(DoubleCounterMetricInstrument metricInstrument, double value, | ||
| List<String> requiredLabelValues, | ||
| List<String> optionalLabelValues) { | ||
| } | ||
|
|
||
| @Override | ||
| public void addLongCounter(LongCounterMetricInstrument metricInstrument, long value, | ||
| List<String> requiredLabelValues, List<String> optionalLabelValues) { | ||
| } | ||
|
|
||
| @Override | ||
| public void addLongUpDownCounter(LongUpDownCounterMetricInstrument metricInstrument, long value, | ||
| List<String> requiredLabelValues, | ||
| List<String> optionalLabelValues) { | ||
| } | ||
|
|
||
| @Override | ||
| public void recordDoubleHistogram(DoubleHistogramMetricInstrument metricInstrument, | ||
| double value, List<String> requiredLabelValues, | ||
| List<String> optionalLabelValues) { | ||
| } | ||
|
|
||
| @Override | ||
| public void recordLongHistogram(LongHistogramMetricInstrument metricInstrument, long value, | ||
| List<String> requiredLabelValues, | ||
| List<String> optionalLabelValues) { | ||
| } | ||
|
|
||
| @Override | ||
| public Registration registerBatchCallback(BatchCallback callback, | ||
| CallbackMetricInstrument... metricInstruments) { | ||
| return () -> { }; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright 2026 The gRPC Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.grpc; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| @RunWith(JUnit4.class) | ||
| public class ChannelConfigurerTest { | ||
|
|
||
| @Test | ||
| public void defaultMethods_doNothing() { | ||
| ChannelConfigurer configurer = new ChannelConfigurer() {}; | ||
|
|
||
| ManagedChannelBuilder<?> mockChannelBuilder = mock(ManagedChannelBuilder.class); | ||
| configurer.configureChannelBuilder(mockChannelBuilder); | ||
| verifyNoInteractions(mockChannelBuilder); | ||
|
|
||
| ServerBuilder<?> mockServerBuilder = mock(ServerBuilder.class); | ||
| configurer.configureServerBuilder(mockServerBuilder); | ||
| verifyNoInteractions(mockServerBuilder); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split it into 2 interfaces, one each for channel and server