Skip to content

xds: add support for multiple xDS clients, for fallback #7347

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
merged 7 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/testutils/xds/e2e/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
}

func (l serverLogger) Debugf(format string, args ...any) {
l.logger.Logf(format, args)
l.logger.Logf(format, args...)
}
func (l serverLogger) Infof(format string, args ...any) {
l.logger.Logf(format, args)
l.logger.Logf(format, args...)

Check warning on line 33 in internal/testutils/xds/e2e/logging.go

View check run for this annotation

Codecov / codecov/patch

internal/testutils/xds/e2e/logging.go#L33

Added line #L33 was not covered by tests
}
func (l serverLogger) Warnf(format string, args ...any) {
l.logger.Logf(format, args)
l.logger.Logf(format, args...)
}
func (l serverLogger) Errorf(format string, args ...any) {
l.logger.Logf(format, args)
l.logger.Logf(format, args...)

Check warning on line 39 in internal/testutils/xds/e2e/logging.go

View check run for this annotation

Codecov / codecov/patch

internal/testutils/xds/e2e/logging.go#L39

Added line #L39 was not covered by tests
}
22 changes: 15 additions & 7 deletions internal/xds/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"google.golang.org/grpc/credentials/tls/certprovider"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/envconfig"
"google.golang.org/grpc/internal/pretty"
"google.golang.org/grpc/xds/bootstrap"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -213,6 +212,9 @@
// content. It doesn't cover NodeProto because NodeProto isn't used by
// federation.
func (sc *ServerConfig) String() string {
if len(sc.serverFeatures) == 0 {
return fmt.Sprintf("%s-%s", sc.serverURI, sc.selectedCreds.String())
}
features := strings.Join(sc.serverFeatures, "-")
return strings.Join([]string{sc.serverURI, sc.selectedCreds.String(), features}, "-")
}
Expand Down Expand Up @@ -418,6 +420,12 @@
return true
}

// String returns a string representation of the Config.
func (c *Config) String() string {
s, _ := c.MarshalJSON()
return string(s)

Check warning on line 426 in internal/xds/bootstrap/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/bootstrap/bootstrap.go#L424-L426

Added lines #L424 - L426 were not covered by tests
}

// The following fields correspond 1:1 with the JSON schema for Config.
type configJSON struct {
XDSServers []*ServerConfig `json:"xds_servers,omitempty"`
Expand All @@ -438,7 +446,7 @@
Authorities: c.authorities,
Node: c.node,
}
return json.Marshal(config)
return json.MarshalIndent(config, " ", " ")

Check warning on line 449 in internal/xds/bootstrap/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/bootstrap/bootstrap.go#L449

Added line #L449 was not covered by tests
}

// UnmarshalJSON takes the json data (the complete bootstrap configuration) and
Expand Down Expand Up @@ -509,7 +517,9 @@
fContent := envconfig.XDSBootstrapFileContent

if fName != "" {
logger.Debugf("Using bootstrap file with name %q", fName)
if logger.V(2) {
logger.Infof("Using bootstrap file with name %q", fName)

Check warning on line 521 in internal/xds/bootstrap/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/bootstrap/bootstrap.go#L521

Added line #L521 was not covered by tests
}
return bootstrapFileReadFunc(fName)
}

Expand Down Expand Up @@ -564,9 +574,7 @@
}

if logger.V(2) {
logger.Infof("Bootstrap config for creating xds-client: %v", pretty.ToJSON(config))
} else {
logger.Infof("Bootstrap config for creating xds-client: %+v", config)
logger.Infof("Bootstrap config for creating xds-client: %s", config)

Check warning on line 577 in internal/xds/bootstrap/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/bootstrap/bootstrap.go#L577

Added line #L577 was not covered by tests
}
return config, nil
}
Expand Down Expand Up @@ -630,7 +638,7 @@
Authorities: authorities,
Node: node{ID: opts.NodeID},
}
contents, err := json.Marshal(cfgJSON)
contents, err := json.MarshalIndent(cfgJSON, " ", " ")
if err != nil {
return nil, fmt.Errorf("failed to marshal bootstrap configuration for provided options %+v: %v", opts, err)
}
Expand Down
27 changes: 4 additions & 23 deletions xds/csds/csds.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"context"
"fmt"
"io"
"sync"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
Expand Down Expand Up @@ -55,22 +54,14 @@ func prefixLogger(s *ClientStatusDiscoveryServer) *internalgrpclog.PrefixLogger
// https://github.com/grpc/proposal/blob/master/A40-csds-support.md.
type ClientStatusDiscoveryServer struct {
logger *internalgrpclog.PrefixLogger

mu sync.Mutex
xdsClient xdsclient.XDSClient
xdsClientClose func()
}

// NewClientStatusDiscoveryServer returns an implementation of the CSDS server
// that can be registered on a gRPC server.
func NewClientStatusDiscoveryServer() (*ClientStatusDiscoveryServer, error) {
c, close, err := xdsclient.New()
if err != nil {
logger.Warningf("Failed to create xDS client: %v", err)
}
s := &ClientStatusDiscoveryServer{xdsClient: c, xdsClientClose: close}
s := &ClientStatusDiscoveryServer{}
s.logger = prefixLogger(s)
s.logger.Infof("Created CSDS server, with xdsClient %p", c)
s.logger.Infof("Created CSDS server")
return s, nil
}

Expand Down Expand Up @@ -104,24 +95,14 @@ func (s *ClientStatusDiscoveryServer) FetchClientStatus(_ context.Context, req *
//
// If it returns an error, the error is a status error.
func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statuspb.ClientStatusRequest) (*v3statuspb.ClientStatusResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()

if s.xdsClient == nil {
return &v3statuspb.ClientStatusResponse{}, nil
}
// Field NodeMatchers is unsupported, by design
// https://github.com/grpc/proposal/blob/master/A40-csds-support.md#detail-node-matching.
if len(req.NodeMatchers) != 0 {
return nil, status.Errorf(codes.InvalidArgument, "node_matchers are not supported, request contains node_matchers: %v", req.NodeMatchers)
}

return s.xdsClient.DumpResources()
return xdsclient.DumpResources(), nil
}

// Close cleans up the resources.
func (s *ClientStatusDiscoveryServer) Close() {
if s.xdsClientClose != nil {
s.xdsClientClose()
}
}
func (s *ClientStatusDiscoveryServer) Close() {}
Loading