[go: nahoru, domu]

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

balancer: add server loads from RPC trailers to DoneInfo #2641

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
comments
  • Loading branch information
menghanl committed Apr 2, 2019
commit 4e8037dde9b011d4dba92610c391f660101d3901
17 changes: 10 additions & 7 deletions internal/balancerload/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,31 @@
* limitations under the License.
*/

// Package balancerload defines APIs to parse server loads in trailers. The
// parsed loads are sent to balancers in DoneInfo.
package balancerload
dfawley marked this conversation as resolved.
Show resolved Hide resolved

import (
"google.golang.org/grpc/metadata"
)

// ServerLoadParser converts loads from metadata into a concrete type.
type ServerLoadParser interface {
// Parser converts loads from metadata into a concrete type.
type Parser interface {
// Parse parses loads from metadata.
Parse(md metadata.MD) interface{}
dfawley marked this conversation as resolved.
Show resolved Hide resolved
}

var parser ServerLoadParser
var parser Parser

// SetServerLoadReader sets the load parser.
// SetParser sets the load parser.
//
// Not mutex-protected, should be called before any gRPC functions.
func SetServerLoadReader(lr ServerLoadParser) {
func SetParser(lr Parser) {
parser = lr
}

// ParseServerLoad calls parser.Read().
func ParseServerLoad(md metadata.MD) interface{} {
// Parse calls parser.Read().
func Parse(md metadata.MD) interface{} {
if parser == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/balancerload/orca/orca.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ func (*loadParser) Parse(md metadata.MD) interface{} {
}

func init() {
balancerload.SetServerLoadReader(&loadParser{})
balancerload.SetParser(&loadParser{})
}
2 changes: 0 additions & 2 deletions internal/balancerload/orca/orca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

//go:generate protoc -I ./orca_v1 --go_out=plugins=grpc:./orca_v1 ./orca_v1/orca.proto

package orca

import (
Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ func (a *csAttempt) finish(err error) {
Trailer: tr,
BytesSent: a.s != nil,
BytesReceived: br,
ServerLoad: balancerload.ParseServerLoad(tr),
ServerLoad: balancerload.Parse(tr),
})
}
if a.statsHandler != nil {
Expand Down