Skip to content
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

xds: override bootstrap for xds server #8575

Merged
merged 5 commits into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions xds/src/main/java/io/grpc/xds/XdsServerBuilder.java
Expand Up @@ -22,7 +22,6 @@
import static io.grpc.xds.InternalXdsAttributes.ATTR_DRAIN_GRACE_NANOS;
import static io.grpc.xds.InternalXdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;

import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.DoNotCall;
import io.grpc.Attributes;
import io.grpc.ExperimentalApi;
Expand All @@ -37,9 +36,12 @@
import io.grpc.netty.NettyServerBuilder;
import io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingNegotiatorServerFactory;
import io.grpc.xds.XdsNameResolverProvider.XdsClientPoolFactory;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line

import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* A version of {@link ServerBuilder} to create xDS managed servers.
Expand Down Expand Up @@ -130,9 +132,18 @@ public Server build() {
filterChainSelectorManager, xdsClientPoolFactory, filterRegistry);
}

@VisibleForTesting
XdsServerBuilder xdsClientPoolFactory(XdsClientPoolFactory xdsClientPoolFactory) {
this.xdsClientPoolFactory = checkNotNull(xdsClientPoolFactory, "xdsClientPoolFactory");
/**
* Allows injecting {@link XdsClientPoolFactory} and/or overriding bootstrap configuration, useful
* for testing.
*/
public XdsServerBuilder xdsClientPoolFactory(@Nullable XdsClientPoolFactory xdsClientPoolFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XdsClientPoolFactory is not public, and we don't want it to be public. We just want the bootstrap. And we should probably put "for test" or the like in the name.

@Nullable Map<String, ?> bootstrapOverride) {
if (xdsClientPoolFactory != null) {
this.xdsClientPoolFactory = xdsClientPoolFactory;
}
if (bootstrapOverride != null) {
this.xdsClientPoolFactory.setBootstrapOverride(bootstrapOverride);
}
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion xds/src/test/java/io/grpc/xds/XdsSdsClientServerTest.java
Expand Up @@ -337,7 +337,7 @@ private void buildServerWithFallbackServerCredentials(
throws Exception {
ServerCredentials xdsCredentials = XdsServerCredentials.create(fallbackCredentials);
XdsServerBuilder builder = XdsServerBuilder.forPort(0, xdsCredentials)
.xdsClientPoolFactory(fakePoolFactory)
.xdsClientPoolFactory(fakePoolFactory, null)
.addService(new SimpleServiceImpl());
buildServer(builder, downstreamTlsContext);
}
Expand Down
2 changes: 1 addition & 1 deletion xds/src/test/java/io/grpc/xds/XdsServerBuilderTest.java
Expand Up @@ -77,7 +77,7 @@ private void buildBuilder(XdsServerBuilder.XdsServingStatusListener xdsServingSt
builder =
XdsServerBuilder.forPort(
port, XdsServerCredentials.create(InsecureServerCredentials.create()));
builder.xdsClientPoolFactory(new FakeXdsClientPoolFactory(xdsClient));
builder.xdsClientPoolFactory(new FakeXdsClientPoolFactory(xdsClient), null);
if (xdsServingStatusListener != null) {
builder.xdsServingStatusListener(xdsServingStatusListener);
}
Expand Down