Skip to content

Commit

Permalink
Merge pull request #350 from sljeff/fix-stubext
Browse files Browse the repository at this point in the history
fix stubext: Dialoptions; ChainInterceptor
  • Loading branch information
fenngwd authored Oct 11, 2021
2 parents 96d7086 + 52ffc09 commit 80c803e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.17.0 (2021-10-09)

- 修正 `DialOptions` 拼写
- 修复启用 apm 的时候 retry 不生效的问题

**BREAKING CHANGE**:

初始化 stubext 时参数应该改叫 `DialOptions`

# 0.16.0 (2021-08-16)

- 改用 `shanbay/amqp`
Expand Down
20 changes: 10 additions & 10 deletions extensions/stubext/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (

type StubExt struct {
NS string
DailOptions []grpc.DialOption
DialOptions []grpc.DialOption
NewClientFuncs map[string]NewClientFunc
RetryCodes []codes.Code
app *gobay.Application
Expand Down Expand Up @@ -93,7 +93,7 @@ func (d *StubExt) Init(app *gobay.Application) error {
if d.Mocked {
return nil
}
if conn, err := d.GetConn(d.DailOptions...); err != nil {
if conn, err := d.GetConn(d.DialOptions...); err != nil {
return err
} else {
for k, v := range d.NewClientFuncs {
Expand Down Expand Up @@ -129,23 +129,23 @@ func (d *StubExt) getCallOpts() []grpc_retry.CallOption {
func (d *StubExt) GetConn(userOpts ...grpc.DialOption) (*grpc.ClientConn, error) {
if d.conn == nil {
var opts []grpc.DialOption
// opts: per call opts
callOpts := d.getCallOpts()
opts = append(
opts,
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(callOpts...)),
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(callOpts...)),
)
// opts: authority
if d.Authority != "" {
opts = append(opts, grpc.WithAuthority(d.Authority))
}
// opts: apm
if d.enableApm {
opts = append(opts, grpc.WithUnaryInterceptor(apmgrpc.NewUnaryClientInterceptor()))
opts = append(opts, grpc.WithChainUnaryInterceptor(apmgrpc.NewUnaryClientInterceptor()))
}
// opts: user opts
opts = append(opts, userOpts...)
// opts: per call opts
callOpts := d.getCallOpts()
opts = append(
opts,
grpc.WithChainUnaryInterceptor(grpc_retry.UnaryClientInterceptor(callOpts...)),
grpc.WithChainStreamInterceptor(grpc_retry.StreamClientInterceptor(callOpts...)),
)
// connect
ctxDefault := context.Background()
if d.ConnTimeout > 0 {
Expand Down
2 changes: 1 addition & 1 deletion extensions/stubext/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
func setupStub(env string) {
stubext = StubExt{
NS: "stub_health_",
DailOptions: []grpc.DialOption{grpc.WithInsecure(), grpc.WithBlock()},
DialOptions: []grpc.DialOption{grpc.WithInsecure(), grpc.WithBlock()},
NewClientFuncs: map[string]NewClientFunc{
"health": func(conn *grpc.ClientConn) interface{} {
return protos_go.NewHealthClient(conn)
Expand Down

0 comments on commit 80c803e

Please sign in to comment.