-
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
Draft
AgraVator
wants to merge
6
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.
Draft
enable child channel plugins #12578
Changes from all commits
Commits
Show all changes
6 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 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,70 @@ | ||||||||||
| /* | ||||||||||
| * Copyright 2025 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 java.util.function.Consumer; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 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 | ||||||||||
| * ChildChannelConfigurer configurer = builder -> { | ||||||||||
| * builder.intercept(new MyAuthInterceptor()); | ||||||||||
| * 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 {@link #accept} may be invoked concurrently | ||||||||||
| * by multiple internal components. | ||||||||||
| * | ||||||||||
| * @since 1.79.0 | ||||||||||
| */ | ||||||||||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574") | ||||||||||
| @FunctionalInterface | ||||||||||
| public interface ChildChannelConfigurer extends Consumer<ManagedChannelBuilder<?>> { | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 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. | ||||||||||
| * | ||||||||||
| * <p>Note: The provided {@code builder} is generic (`?`). Implementations should use | ||||||||||
| * universal configuration methods (like {@code intercept()}, {@code userAgent()}) rather | ||||||||||
| * than casting to specific implementation types. | ||||||||||
|
Comment on lines
+63
to
+64
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.
Suggested change
|
||||||||||
| * | ||||||||||
| * @param builder the mutable channel builder for the new child channel | ||||||||||
| */ | ||||||||||
| @Override | ||||||||||
| void accept(ManagedChannelBuilder<?> 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * Copyright 2025 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 com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Utilities for working with {@link ChildChannelConfigurer}. | ||
| * | ||
| * @since 1.79.0 | ||
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574") | ||
| public final class ChildChannelConfigurers { | ||
| private static final Logger logger = Logger.getLogger(ChildChannelConfigurers.class.getName()); | ||
|
|
||
| // Singleton no-op instance to avoid object churn | ||
| private static final ChildChannelConfigurer NO_OP = builder -> { | ||
| }; | ||
|
|
||
| private ChildChannelConfigurers() { // Prevent instantiation | ||
| } | ||
|
|
||
| /** | ||
| * Returns a configurer that does nothing. | ||
| * Useful as a default value to avoid null checks in internal code. | ||
| */ | ||
| public static ChildChannelConfigurer noOp() { | ||
| return NO_OP; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a configurer that applies all the given configurers in sequence. | ||
| * | ||
| * <p>If any configurer in the chain throws an exception, the remaining ones are skipped | ||
| * (unless wrapped in {@link #safe(ChildChannelConfigurer)}). | ||
| * | ||
| * @param configurers the configurers to apply in order. Null elements are ignored. | ||
| */ | ||
| public static ChildChannelConfigurer compose(ChildChannelConfigurer... configurers) { | ||
| checkNotNull(configurers, "configurers"); | ||
| return builder -> { | ||
| for (ChildChannelConfigurer configurer : configurers) { | ||
| if (configurer != null) { | ||
| configurer.accept(builder); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a configurer that applies the delegate but catches and logs any exceptions. | ||
| * | ||
| * <p>This prevents a buggy configurer (e.g., one that fails metric setup) from crashing | ||
| * the critical path of channel creation. | ||
| * | ||
| * @param delegate the configurer to wrap. | ||
| */ | ||
| public static ChildChannelConfigurer safe(ChildChannelConfigurer delegate) { | ||
| checkNotNull(delegate, "delegate"); | ||
| return builder -> { | ||
| try { | ||
| delegate.accept(builder); | ||
| } catch (Exception e) { | ||
| logger.log(Level.WARNING, "Failed to apply child channel configuration", e); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a configurer that applies the delegate only if the given condition is true. | ||
| * | ||
| * <p>Useful for applying interceptors only in specific environments (e.g., Debug/Test). | ||
| * | ||
| * @param condition true to apply the delegate, false to do nothing. | ||
| * @param delegate the configurer to apply if condition is true. | ||
| */ | ||
| public static ChildChannelConfigurer conditional(boolean condition, | ||
| ChildChannelConfigurer delegate) { | ||
| checkNotNull(delegate, "delegate"); | ||
| return condition ? delegate : NO_OP; | ||
| } | ||
| } |
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
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
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.
nit: 2026