Skip to content

Commit

Permalink
Merge pull request #616 from cloudwego/release/v0.4.0
Browse files Browse the repository at this point in the history
chore: release v0.4.0
  • Loading branch information
simon0-o authored Aug 26, 2022
2 parents c8b4cd7 + bcac7f8 commit 4a7219a
Show file tree
Hide file tree
Showing 212 changed files with 8,225 additions and 2,991 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
name: Pull Request Check

on: [pull_request]
on: [ pull_request ]

jobs:
compliant:
runs-on: [self-hosted, X64]
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3

- name: Check License Header
uses: apache/skywalking-eyes@f461a46e74e5fa22e9f9599a355ab4f0ac265469
uses: apache/skywalking-eyes/header@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: typos-action
- name: Check Spell
uses: crate-ci/typos@master

staticcheck:
runs-on: self-hosted
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- uses: actions/cache@v3
with:
Expand All @@ -44,3 +43,18 @@ jobs:
fail_on_error: true
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1029

lint:
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Golangci Lint
# https://golangci-lint.run/
uses: golangci/golangci-lint-action@v3
with:
version: latest
79 changes: 34 additions & 45 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
name: Tests

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
lint-and-ut:
runs-on: self-hosted
unit-benchmark-test:
strategy:
matrix:
go: [ 1.17, 1.18, 1.19 ]
os: [ X64, ARM64 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: ${{ matrix.go }}

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Lint
run: |
go vet -stdmethods=false $(go list ./...)
go install mvdan.cc/[email protected]
test -z "$(gofumpt -l -extra .)"
# block scenario, comment temporarily
# - uses: actions/cache@v3
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-

- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...

benchmark:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...

scenario:
runs-on: self-hosted
scenario-test:
strategy:
matrix:
go: [ 1.17, 1.18 ]
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
architecture: x64

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: ${{ matrix.go }}

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: scenario-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
scenario-${{ runner.os }}-go-
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-go-
# block scenario, comment temporarily
# - uses: actions/cache@v3
# with:
# path: ~/go/pkg/mod
# key: scenario-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# scenario-${{ runner.os }}-go-
# ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# ${{ runner.os }}-go-

- name: Scenario Tests
run: |
Expand Down
41 changes: 41 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Options for analysis running.
run:
# include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin`
skip-dirs-use-default: true
skip-dirs:
- kitex_gen
skip-files:
- ".*\\.mock\\.go$"
# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
format: colored-line-number
# All available settings of specific linters.
# Refer to https://golangci-lint.run/usage/linters
linters-settings:
gofumpt:
# Choose whether to use the extra rules.
# Default: false
extra-rules: true
goimports:
# Put imports beginning with prefix after 3rd-party packages.
# It's a comma-separated list of prefixes.
local-prefixes: github.com/cloudwego/kitex
govet:
# Disable analyzers by name.
# Run `go tool vet help` to see all analyzers.
disable:
- stdmethods
linters:
enable:
- gofumpt
- goimports
- gofmt
disable:
- errcheck
- typecheck
- deadcode
- varcheck
- staticcheck
issues:
exclude-use-default: true
3 changes: 2 additions & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ header:
paths-ignore:
- internal/mocks/thrift/test.go
- pkg/remote/trans/nphttp2/codes/codes.go
- pkg/remote/trans/nphttp2/grpc/grpcframe/
- pkg/remote/trans/nphttp2/grpc/bdp_estimator.go
- pkg/remote/trans/nphttp2/grpc/controlbuf.go
- pkg/remote/trans/nphttp2/grpc/defaults.go
- pkg/remote/trans/nphttp2/grpc/framer.go
- pkg/remote/trans/nphttp2/grpc/flowcontrol.go
- pkg/remote/trans/nphttp2/grpc/http2_client.go
- pkg/remote/trans/nphttp2/grpc/http2_server.go
Expand All @@ -25,7 +27,6 @@ header:
- pkg/remote/codec/protobuf/test.pb.go
- pkg/generic/descriptor/tree.go
- pkg/generic/descriptor/tree_test.go
- pkg/protocol/bprotoc/wire.go
- pkg/utils/json.go

comment: on-failure
69 changes: 49 additions & 20 deletions client/callopt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cloudwego/kitex/internal/client"
"github.com/cloudwego/kitex/pkg/discovery"
"github.com/cloudwego/kitex/pkg/http"
"github.com/cloudwego/kitex/pkg/retry"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/rpcinfo/remoteinfo"
"github.com/cloudwego/kitex/pkg/utils"
Expand All @@ -36,38 +37,45 @@ var callOptionsPool = sync.Pool{
New: newOptions,
}

type callOptions struct {
configs rpcinfo.RPCConfig
type CallOptions struct {
configs rpcinfo.MutableRPCConfig
svr remoteinfo.RemoteInfo
locks *client.ConfigLocks
httpResolver http.Resolver

// export field for using in client
RetryPolicy retry.Policy
}

func newOptions() interface{} {
return &callOptions{
return &CallOptions{
locks: &client.ConfigLocks{
Tags: make(map[string]struct{}),
},
}
}

// Recycle zeros the call option and put it to the pool.
func (co *callOptions) Recycle() {
func (co *CallOptions) Recycle() {
if co == nil {
return
}
co.configs = nil
co.svr = nil
co.RetryPolicy = retry.Policy{}
co.locks.Zero()
callOptionsPool.Put(co)
}

// Option is a series of options used at the beginning of a RPC call.
type Option struct {
f func(o *callOptions, di *strings.Builder)
f func(o *CallOptions, di *strings.Builder)
}

// WithHostPort specifies the target address for a RPC call.
// The given address will overwrite the result from Resolver.
func WithHostPort(hostport string) Option {
return Option{func(o *callOptions, di *strings.Builder) {
return Option{func(o *CallOptions, di *strings.Builder) {
di.WriteString("WithHostPort(")
di.WriteString(hostport)
di.WriteString("),")
Expand All @@ -92,7 +100,7 @@ func setInstance(svr remoteinfo.RemoteInfo, hostport string) error {
// WithURL specifies the target for a RPC call with url.
// The given url will be resolved to hostport and overwrites the result from Resolver.
func WithURL(url string) Option {
return Option{func(o *callOptions, di *strings.Builder) {
return Option{func(o *CallOptions, di *strings.Builder) {
di.WriteString("WithURL(")
di.WriteString(url)
di.WriteString("),")
Expand All @@ -111,7 +119,7 @@ func WithURL(url string) Option {

// WithHTTPHost specifies host in http header(work when RPC over http).
func WithHTTPHost(host string) Option {
return Option{func(o *callOptions, di *strings.Builder) {
return Option{func(o *CallOptions, di *strings.Builder) {
o.svr.SetTag(rpcinfo.HTTPHost, host)
}}
}
Expand All @@ -120,37 +128,35 @@ func WithHTTPHost(host string) Option {
// FIXME: callopt.WithRPCTimeout works only when client.WithRPCTimeout or
// client.WithTimeoutProvider is specified.
func WithRPCTimeout(d time.Duration) Option {
return Option{func(o *callOptions, di *strings.Builder) {
return Option{func(o *CallOptions, di *strings.Builder) {
di.WriteString("WithRPCTimeout(")
utils.WriteInt64ToStringBuilder(di, d.Milliseconds())
di.WriteString("ms)")

cfg := rpcinfo.AsMutableRPCConfig(o.configs)
cfg.SetRPCTimeout(d)
o.configs.SetRPCTimeout(d)
o.locks.Bits |= rpcinfo.BitRPCTimeout

// TODO SetReadWriteTimeout 是否考虑删除
cfg.SetReadWriteTimeout(d)
o.configs.SetReadWriteTimeout(d)
o.locks.Bits |= rpcinfo.BitReadWriteTimeout
}}
}

// WithConnectTimeout specifies the connection timeout for a RPC call.
func WithConnectTimeout(d time.Duration) Option {
return Option{func(o *callOptions, di *strings.Builder) {
return Option{func(o *CallOptions, di *strings.Builder) {
di.WriteString("WithConnectTimeout(")
utils.WriteInt64ToStringBuilder(di, d.Milliseconds())
di.WriteString("ms)")

cfg := rpcinfo.AsMutableRPCConfig(o.configs)
cfg.SetConnectTimeout(d)
o.configs.SetConnectTimeout(d)
o.locks.Bits |= rpcinfo.BitConnectTimeout
}}
}

// WithTag sets the tags for service discovery for a RPC call.
func WithTag(key, val string) Option {
return Option{f: func(o *callOptions, di *strings.Builder) {
return Option{f: func(o *CallOptions, di *strings.Builder) {
di.WriteString("WithTag")
di.WriteByte('(')
di.WriteString(key)
Expand All @@ -163,13 +169,37 @@ func WithTag(key, val string) Option {
}}
}

// WithRetryPolicy sets the retry policy for a RPC call.
// Build retry.Policy with retry.BuildFailurePolicy or retry.BuildBackupRequest instead of building retry.Policy directly.
// Below is use demo, eg:
//
// demo1. call with failure retry policy, default retry error is Timeout
// resp, err := cli.Mock(ctx, req, callopt.WithRetryPolicy(retry.BuildFailurePolicy(retry.NewFailurePolicy())))
// demo2. call with backup request policy
// bp := retry.NewBackupPolicy(10)
// bp.WithMaxRetryTimes(1)
// resp, err := cli.Mock(ctx, req, callopt.WithRetryPolicy(retry.BuildBackupRequest(bp)))
func WithRetryPolicy(p retry.Policy) Option {
return Option{f: func(o *CallOptions, di *strings.Builder) {
if !p.Enable {
return
}
if p.Type == retry.BackupType {
di.WriteString("WithBackupRequest")
} else {
di.WriteString("WithFailureRetry")
}
o.RetryPolicy = p
}}
}

// Apply applies call options to the rpcinfo.RPCConfig and internal.RemoteInfo of kitex client.
// The return value records the name and arguments of each option.
// This function is for internal purpose only.
func Apply(cos []Option, cfg rpcinfo.RPCConfig, svr remoteinfo.RemoteInfo, locks *client.ConfigLocks, httpResolver http.Resolver) string {
func Apply(cos []Option, cfg rpcinfo.MutableRPCConfig, svr remoteinfo.RemoteInfo, locks *client.ConfigLocks, httpResolver http.Resolver) (string, *CallOptions) {
var buf strings.Builder

co := callOptionsPool.Get().(*callOptions)
co := callOptionsPool.Get().(*CallOptions)
co.configs = cfg
co.svr = svr
co.locks.Merge(locks)
Expand All @@ -185,6 +215,5 @@ func Apply(cos []Option, cfg rpcinfo.RPCConfig, svr remoteinfo.RemoteInfo, locks
buf.WriteByte(']')

co.locks.ApplyLocks(cfg, svr)
co.Recycle()
return buf.String()
return buf.String(), co
}
Loading

0 comments on commit 4a7219a

Please sign in to comment.