Skip to content

Commit 0f18091

Browse files
authored
Merge pull request #695 from cloudwego/release/v0.4.3
chore: release v0.4.3
2 parents 5f0f79e + c65e954 commit 0f18091

158 files changed

Lines changed: 8788 additions & 1869 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ignore:
2+
- "images/.*"
3+
- "tool"
4+
- "internal/mocks"

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,33 @@ optimize: A new optimization
1010
fix: A bug fix
1111
perf: A code change that improves performance
1212
refactor: A code change that neither fixes a bug nor adds a feature
13-
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
13+
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc)
1414
test: Adding missing tests or correcting existing tests
1515
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
1616
-->
1717

18-
#### What this PR does / why we need it (en: English/zh: Chinese):
18+
#### Check the PR title.
1919
<!--
20-
The description will be attached in Release Notes,
21-
so please describe it from user-oriented.
20+
The description of the title will be attached in Release Notes,
21+
so please describe it from user-oriented, what this PR does / why we need it.
22+
Please check your PR title with the below requirements:
23+
-->
24+
- [ ] This PR title match the format: \<type\>(optional scope): \<description\>
25+
- [ ] The description of this PR title is user-oriented and clear enough for others to understand.
26+
27+
28+
#### (Optional) Translate the PR title into Chinese.
29+
30+
31+
#### (Optional) More detailed description for this PR(en: English/zh: Chinese).
32+
<!--
33+
Provide more detailed info for review(e.g., it's recommended to provide perf data if this is a perf type PR).
2234
-->
2335
en:
24-
zh:
36+
zh(optional):
2537

2638
#### Which issue(s) this PR fixes:
2739
<!--
28-
*Automatically closes linked issue when PR is merged.
40+
Automatically closes linked issue when PR is merged.
2941
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
3042
-->

.github/workflows/pr-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- uses: actions/checkout@v3
1010

1111
- name: Check License Header
12-
uses: apache/skywalking-eyes/header@main
12+
uses: apache/skywalking-eyes/header@v0.4.0
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1515

.github/workflows/tests.yml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,50 @@ on: [ push, pull_request ]
44

55
jobs:
66
unit-benchmark-test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Set up Go
11+
uses: actions/setup-go@v3
12+
with:
13+
go-version: '1.16'
14+
- name: Unit Test
15+
run: go test -gcflags all=-N -l -race -covermode=atomic -coverprofile=coverage.txt ./...
16+
- name: Codecov
17+
run: bash <(curl -s https://codecov.io/bash)
18+
- name: Benchmark
19+
run: go test -gcflags all=-N -l -bench=. -benchmem -run=none ./...
20+
21+
compatibility-test:
722
strategy:
823
matrix:
924
go: [ 1.15, 1.17, 1.18, 1.19 ]
1025
os: [ X64, ARM64 ]
1126
runs-on: ${{ matrix.os }}
1227
steps:
1328
- uses: actions/checkout@v3
14-
1529
- name: Set up Go
1630
uses: actions/setup-go@v3
1731
with:
1832
go-version: ${{ matrix.go }}
19-
20-
# block scenario, comment temporarily
21-
# - uses: actions/cache@v3
22-
# with:
23-
# path: ~/go/pkg/mod
24-
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
25-
# restore-keys: |
26-
# ${{ runner.os }}-go-
27-
2833
- name: Unit Test
29-
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
30-
31-
- name: Benchmark
32-
run: go test -bench=. -benchmem -run=none ./...
34+
run: go test -gcflags all=-N -l -race -covermode=atomic -coverprofile=coverage.txt ./...
3335

3436
scenario-test:
3537
strategy:
3638
matrix:
37-
go: [ 1.15, 1.18 ]
39+
go: [ 1.16, 1.18 ]
3840
runs-on: [ self-hosted, X64 ]
3941
steps:
4042
- uses: actions/checkout@v3
41-
4243
- uses: actions/setup-python@v4
4344
with:
4445
python-version: '3.x'
4546
architecture: x64
46-
4747
- name: Set up Go
4848
uses: actions/setup-go@v3
4949
with:
5050
go-version: ${{ matrix.go }}
51-
52-
# block scenario, comment temporarily
53-
# - uses: actions/cache@v3
54-
# with:
55-
# path: ~/go/pkg/mod
56-
# key: scenario-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
57-
# restore-keys: |
58-
# scenario-${{ runner.os }}-go-
59-
# ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
60-
# ${{ runner.os }}-go-
61-
6251
- name: Scenario Tests
6352
run: |
6453
cd ..

.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ header:
3030
- pkg/remote/codec/protobuf/test.pb.go
3131
- pkg/generic/descriptor/tree.go
3232
- pkg/generic/descriptor/tree_test.go
33+
- pkg/generic/httppb_test/idl/echo.pb.go
3334
- pkg/utils/json.go
3435

3536
comment: on-failure

CONTRIBUTING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
## Your First Pull Request
44
We use github for our codebase. You can start by reading [How To Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).
55

6-
## Without Semantic Versioning
7-
We keep the stable code in branch `main` like `golang.org/x`. Development base on branch `develop`. And we promise the **Forward Compatibility** by adding new package directory with suffix `v2/v3` when code has break changes.
8-
96
## Branch Organization
107
We use [git-flow](https://nvie.com/posts/a-successful-git-branching-model/) as our branch organization, as known as [FDD](https://en.wikipedia.org/wiki/Feature-driven_development)
118

client/client.go

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/cloudwego/kitex/pkg/diagnosis"
3434
"github.com/cloudwego/kitex/pkg/discovery"
3535
"github.com/cloudwego/kitex/pkg/endpoint"
36+
"github.com/cloudwego/kitex/pkg/event"
3637
"github.com/cloudwego/kitex/pkg/kerrors"
3738
"github.com/cloudwego/kitex/pkg/klog"
3839
"github.com/cloudwego/kitex/pkg/loadbalance"
@@ -46,7 +47,6 @@ import (
4647
"github.com/cloudwego/kitex/pkg/rpcinfo/remoteinfo"
4748
"github.com/cloudwego/kitex/pkg/rpctimeout"
4849
"github.com/cloudwego/kitex/pkg/serviceinfo"
49-
"github.com/cloudwego/kitex/pkg/transmeta"
5050
"github.com/cloudwego/kitex/pkg/utils"
5151
"github.com/cloudwego/kitex/pkg/warmup"
5252
"github.com/cloudwego/kitex/transport"
@@ -74,21 +74,27 @@ type kClient struct {
7474
closed bool
7575
}
7676

77+
// Set finalizer on kClient does not take effect, because kClient has a circular reference problem
78+
// when construct the endpoint.Endpoint in the invokeHandleEndpoint,
79+
// so wrapping kClient as kcFinalizerClient, and set finalizer on kcFinalizerClient, it can solve this problem.
80+
type kcFinalizerClient struct {
81+
*kClient
82+
}
83+
7784
// NewClient creates a kitex.Client with the given ServiceInfo, it is from generated code.
7885
func NewClient(svcInfo *serviceinfo.ServiceInfo, opts ...Option) (Client, error) {
7986
if svcInfo == nil {
8087
return nil, errors.New("NewClient: no service info")
8188
}
82-
kc := &kClient{
83-
svcInfo: svcInfo,
84-
opt: client.NewOptions(opts),
85-
}
89+
kc := &kcFinalizerClient{kClient: &kClient{}}
90+
kc.svcInfo = svcInfo
91+
kc.opt = client.NewOptions(opts)
8692
if err := kc.init(); err != nil {
8793
return nil, err
8894
}
8995
// like os.File, if kc is garbage-collected, but Close is not called, call Close.
90-
runtime.SetFinalizer(kc, func(c *kClient) {
91-
c.Close()
96+
runtime.SetFinalizer(kc, func(c *kcFinalizerClient) {
97+
_ = c.Close()
9298
})
9399
return kc, nil
94100
}
@@ -107,6 +113,9 @@ func (kc *kClient) init() (err error) {
107113
if err = kc.initProxy(); err != nil {
108114
return err
109115
}
116+
if err = kc.initConnPool(); err != nil {
117+
return err
118+
}
110119
if err = kc.initLBCache(); err != nil {
111120
return err
112121
}
@@ -181,6 +190,33 @@ func (kc *kClient) initProxy() error {
181190
return nil
182191
}
183192

193+
func (kc *kClient) initConnPool() error {
194+
pool := kc.opt.RemoteOpt.ConnPool
195+
kc.opt.CloseCallbacks = append(kc.opt.CloseCallbacks, pool.Close)
196+
197+
if df, ok := pool.(interface{ Dump() interface{} }); ok {
198+
kc.opt.DebugService.RegisterProbeFunc(diagnosis.ConnPoolKey, df.Dump)
199+
}
200+
if r, ok := pool.(remote.ConnPoolReporter); ok && kc.opt.RemoteOpt.EnableConnPoolReporter {
201+
r.EnableReporter()
202+
}
203+
204+
if long, ok := pool.(remote.LongConnPool); ok {
205+
kc.opt.Bus.Watch(discovery.ChangeEventName, func(ev *event.Event) {
206+
ch, ok := ev.Extra.(*discovery.Change)
207+
if !ok {
208+
return
209+
}
210+
for _, inst := range ch.Removed {
211+
if addr := inst.Address(); addr != nil {
212+
long.Clean(addr.Network(), addr.String())
213+
}
214+
}
215+
})
216+
}
217+
return nil
218+
}
219+
184220
func (kc *kClient) initLBCache() error {
185221
if kc.opt.Proxy != nil && kc.opt.Resolver == nil {
186222
return nil
@@ -226,7 +262,7 @@ func (kc *kClient) initMiddlewares(ctx context.Context) {
226262
if kc.opt.XDSEnabled && kc.opt.XDSRouterMiddleware != nil && kc.opt.Proxy == nil {
227263
kc.mws = append(kc.mws, kc.opt.XDSRouterMiddleware)
228264
}
229-
kc.mws = append(kc.mws, kc.opt.CBSuite.ServiceCBMW(), rpcTimeoutMW(ctx))
265+
kc.mws = append(kc.mws, kc.opt.CBSuite.ServiceCBMW(), rpcTimeoutMW(ctx), contextMW)
230266
kc.mws = append(kc.mws, builderMWs...)
231267
kc.mws = append(kc.mws, acl.NewACLMiddleware(kc.opt.ACLRules))
232268
if kc.opt.Proxy == nil {
@@ -330,6 +366,7 @@ func (kc *kClient) Call(ctx context.Context, method string, request, response in
330366
err := kc.eps(ctx, request, response)
331367
kc.opt.TracerCtl.DoFinish(ctx, ri, err)
332368
if err == nil {
369+
err = ri.Invocation().BizStatusErr()
333370
rpcinfo.PutRPCInfo(ri)
334371
}
335372
return err
@@ -357,6 +394,9 @@ func (kc *kClient) Call(ctx context.Context, method string, request, response in
357394

358395
kc.opt.TracerCtl.DoFinish(ctx, ri, err)
359396
callOpts.Recycle()
397+
if err == nil {
398+
err = ri.Invocation().BizStatusErr()
399+
}
360400
if recycleRI {
361401
// why need check recycleRI to decide if recycle RPCInfo?
362402
// 1. no retry, rpc timeout happen will cause panic when response return
@@ -380,21 +420,14 @@ func (kc *kClient) initDebugService() {
380420

381421
func (kc *kClient) richRemoteOption() {
382422
kc.opt.RemoteOpt.SvcInfo = kc.svcInfo
383-
// add default meta handler
384-
if len(kc.opt.MetaHandlers) == 0 {
385-
if kc.opt.Configs.TransportProtocol()&transport.GRPC == transport.GRPC {
386-
kc.opt.MetaHandlers = append(kc.opt.MetaHandlers, transmeta.ClientHTTP2Handler)
387-
}
388-
if kc.opt.Configs.TransportProtocol()&transport.TTHeader == transport.TTHeader {
389-
kc.opt.MetaHandlers = append(kc.opt.MetaHandlers, transmeta.ClientTTHeaderHandler)
390-
}
391-
}
392423
// for client trans info handler
393-
// TODO in stream situations, meta is only assembled when the stream creates
394-
// metaHandler needs to be called separately.
395-
// (newClientStreamer: call WriteMeta before remotecli.NewClient)
396-
transInfoHdlr := bound.NewTransMetaHandler(kc.opt.MetaHandlers)
397-
kc.opt.RemoteOpt.PrependBoundHandler(transInfoHdlr)
424+
if len(kc.opt.MetaHandlers) > 0 {
425+
// TODO in stream situations, meta is only assembled when the stream creates
426+
// metaHandler needs to be called separately.
427+
// (newClientStreamer: call WriteMeta before remotecli.NewClient)
428+
transInfoHdlr := bound.NewTransMetaHandler(kc.opt.MetaHandlers)
429+
kc.opt.RemoteOpt.PrependBoundHandler(transInfoHdlr)
430+
}
398431
}
399432

400433
func (kc *kClient) buildInvokeChain() error {
@@ -461,7 +494,7 @@ func (kc *kClient) invokeHandleEndpoint() (endpoint.Endpoint, error) {
461494
// Close is not concurrency safe.
462495
func (kc *kClient) Close() error {
463496
if kc.closed {
464-
panic("client is already closed")
497+
return nil
465498
}
466499
kc.closed = true
467500
var errs utils.ErrChain
@@ -475,7 +508,6 @@ func (kc *kClient) Close() error {
475508
errs.Append(err)
476509
}
477510
}
478-
runtime.SetFinalizer(kc, nil)
479511
if errs.HasError() {
480512
return errs
481513
}

0 commit comments

Comments
 (0)