-
Notifications
You must be signed in to change notification settings - Fork 4.6k
xds: avoid log spam during server mode switches (better A36 compliance) #5215
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -105,10 +105,10 @@ func NewGRPCServer(opts ...grpc.ServerOption) *GRPCServer { | |
| s := &GRPCServer{ | ||
| gs: newGRPCServer(newOpts...), | ||
| quit: grpcsync.NewEvent(), | ||
| opts: handleServerOptions(opts), | ||
| } | ||
| s.logger = prefixLogger(s) | ||
| s.logger.Infof("Created xds.GRPCServer") | ||
| s.handleServerOptions(opts) | ||
|
|
||
| // We type assert our underlying gRPC server to the real grpc.Server here | ||
| // before trying to retrieve the configured credentials. This approach | ||
|
|
@@ -128,14 +128,32 @@ func NewGRPCServer(opts ...grpc.ServerOption) *GRPCServer { | |
|
|
||
| // handleServerOptions iterates through the list of server options passed in by | ||
| // the user, and handles the xDS server specific options. | ||
| func handleServerOptions(opts []grpc.ServerOption) *serverOptions { | ||
| func (s *GRPCServer) handleServerOptions(opts []grpc.ServerOption) { | ||
| so := &serverOptions{} | ||
| for _, opt := range opts { | ||
| if o, ok := opt.(*serverOption); ok { | ||
| o.apply(so) | ||
| } | ||
| } | ||
| return so | ||
|
|
||
| // If the application did not register a mode change callback, the XdsServer | ||
| // registers its own which simply logs any errors and each serving resumption | ||
| // after an error, all at a default-visible log level, as per A36. The | ||
| // default-visible log level for us is ERROR. | ||
| // | ||
| // Note that this means that `s.opts.modeCallback` will never be nil and can | ||
| // safely be invoked directly from `handleServiceModeChanges`. | ||
| if so.modeCallback == nil { | ||
| so.modeCallback = func(addr net.Addr, args ServingModeChangeArgs) { | ||
|
||
| switch args.Mode { | ||
| case connectivity.ServingModeServing: | ||
| s.logger.Errorf("Listener %q entering mode: %q", addr.String(), args.Mode) | ||
| case connectivity.ServingModeNotServing: | ||
| s.logger.Errorf("Listener %q entering mode: %q due to error: %v", addr.String(), args.Mode, args.Err) | ||
| } | ||
| } | ||
| } | ||
| s.opts = so | ||
| } | ||
|
|
||
| // RegisterService registers a service and its implementation to the underlying | ||
|
|
@@ -291,12 +309,16 @@ func (s *GRPCServer) handleServingModeChanges(updateCh *buffer.Unbounded) { | |
| drainServerTransports(gs, args.addr.String()) | ||
| } | ||
| } | ||
| if s.opts.modeCallback != nil { | ||
| s.opts.modeCallback(args.addr, ServingModeChangeArgs{ | ||
| Mode: args.mode, | ||
| Err: args.err, | ||
| }) | ||
| } | ||
|
|
||
| // The XdsServer API will allow applications to register a "serving state" | ||
| // callback to be invoked when the server begins serving and when the | ||
| // server encounters errors that force it to be "not serving". If "not | ||
| // serving", the callback must be provided error information, for | ||
| // debugging use by developers - A36. | ||
| s.opts.modeCallback(args.addr, ServingModeChangeArgs{ | ||
| Mode: args.mode, | ||
| Err: args.err, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a
defaultServerOptionsthat has this set in it, such that if applying the options doesn't override it, we get the defaults? (e.g. how we handle DialOptions in the grpc package)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.