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: unify xDS client creation APIs meant for testing #7268

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

easwars
Copy link
Contributor

@easwars easwars commented May 24, 2024

Summary of changes:

  • API changes
    • We are now down to three APIs for creating an xDS client
      • New(): almost all production code should use this
      • NewWithConfig(): Only the google-c2p resolver uses this since it has to manually construct the bootstrap configuration
      • NewForTesting(): All tests should use this and it accepts a config struct
        • This places all test xDS clients in a map keyed by its bootstrap configuration, and reuses clients if one exists for the same configuration
  • Fix a minor data race in the authority type by grabbing the lock early when handling watch timer expiry
  • Bootstrap changes
    • Always normalize contents when parsing bootstrap configuration to create the internal representation. This makes it easier to use the normalized configuration as the map key for xDS clients (used for testing purposes).
    • Remove any usages of the bootstrap.Config struct being manually initialized instead of being created using one of the NewXxx functions.
  • Testing changes
    • Cleanup the mess around the functions used to trigger resource-not-found errors for testing
    • Move some tests out of test/xds which were using the above functionality into a test only package in xds
  • Update all callsites of deleted APIs to use the new API

#a71-xds-fallback

RELEASE NOTES: none

@easwars easwars added the Type: Internal Cleanup Refactors, etc label May 24, 2024
@easwars easwars added this to the 1.65 Release milestone May 24, 2024
@easwars easwars requested a review from dfawley May 24, 2024 19:03
@easwars easwars force-pushed the xdsclient_new_cleanup_attempt_2 branch from de5e265 to f27e13a Compare May 28, 2024 19:05
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a couple small things.

@@ -415,6 +418,14 @@ func NewConfigFromContents(data []byte) (*Config, error) {
}

func newConfigFromContents(data []byte) (*Config, error) {
// Normalize the input configuration.
Copy link
Member

Choose a reason for hiding this comment

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

Comments should generally say "why" not "what" -- so why are we doing this step now?

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 a comment.

Earlier, we were doing this for some of the code paths involving testing xDS clients, but not in others. Doing this here would ensure that this is done for all testing xDS clients. And for non-testing xDS clients, this really does not matter.

}

func init() {
internal.TriggerXDSResourceNotFoundForTesting = triggerXDSResourceNotFoundForTesting
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit unfortunate...if we're going to have tests for xds living outside of xds/ then is that another reason to move all of xds/internal into internal/xds? Because we could just export this function directly instead of doing all the dance to trampoline through internal and losing static type safety.

We even still could expose it for use from inside xds/...

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 have some tests in test/xds which is probably why we need this. Also, this is not something new that I added in this PR. Instead there were two vars in the internal package that I reduced to one. But I agree with your sentiment and I've filed #7290 to ensure that this gets done. I will get to this once I'm done with the changes that are currently in flight.

)

type testService struct {
testgrpc.TestServiceServer
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this embed the Unimplemented server?

Also, it might be nice to (*always) use the stub server instead, since that allows you to define the RPC behavior inside the test case. Otherwise your test logic ends up decoupled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to the unimplemented server.

With regards to using the stub server, this is also an existing test that I moved to a different place. But I looked to see if I could use the stub server. The problem is that the stub server creates a new grpc.Server and registers the test service on it. We need to change it to optionally accept a server (a vanilla grpc.Server or xds.GRPCServer) and register the test service on it, if provided. Filed #7291 to track this.

@dfawley dfawley assigned easwars and unassigned dfawley May 30, 2024
@easwars easwars assigned dfawley and arvindbr8 and unassigned easwars May 31, 2024
Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

I think this mostly looks good to me. Had a few comments. PTAL

internal/xds/bootstrap/bootstrap.go Outdated Show resolved Hide resolved
internal/testutils/xds/bootstrap/bootstrap.go Show resolved Hide resolved
internal/xds/bootstrap/bootstrap.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/client_new.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/client_new.go Show resolved Hide resolved
xds/internal/xdsclient/client_new.go Outdated Show resolved Hide resolved
@arvindbr8 arvindbr8 assigned easwars and unassigned arvindbr8 and dfawley Jun 3, 2024
@easwars easwars assigned arvindbr8 and unassigned easwars Jun 3, 2024
Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

LGTM, Approved! :)

internal/testutils/xds/bootstrap/bootstrap.go Show resolved Hide resolved
@arvindbr8 arvindbr8 assigned dfawley and easwars and unassigned arvindbr8 and dfawley Jun 3, 2024
@easwars easwars merged commit 7e5898e into grpc:master Jun 3, 2024
11 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants