Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable the percentage limit feature #7

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[中文](https://github.com/kitex-contrib/config-nacos/blob/main/README_CN.md)

Nacos as config centre.
Nacos as config centre for service governance.

## How to use?
## Usage

### Basic

Expand Down Expand Up @@ -143,10 +143,12 @@ Provide the mechanism to custom the nacos parameter `vo.ConfigParam`.
|----|----|
|connection_limit| Maximum concurrent connections |
|qps_limit| Maximum request number every 100ms |

Example:
```
configDataID: ServiceName.limit

> configDataID: ServiceName.limit

```json
{
"connection_limit": 100,
"qps_limit": 2000
whalecold marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -168,8 +170,10 @@ Note:
|failure_policy.backoff_policy| Can only be set one of `fixed` `none` `random` |

Example:
```
configDataId: ClientName.ServiceName.retry

> configDataId: ClientName.ServiceName.retry

```json
{
"*": {
"enable": true,
Expand Down Expand Up @@ -215,8 +219,10 @@ Note: retry.Container has built-in support for specifying the default configurat
[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/rpctimeout/item_rpc_timeout.go#L42)

Example:
```
configDataId: ClientName.ServiceName.rpc_timeout

> configDataId: ClientName.ServiceName.rpc_timeout

```json
{
"*": {
"conn_timeout_ms": 100,
Expand All @@ -237,10 +243,14 @@ Note: The circuit breaker implementation of kitex does not currently support cha
|Variable|Introduction|
|----|----|
|min_sample| Minimum statistical sample number|

Example:
```

The echo method uses the following configuration (0.3, 100) and other methods use the global default configuration (0.5, 200)
configDataId: `ClientName.ServiecName.circuit_break`

> configDataId: `ClientName.ServiecName.circuit_break`

```json
{
"echo": {
"enable": true,
Expand Down
30 changes: 20 additions & 10 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[English](https://github.com/kitex-contrib/config-nacos/blob/main/README.md)

使用 **nacos** 作为 **Kitex** 的配置中心
使用 **nacos** 作为 **Kitex** 的服务治理配置中心

## 这个项目应当如何使用?
## 用法

### 基本使用

Expand Down Expand Up @@ -144,8 +144,10 @@ func main() {
|qps_limit|每 100ms 内的最大请求数量|

例子:
```
configDataID: ServiceName.limit

> configDataID: ServiceName.limit

```json
{
"connection_limit": 100,
"qps_limit": 2000
Expand All @@ -167,8 +169,10 @@ configDataID: ServiceName.limit
|failure_policy.backoff_policy| 可以设置的策略: `fixed` `none` `random` |

例子:
```
configDataId: ClientName.ServiceName.retry

> configDataId: ClientName.ServiceName.retry

```json
whalecold marked this conversation as resolved.
Show resolved Hide resolved
{
"*": {
"enable": true,
Expand Down Expand Up @@ -214,8 +218,10 @@ configDataId: ClientName.ServiceName.retry
[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/rpctimeout/item_rpc_timeout.go#L42)

例子:
```
configDataId: ClientName.ServiceName.rpc_timeout

> configDataId: ClientName.ServiceName.rpc_timeout

```json
{
"*": {
"conn_timeout_ms": 100,
Expand All @@ -236,10 +242,14 @@ configDataId: ClientName.ServiceName.rpc_timeout
|参数|说明|
|----|----|
|min_sample| 最小的统计样本数|

例子:
```

echo 方法使用下面的配置(0.3、100),其他方法使用全局默认配置(0.5、200)
configDataId: `ClientName.ServiceName.circuit_break`

> configDataId: `ClientName.ServiceName.circuit_break`

```json
{
"echo": {
"enable": true,
Expand Down
14 changes: 8 additions & 6 deletions client/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package client

import (
"github.com/kitex-contrib/config-nacos/nacos"
"github.com/kitex-contrib/config-nacos/utils"
"github.com/nacos-group/nacos-sdk-go/vo"

"github.com/cloudwego/kitex/client"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/retry"
"github.com/nacos-group/nacos-sdk-go/vo"

"github.com/kitex-contrib/config-nacos/nacos"
"github.com/kitex-contrib/config-nacos/utils"
)

// WithRetryPolicy sets the retry policy from nacos configuration center.
Expand All @@ -37,8 +37,10 @@ func WithRetryPolicy(dest, src string, nacosClient nacos.Client,
panic(err)
}

rc := initRetryContainer(param, dest, nacosClient)
return []client.Option{
client.WithRetryContainer(initRetryContainer(param, dest, nacosClient)),
client.WithRetryContainer(rc),
client.WithCloseCallbacks(rc.Close),
client.WithCloseCallbacks(func() error {
// cancel the configuration listener when client is closed.
return nacosClient.DeregisterConfig(param)
Expand All @@ -49,7 +51,7 @@ func WithRetryPolicy(dest, src string, nacosClient nacos.Client,
func initRetryContainer(param vo.ConfigParam, dest string,
nacosClient nacos.Client,
) *retry.Container {
retryContainer := retry.NewRetryContainer()
retryContainer := retry.NewRetryContainerWithPercentageLimit()

ts := utils.ThreadSafeSet{}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kitex-contrib/config-nacos
go 1.19

require (
github.com/cloudwego/kitex v0.7.1
github.com/cloudwego/kitex v0.7.2
github.com/cloudwego/kitex-examples v0.2.0
github.com/nacos-group/nacos-sdk-go v1.1.4
github.com/stretchr/testify v1.8.2
Expand All @@ -22,9 +22,9 @@ require (
github.com/cloudwego/configmanager v0.2.0 // indirect
github.com/cloudwego/dynamicgo v0.1.3 // indirect
github.com/cloudwego/fastpb v0.0.4 // indirect
github.com/cloudwego/frugal v0.1.7 // indirect
github.com/cloudwego/frugal v0.1.8 // indirect
github.com/cloudwego/localsession v0.0.2 // indirect
github.com/cloudwego/netpoll v0.4.1 // indirect
github.com/cloudwego/netpoll v0.5.0 // indirect
github.com/cloudwego/thriftgo v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/structtag v1.2.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,16 @@ github.com/cloudwego/fastpb v0.0.4 h1:/ROVVfoFtpfc+1pkQLzGs+azjxUbSOsAqSY4tAAx4m
github.com/cloudwego/fastpb v0.0.4/go.mod h1:/V13XFTq2TUkxj2qWReV8MwfPC4NnPcy6FsrojnsSG0=
github.com/cloudwego/frugal v0.1.3/go.mod h1:b981ViPYdhI56aFYsoMjl9kv6yeqYSO+iEz2jrhkCgI=
github.com/cloudwego/frugal v0.1.6/go.mod h1:9ElktKsh5qd2zDBQ5ENhPSQV7F2dZ/mXlr1eaZGDBFs=
github.com/cloudwego/frugal v0.1.7 h1:Ggyk8mk0WrhBlM4g4RJxdOcVWJl/Hxbd8NJ19J8My6c=
github.com/cloudwego/frugal v0.1.7/go.mod h1:3VECBCSiTYwm3QApqHXjZB9NDH+8hUw7txxlr+6pPb4=
github.com/cloudwego/frugal v0.1.8 h1:MaJDRfvSnepsbUyMlQA9cySJ2+Y/we+r57tv5txx3sE=
github.com/cloudwego/frugal v0.1.8/go.mod h1:F0mLIWHymuQgh6r8N0owTA/ARv1B4SOiKa88tpOAfEU=
github.com/cloudwego/kitex v0.0.4/go.mod h1:EIjPJ4Dom2ornk7xDCdKpUpOnf4Tulevimh4Tn05OGc=
github.com/cloudwego/kitex v0.2.0/go.mod h1:1p4rtGIIiFZMOePYbSPgLkIhdhdfhEtVOJSti/k9vK4=
github.com/cloudwego/kitex v0.3.2/go.mod h1:/XD07VpUD9VQWmmoepASgZ6iw//vgWikVA9MpzLC5i0=
github.com/cloudwego/kitex v0.4.4/go.mod h1:3FcH5h9Qw+dhRljSzuGSpWuThttA8DvK0BsL7HUYydo=
github.com/cloudwego/kitex v0.5.0/go.mod h1:yhw7XikNVG4RstmlQAidBuxMlZYpIiCLsDU8eHPGEMo=
github.com/cloudwego/kitex v0.6.1/go.mod h1:zI1GBrjT0qloTikcCfQTgxg3Ws+yQMyaChEEOcGNUvA=
github.com/cloudwego/kitex v0.7.1 h1:GbCsJ+zDOCsjHaqXVLLD6QIHqDnKPqefqU3+QAOhclg=
github.com/cloudwego/kitex v0.7.1/go.mod h1:TU0FRxTH26XpbR7zm063O/OfqSszVlQvM1eGJES2A4E=
github.com/cloudwego/kitex v0.7.2 h1:lF+Yb058k+91C4dLCvG7YzcoK4CRlV15mltl5WZIbek=
github.com/cloudwego/kitex v0.7.2/go.mod h1:56xuO0DCgKwOMv8NjAs/ooDe1Zb9W8iMKiw04Wv0o7Q=
github.com/cloudwego/kitex-examples v0.2.0 h1:77PXV+5q5OCKE38q2DVvHO7ePemtNapwnX+n6zaVSjo=
github.com/cloudwego/kitex-examples v0.2.0/go.mod h1:jmqlyPgALXoYXiZwWJSpzb8wEycu9PIIyRRs2cN9OJs=
github.com/cloudwego/localsession v0.0.2 h1:N9/IDtCPj1fCL9bCTP+DbXx3f40YjVYWcwkJG0YhQkY=
Expand All @@ -497,8 +497,8 @@ github.com/cloudwego/netpoll v0.2.4/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzC
github.com/cloudwego/netpoll v0.3.1/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E=
github.com/cloudwego/netpoll v0.3.2/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ=
github.com/cloudwego/netpoll v0.4.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ=
github.com/cloudwego/netpoll v0.4.1 h1:/pGsY7Rs09KqEXEniB9fcsEWfi1iY+66bKUO3/NO6hc=
github.com/cloudwego/netpoll v0.4.1/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ=
github.com/cloudwego/netpoll v0.5.0 h1:oRrOp58cPCvK2QbMozZNDESvrxQaEHW2dCimmwH1lcU=
github.com/cloudwego/netpoll v0.5.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ=
github.com/cloudwego/netpoll-http2 v0.0.4/go.mod h1:iFr5SzJCXIYgBg0ubL0fZiCQ6W36s9p0KjXpV04lmoY=
github.com/cloudwego/netpoll-http2 v0.0.6/go.mod h1:+bjPyu2Cd4GDzKa0IegPgp1hjMjpZ6/kXTsSjIsmUk8=
github.com/cloudwego/thriftgo v0.1.2/go.mod h1:LzeafuLSiHA9JTiWC8TIMIq64iadeObgRUhmVG1OC/w=
Expand Down
Loading