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: only include nodeID in error strings, not the whole nodeProto #5461

Merged
merged 2 commits into from Jun 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion xds/internal/xdsclient/authority.go
Expand Up @@ -21,6 +21,8 @@ import (
"errors"
"fmt"

v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
"google.golang.org/grpc/xds/internal/xdsclient/load"
"google.golang.org/grpc/xds/internal/xdsclient/pubsub"
Expand Down Expand Up @@ -102,7 +104,13 @@ func (c *clientImpl) newAuthorityLocked(config *bootstrap.ServerConfig) (_ *auth
}

// Make a new authority since there's no existing authority for this config.
ret := &authority{config: config, pubsub: pubsub.New(c.watchExpiryTimeout, c.config.XDSServer.NodeProto, c.logger)}
nodeID := ""
if v3, ok := c.config.XDSServer.NodeProto.(*v3corepb.Node); ok {
nodeID = v3.GetId()
} else if v2, ok := c.config.XDSServer.NodeProto.(*v2corepb.Node); ok {
nodeID = v2.GetId()
}
ret := &authority{config: config, pubsub: pubsub.New(c.watchExpiryTimeout, nodeID, c.logger)}
defer func() {
if retErr != nil {
ret.close()
Expand Down
8 changes: 3 additions & 5 deletions xds/internal/xdsclient/pubsub/pubsub.go
Expand Up @@ -23,11 +23,9 @@
package pubsub

import (
"fmt"
"sync"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/internal/buffer"
"google.golang.org/grpc/internal/grpclog"
"google.golang.org/grpc/internal/grpcsync"
Expand All @@ -43,7 +41,7 @@ type Pubsub struct {
done *grpcsync.Event
logger *grpclog.PrefixLogger
watchExpiryTimeout time.Duration
nodeIDJSON string
nodeID string

updateCh *buffer.Unbounded // chan *watcherInfoWithUpdate
// All the following maps are to keep the updates/metadata in a cache.
Expand All @@ -65,12 +63,12 @@ type Pubsub struct {
// New creates a new Pubsub.
//
// The passed in nodeID will be attached to all errors sent to the watchers.
func New(watchExpiryTimeout time.Duration, nodeID proto.Message, logger *grpclog.PrefixLogger) *Pubsub {
func New(watchExpiryTimeout time.Duration, nodeID string, logger *grpclog.PrefixLogger) *Pubsub {
pb := &Pubsub{
done: grpcsync.NewEvent(),
logger: logger,
watchExpiryTimeout: watchExpiryTimeout,
nodeIDJSON: fmt.Sprint(nodeID),
nodeID: nodeID,

updateCh: buffer.NewUnbounded(),
ldsWatchers: make(map[string]map[*watchInfo]bool),
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/xdsclient/pubsub/watch.go
Expand Up @@ -115,9 +115,9 @@ func (wi *watchInfo) sendErrorLocked(err error) {
errMsg := err.Error()
errTyp := xdsresource.ErrType(err)
if errTyp == xdsresource.ErrorTypeUnknown {
err = fmt.Errorf("%v, xDS client nodeID: %s", errMsg, wi.c.nodeIDJSON)
err = fmt.Errorf("%v, xDS client nodeID: %s", errMsg, wi.c.nodeID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test of this error message (only logging nodeID) if not too much effort?

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 had looked into it before sending the PR out as well. It isn't very straightforward and would not be worth the mess. Thanks.

} else {
err = xdsresource.NewErrorf(errTyp, "%v, xDS client nodeID: %s", errMsg, wi.c.nodeIDJSON)
err = xdsresource.NewErrorf(errTyp, "%v, xDS client nodeID: %s", errMsg, wi.c.nodeID)
}

wi.c.scheduleCallback(wi, u, err)
Expand Down