-
Notifications
You must be signed in to change notification settings - Fork 4.6k
xds: add xDS transport custom Dialer support #7586
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
Merged
easwars
merged 10 commits into
grpc:master
from
danielzhaotongliu:xds-transport-dialer-support
Sep 27, 2024
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
354e088
Dialer method via credentials bundle
danielzhaotongliu b5d173c
tests for xDS transport custom Dialer via credentials bundle
danielzhaotongliu d187d39
fix go vet style errors
danielzhaotongliu 6a82444
address review p1: if-compound statement, readability
danielzhaotongliu ad20fd0
address review p2: add higher level tests
danielzhaotongliu a8ff4fb
address review p3: remove global test variables & WaitForReady
danielzhaotongliu 3f564dd
address review p4: rephrase comments for ServerConfig.DialerOption me…
danielzhaotongliu 65feb3c
address review p5: embed credentials.Bundle interface in tests
danielzhaotongliu 14cbf57
address review p6: check number of dial options passed to grpc.NewCli…
danielzhaotongliu 5ebc9a7
address review p7: add TODO, use snake_case for JSON annotations
danielzhaotongliu 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
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,158 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 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 xds_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net" | ||
| "testing" | ||
|
|
||
| "github.com/google/uuid" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/credentials" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
| "google.golang.org/grpc/internal" | ||
| "google.golang.org/grpc/internal/stubserver" | ||
| "google.golang.org/grpc/internal/testutils" | ||
| "google.golang.org/grpc/internal/testutils/xds/e2e" | ||
| internalbootstrap "google.golang.org/grpc/internal/xds/bootstrap" | ||
| "google.golang.org/grpc/resolver" | ||
| "google.golang.org/grpc/xds/bootstrap" | ||
|
|
||
| testgrpc "google.golang.org/grpc/interop/grpc_testing" | ||
| testpb "google.golang.org/grpc/interop/grpc_testing" | ||
| ) | ||
|
|
||
| const testDialerCredsBuilderName = "test_dialer_creds" | ||
|
|
||
| var ( | ||
| mgmtServerAddress string | ||
| customDialerCalled bool | ||
| ) | ||
|
|
||
| func init() { | ||
| bootstrap.RegisterCredentials(&testDialerCredsBuilder{}) | ||
| } | ||
|
|
||
| // testDialerCredsBuilder implements the `Credentials` interface defined in | ||
| // package `xds/bootstrap` and encapsulates an insecure credential with a | ||
| // custom Dialer that specifies how to dial the xDS server. | ||
| type testDialerCredsBuilder struct{} | ||
|
|
||
| func (t *testDialerCredsBuilder) Build(json.RawMessage) (credentials.Bundle, func(), error) { | ||
| return &testDialerCredsBundle{}, func() {}, nil | ||
| } | ||
|
|
||
| func (t *testDialerCredsBuilder) Name() string { | ||
| return testDialerCredsBuilderName | ||
| } | ||
|
|
||
| // testDialerCredsBundle implements the `Bundle` interface defined in package | ||
| // `credentials` and encapsulates an insecure credential with a custom Dialer | ||
| // that specifies how to dial the xDS server. | ||
| type testDialerCredsBundle struct{} | ||
|
|
||
| func (t *testDialerCredsBundle) TransportCredentials() credentials.TransportCredentials { | ||
| return insecure.NewCredentials() | ||
| } | ||
|
|
||
| func (t *testDialerCredsBundle) PerRPCCredentials() credentials.PerRPCCredentials { | ||
| return nil | ||
| } | ||
|
|
||
| func (t *testDialerCredsBundle) NewWithMode(string) (credentials.Bundle, error) { | ||
| return &testDialerCredsBundle{}, nil | ||
| } | ||
|
|
||
| // Dialer specifies how to dial the xDS management server. | ||
| func (t *testDialerCredsBundle) Dialer(context.Context, string) (net.Conn, error) { | ||
| customDialerCalled = true | ||
| // Create a pass-through connection (no-op) to the xDS management server. | ||
| return net.Dial("tcp", mgmtServerAddress) | ||
| } | ||
|
|
||
| func (s) TestClientCustomDialerFromCredentialsBundle(t *testing.T) { | ||
| customDialerCalled = false | ||
easwars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Start an xDS management server. | ||
| mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{}) | ||
|
|
||
| // Create bootstrap configuration pointing to the above management server. | ||
| nodeID := uuid.New().String() | ||
| bc, err := internalbootstrap.NewContentsForTesting(internalbootstrap.ConfigOptionsForTesting{ | ||
| Servers: []byte(fmt.Sprintf(`[{ | ||
| "server_uri": %q, | ||
| "channel_creds": [{"type": %q}] | ||
| }]`, mgmtServer.Address, testDialerCredsBuilderName)), | ||
| Node: []byte(fmt.Sprintf(`{"id": "%s"}`, nodeID)), | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create bootstrap configuration: %v", err) | ||
| } | ||
|
|
||
| // Set the management server address to be used by the custom dialer. | ||
| mgmtServerAddress = mgmtServer.Address | ||
|
|
||
| // Create an xDS resolver with the above bootstrap configuration. | ||
| var resolverBuilder resolver.Builder | ||
| if newResolver := internal.NewXDSResolverWithConfigForTesting; newResolver != nil { | ||
| resolverBuilder, err = newResolver.(func([]byte) (resolver.Builder, error))(bc) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create xDS resolver for testing: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // Spin up a test backend. | ||
| server := stubserver.StartTestService(t, nil) | ||
| defer server.Stop() | ||
|
|
||
| // Configure client side xDS resources on the management server. | ||
| const serviceName = "my-service-client-side-xds" | ||
| resources := e2e.DefaultClientResources(e2e.ResourceParams{ | ||
| DialTarget: serviceName, | ||
| NodeID: nodeID, | ||
| Host: "localhost", | ||
| Port: testutils.ParsePort(t, server.Address), | ||
| SecLevel: e2e.SecurityLevelNone, | ||
| }) | ||
| ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
| defer cancel() | ||
| if err := mgmtServer.Update(ctx, resources); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Create a ClientConn and make a successful RPC. The insecure transport credentials passed into | ||
| // the gRPC.NewClient is the credentials for the data plane communication with the test backend. | ||
| cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolverBuilder)) | ||
| if err != nil { | ||
| t.Fatalf("failed to dial local test server: %v", err) | ||
| } | ||
| defer cc.Close() | ||
|
|
||
| client := testgrpc.NewTestServiceClient(cc) | ||
| if _, err := client.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); err != nil { | ||
danielzhaotongliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| t.Fatalf("EmptyCall() failed: %v", err) | ||
| } | ||
|
|
||
| if !customDialerCalled { | ||
| t.Fatalf("xDS client transport custom dialer called = false, want true") | ||
| } | ||
| } | ||
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
easwars marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.