Skip to content

Commit

Permalink
Merge branch 'master' into pace
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Nov 20, 2020
2 parents 8bcc6ae + 1a641f9 commit 6c935ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ jobs:
brew bump-formula-pr --url=https://github.com/bojand/ghz/archive/${{ env.RELEASE_VERSION }}.tar.gz --message="Automated release pull request using continuous integration." --no-browse -v ghz --force
brew bump-formula-pr --url=https://github.com/bojand/ghz/archive/${{ env.RELEASE_VERSION }}.tar.gz --message="Automated release pull request using continuous integration." --no-browse -v ghz-web --force
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GH_PAGES_ACTION_TOKEN }}
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GH_PAGES_ACTION_TOKEN }}
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ issues:

# TODO fix protobuf deprecated
- path: protodesc/
text: "SA1019: package github.com/golang/protobuf"
text: "SA1019: package github.com/golang/protobuf"

- path: runner/requester.go
text: "SA1019: grpc.WithBalancerName"
12 changes: 12 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type RunConfig struct {
// data
data []byte

// lbStrategy
lbStrategy string
// data func
dataFunc BinaryDataFunc

Expand Down Expand Up @@ -456,6 +458,16 @@ func WithBinaryData(data []byte) Option {
}
}

// WithClientLoadBalancing specifies the LB strategy to use
// The strategies has to be self written and pre defined
func WithClientLoadBalancing(strategy string) Option {
return func(o *RunConfig) error {
o.lbStrategy = strategy

return nil
}
}

// WithBinaryDataFunc specifies the binary data func which will be called on each request
// WithBinaryDataFunc(changeFunc)
func WithBinaryDataFunc(data func(mtd *desc.MethodDescriptor, callData *CallData) []byte) Option {
Expand Down
4 changes: 3 additions & 1 deletion runner/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ func TestRunConfig_newRunConfig(t *testing.T) {
WithDialTimeout(time.Duration(30*time.Second)),
WithName("asdf"),
WithCPUs(4),
WithBinaryDataFunc(changeFunc),
WithBinaryData([]byte("asdf1234foobar")),
WithBinaryDataFunc(changeFunc),
WithClientLoadBalancing("round_robin"),
WithMetadataFromFile("../testdata/metadata.json"),
WithProtoset("testdata/bundle.protoset"),
)
Expand All @@ -161,6 +162,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, 4, c.cpus)
assert.Equal(t, "asdf", c.name)
assert.Equal(t, []byte("asdf1234foobar"), c.data)
assert.Equal(t, "round_robin", c.lbStrategy)
funcName1 := runtime.FuncForPC(reflect.ValueOf(changeFunc).Pointer()).Name()
funcName2 := runtime.FuncForPC(reflect.ValueOf(c.dataFunc).Pointer()).Name()
assert.Equal(t, funcName1, funcName2)
Expand Down
4 changes: 4 additions & 0 deletions runner/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ func (b *Requester) newClientConn(withStatsHandler bool) (*grpc.ClientConn, erro
grpc.MaxCallSendMsgSize(math.MaxInt32),
))

if b.config.lbStrategy != "" {
opts = append(opts, grpc.WithBalancerName(b.config.lbStrategy))
}

// create client connection
return grpc.DialContext(ctx, b.config.host, opts...)
}
Expand Down

0 comments on commit 6c935ef

Please sign in to comment.