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

xdsclient: introduce pool to manage multiple xDS clients with same bootstrap content #7898

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

purnesh42H
Copy link
Contributor

@purnesh42H purnesh42H commented Dec 4, 2024

Fixes: #7592

RELEASE NOTES:

  • xds: fixed a bug which sometimes prevented a server to be used with multiple clients with different configurations.

@purnesh42H purnesh42H added this to the 1.69 Release milestone Dec 4, 2024
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch from 202847e to b561f1c Compare December 4, 2024 20:23
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 84.14634% with 13 lines in your changes missing coverage. Please review.

Project coverage is 82.14%. Comparing base (724f450) to head (d43ade8).

Files with missing lines Patch % Lines
xds/internal/xdsclient/pool.go 83.78% 4 Missing and 2 partials ⚠️
xds/internal/resolver/xds_resolver.go 66.66% 2 Missing and 1 partial ⚠️
xds/internal/xdsclient/client_refcounted.go 80.00% 2 Missing and 1 partial ⚠️
xds/internal/xdsclient/client_new.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7898      +/-   ##
==========================================
+ Coverage   82.05%   82.14%   +0.09%     
==========================================
  Files         381      382       +1     
  Lines       38539    38558      +19     
==========================================
+ Hits        31622    31674      +52     
+ Misses       5602     5574      -28     
+ Partials     1315     1310       -5     
Files with missing lines Coverage Δ
xds/internal/testutils/fakeclient/client.go 81.25% <ø> (ø)
xds/internal/xdsclient/clientimpl.go 74.84% <ø> (+1.88%) ⬆️
xds/internal/xdsclient/clientimpl_dump.go 100.00% <100.00%> (ø)
xds/internal/xdsclient/xdsresource/errors.go 100.00% <ø> (ø)
xds/server.go 82.20% <100.00%> (-0.84%) ⬇️
xds/server_options.go 100.00% <100.00%> (ø)
xds/internal/xdsclient/client_new.go 88.33% <85.71%> (+2.61%) ⬆️
xds/internal/resolver/xds_resolver.go 77.94% <66.66%> (-1.44%) ⬇️
xds/internal/xdsclient/client_refcounted.go 76.19% <80.00%> (-5.87%) ⬇️
xds/internal/xdsclient/pool.go 83.78% <83.78%> (ø)

... and 26 files with indirect coverage changes

@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch 2 times, most recently from 23023e9 to 12cb8a7 Compare December 4, 2024 21:16
@purnesh42H purnesh42H requested a review from easwars December 4, 2024 21:17
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch from 12cb8a7 to 8787929 Compare December 5, 2024 04:37
@purnesh42H purnesh42H modified the milestones: 1.69 Release, 1.70 Release Dec 5, 2024
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch from 8787929 to aa7e498 Compare December 5, 2024 16:30
var (
// DefaultPool is the default pool for xds clients. It is created at the
// init time.
DefaultPool *Pool
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the reason to export this DefaultPool variable? Was it to make testing easier? I see most reference of this variable is within the xdsclient package, with only one reference in xds/server_options.go.
Would it be possible to test via Public APIs instead?

Copy link
Contributor Author

@purnesh42H purnesh42H Dec 6, 2024

Choose a reason for hiding this comment

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

yeah server options have to set and get config for testing. I think we can provide the set and get method for default pool but then its equivalent of exporting a variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @danielzhaotongliu. We don't have to make this public. We should change the dial option and the server option to create a pool with the bootstrap config that was passed to it, and use that pool to create the xDS client. This is specified in the proposal in #7592 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just coming back to this comment. I think we would have to export the default pool from the xdsclient package or use the internal package trick, because we want the xDS resolver and the xDS server to be able to use the default pool when they want to create xDS clients in non-test environments.

The internal trick won't work once we move the xDS client out into a separate repo (as part of the generic xDS client work). So, we are only left with the option of exporting this.

Do you both have other ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have kept the DefaultPool exported for now. As you called out in other comment, we set the bootstrap config in DefaultPool if env var is set with correct bootstrap config or contents. The resolver and server will have DefaultPool set by default pool but we have options to override for testing.

@@ -46,7 +46,8 @@ const Scheme = "xds"

// newBuilderWithConfigForTesting creates a new xds resolver builder using a
// specific xds bootstrap config, so tests can use multiple xds clients in
// different ClientConns at the same time.
// different ClientConns at the same time. It creates the new xds client int
Copy link
Contributor

Choose a reason for hiding this comment

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

typo/nit: "It creates a new xds client in the default pool with the provided config."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// expected to invoke once they are done using the client. It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClient(name string) (XDSClient, func(), error) {
config, err := bootstrap.GetConfiguration()
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the reason to not use the Pool.config field xDS bootstrap configuration as that was the config passed in/parsed/created during the NewPool function above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NewClient is for the prod path which actually reads the bootstrap config from env vars and will only deal with default pool.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about the use case where users ONLY set bootstrap config from the SetFallbackBootstrapConfig API and do not set env var? For this case, when creating the xDS client, would it be created via this method? Would they not require p.config instead since that is the field set from the implementation below (line 133-143)?

Copy link
Contributor

Choose a reason for hiding this comment

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

This method must use the config field inside the Pool. There is no point in reading the bootstrap configuration from the env vars or the fallback bootstrap configuration. In fact, once we do that, we don't have a reason to have Pool.NewClientForTesting. Tests could as well use pool.NewClient.

What do you think?

NewClient is for the prod path which actually reads the bootstrap config from env vars and will only deal with default pool

The bootstrap env vars should be read when the default pool is created at init time. And if bootstrap env vars are not set, the default pool should have a nil config and if NewClient is called without calling SetFallbackBootstrapConfig, i.e. config is nil when NewClient is called, then NewClient should fail with a useful error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bootstrap env vars should be read when the default pool is created at init time. And if bootstrap env vars are not set, the default pool should have a nil config and if NewClient is called without calling SetFallbackBootstrapConfig, i.e. config is nil when NewClient is called, then NewClient should fail with a useful error message.

Done

xds/internal/xdsclient/pool.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/pool.go Outdated Show resolved Hide resolved
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch from 2ab7ba2 to 6e822a3 Compare December 6, 2024 09:42
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch 2 times, most recently from 4e62279 to 43b394d Compare December 6, 2024 18:47
Copy link
Contributor

@danielzhaotongliu danielzhaotongliu left a comment

Choose a reason for hiding this comment

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

I might not be familiar enough with the Github testing process for gRPC Go, have we tested this end-to-end, or would the current tests suffice? I recall there are (PSM) interop tests, are those run post PR submission or manually triggered?

Are there any performance implications of this change?

// expected to invoke once they are done using the client. It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClient(name string) (XDSClient, func(), error) {
config, err := bootstrap.GetConfiguration()
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the use case where users ONLY set bootstrap config from the SetFallbackBootstrapConfig API and do not set env var? For this case, when creating the xDS client, would it be created via this method? Would they not require p.config instead since that is the field set from the implementation below (line 133-143)?

)

var (
// DefaultPool is the default pool for xds clients. It is created at the
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Here and everywhere in this PR, please replace occurrences of xds client(s) with xDS client(s). We've been trying to be consistent with xDS client(s) recently. So, let's stick to that. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

DefaultPool *Pool
)

// Pool represents pool of xds clients.
Copy link
Contributor

Choose a reason for hiding this comment

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

This docstring should mention that the pool of clients share the same bootstrap configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +38 to +45
mu sync.Mutex
clients map[string]*clientRefCounted
config *bootstrap.Config
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: mu should ideally only have to guard clients. But here, we need it to guard config as well since SetFallbackBootstrapConfig writes to config. Maybe a comment here to mention that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in the docstring

var (
// DefaultPool is the default pool for xds clients. It is created at the
// init time.
DefaultPool *Pool
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @danielzhaotongliu. We don't have to make this public. We should change the dial option and the server option to create a pool with the bootstrap config that was passed to it, and use that pool to create the xDS client. This is specified in the proposal in #7592 (comment)

}

// NewPool creates a new xds client pool with the given bootstrap contents.
func NewPool(bootstrapContents []byte) (*Pool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nicer to have this accept a *bootstrap.Config (which could optionally be nil) rather than having to parse the configuration here. With that change, this API will return a single value, *Pool, instead of two.

Copy link
Contributor

Choose a reason for hiding this comment

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

When we change this to accept a bootstrap.Config, we should also export bootstrap.newConfigFromContents. This would allow non-test usages for NewPool where the caller would use the exported bootstrap.newConfigFromContents to parse the JSON config and pass it to this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be nicer to have this accept a *bootstrap.Config (which could optionally be nil) rather than having to parse the configuration here. With that change, this API will return a single value, *Pool, instead of two.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should also export bootstrap.newConfigFromContents. This would allow non-test usages for NewPool

We already have bootstrap.NewConfigForTesting which internally call bootstrap.newConfigFromContents

@@ -360,7 +360,7 @@ func (s) TestHandleListenerResponseFromManagementServer(t *testing.T) {
// involving receipt of an RDS response from the management server. The test
// verifies that the internal state of the xDS client (parsed resource and
// metadata) matches expectations.
func (s) TestHandleRouteConfigResponseFromManagementServer(t *testing.T) {
func TestHandleRouteConfigResponseFromManagementServer(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the s receiver being removed from this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted. Was just testing something and forgot to put it back.

WatchExpiryTimeout: defaultTestWatchExpiryTimeout,
Contents: bc,
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests should be using a pool to create an xDS client in. In fact, once we delete these NewXxx functions which don't operate on a pool, the tests will be left with no other choice.

xds/server.go Outdated
@@ -93,12 +93,11 @@ func NewGRPCServer(opts ...grpc.ServerOption) (*GRPCServer, error) {
// simplifies the code by eliminating the need for a mutex to protect the
// xdsC and xdsClientClose fields.
newXDSClient := newXDSClient
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having this newXDSClient var which can be overridden by tests to customize xDS client creation, the xDS server (and possibly the xDS resolver) should contain an xdsClientPool as a global var which would be set to the default pool at init time and can be customized by tests.

@@ -121,14 +121,18 @@ func (s) TestNewServer_Success(t *testing.T) {
desc: "without_xds_creds",
serverOpts: []grpc.ServerOption{
grpc.Creds(insecure.NewCredentials()),
BootstrapContentsForTesting(generateBootstrapContents(t, uuid.NewString(), nonExistentManagementServer)),
func() grpc.ServerOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this func here?

Copy link
Contributor Author

@purnesh42H purnesh42H Dec 28, 2024

Choose a reason for hiding this comment

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

Removed

// matched route configuration. After it transitions back into not ready
// (through an explicit LDS Resource Not Found), previously running RPC's
// should be gracefully closed and still work, and new RPC's should fail.
func (s) TestServingModeChanges_MultipleServers(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to test serving mode changes here. All we need to do here is to ensure that we can create two servers with two different bootstrap configurations. This would also mean that the two servers will request two different LDS resources from the management server, because the LDS resource name depends on the port on which the server is listening.

Then we could have two gRPC clients that talk to each of these servers and we ensure that RPCs work. We need to ensure that a gRPC client is actually talking to the server that it intends to talk to. This can be done with the Peer call option.

@easwars easwars assigned purnesh42H and unassigned easwars Dec 13, 2024
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch 8 times, most recently from 9588254 to 325def2 Compare December 21, 2024 23:09
@purnesh42H
Copy link
Contributor Author

I might not be familiar enough with the Github testing process for gRPC Go, have we tested this end-to-end, or would the current tests suffice? I recall there are (PSM) interop tests, are those run post PR submission or manually triggered?

Are there any performance implications of this change?

This change is only going to change the usages of unit tests and hermatic e2e tests (within grpc-go repo). PSM interop tests, prod and other integration tests should not observe any behavior change.

The reason for this change was to bring back old behavior to be able to create xds clients with different bootstrap config even if they point to same server.

@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch 2 times, most recently from c9274f0 to af40ea3 Compare December 28, 2024 07:37
@purnesh42H purnesh42H force-pushed the xdsclient-pool-per-bootstrap-content branch from af40ea3 to d43ade8 Compare December 28, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xds: v1.66.0 regression in xds.BootstrapContentsForTesting
3 participants