Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Feb 13, 2019
1 parent 519c883 commit 00334da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
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

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{}
}

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 @@ -932,7 +932,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

0 comments on commit 00334da

Please sign in to comment.