-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
stats: Add RPC event for blocking for a picker update #6422
Changes from 1 commit
942bdd9
dc4e6b8
1361dcc
e69d389
5ec681a
ff3dda4
906ed7d
e6d27af
00f02a5
a5d9ad2
624eaf2
9fa6112
4685c89
7a796d9
8e40bc1
e1a01c2
1daf196
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,26 @@ import ( | |
"google.golang.org/grpc/internal/channelz" | ||
istatus "google.golang.org/grpc/internal/status" | ||
"google.golang.org/grpc/internal/transport" | ||
"google.golang.org/grpc/stats" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// pickerWrapper is a wrapper of balancer.Picker. It blocks on certain pick | ||
// actions and unblock when there's a picker update. | ||
type pickerWrapper struct { | ||
mu sync.Mutex | ||
done bool | ||
idle bool | ||
blockingCh chan struct{} | ||
picker balancer.Picker | ||
mu sync.Mutex | ||
done bool | ||
idle bool | ||
blockingCh chan struct{} | ||
picker balancer.Picker | ||
statsHandlers []stats.Handler | ||
} | ||
|
||
func newPickerWrapper() *pickerWrapper { | ||
return &pickerWrapper{blockingCh: make(chan struct{})} | ||
func newPickerWrapper(statsHandlers []stats.Handler) *pickerWrapper { | ||
return &pickerWrapper{ | ||
blockingCh: make(chan struct{}), | ||
statsHandlers: statsHandlers, | ||
} | ||
} | ||
|
||
// updatePicker is called by UpdateBalancerState. It unblocks all blocked pick. | ||
|
@@ -125,6 +130,10 @@ func (pw *pickerWrapper) pick(ctx context.Context, failfast bool, info balancer. | |
return nil, balancer.PickResult{}, status.Error(codes.Canceled, errStr) | ||
} | ||
case <-ch: | ||
for _, sh := range pw.statsHandlers { | ||
sh.HandleRPC(ctx, &stats.PickerPicked{}) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: nix newline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah whoops. Deleted newline. |
||
} | ||
continue | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,26 @@ func (s *Begin) IsClient() bool { return s.Client } | |
|
||
func (s *Begin) isRPCStats() {} | ||
|
||
// ResolverResolved represents an event that the resolved finished resolving if | ||
// the ClientConn blocks on resolver resolution while performing a RPC. | ||
type ResolverResolved struct{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
|
||
// IsClient indicates if the stats information is from client side. Only Client | ||
// Side interfaces with a resolver, thus always returns true. | ||
func (rr *ResolverResolved) IsClient() bool { return true } | ||
|
||
func (rr *ResolverResolved) isRPCStats() {} | ||
|
||
// PickerPicked represents an event that the picker finished picking if the ClientConn | ||
// blocks on picker picking while performing a RPC. | ||
type PickerPicked struct{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah needs to encapsulate all: https://github.com/grpc/grpc-go/blob/master/picker_wrapper.go#L87. PickedUpdated sounds fine to me. |
||
|
||
// IsClient indicates if the stats information is from client side. Only Client | ||
// Side interfaces with a Picker, thus always returns true. | ||
func (pp *PickerPicked) IsClient() bool { return true } | ||
|
||
func (pp *PickerPicked) isRPCStats() {} | ||
|
||
// InPayload contains the information for an incoming payload. | ||
type InPayload struct { | ||
// Client is true if this InPayload is from client side. | ||
|
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.
Maybe a comment here or where
statsHandler
field is defined about what this is for and how this is used?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.
Added comment on field: statsHandlers []stats.Handler // to record blocking picker calls