From 52ffc099d322672284803475b1bae9476daec20c Mon Sep 17 00:00:00 2001 From: sljeff Date: Sat, 9 Oct 2021 18:15:51 +0800 Subject: [PATCH] fix stubext: Dialoptions; ChainInterceptor --- docs/CHANGELOG.md | 9 +++++++++ extensions/stubext/ext.go | 20 ++++++++++---------- extensions/stubext/ext_test.go | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 34ee2d71..b8d58c3d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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` diff --git a/extensions/stubext/ext.go b/extensions/stubext/ext.go index 26251047..e979b416 100644 --- a/extensions/stubext/ext.go +++ b/extensions/stubext/ext.go @@ -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 @@ -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 { @@ -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 { diff --git a/extensions/stubext/ext_test.go b/extensions/stubext/ext_test.go index 2d477d47..11ec18c3 100644 --- a/extensions/stubext/ext_test.go +++ b/extensions/stubext/ext_test.go @@ -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)