From 82f0b39ccac72b01df1ff5090eca2af6fdae395e Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Sat, 18 Nov 2023 17:00:32 +0800 Subject: [PATCH 1/7] docs:update README.md --- README.md | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++- README_CN.md | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++ etcd/etcd.go | 8 +- 3 files changed, 569 insertions(+), 5 deletions(-) create mode 100644 README_CN.md diff --git a/README.md b/README.md index a46ae92..a3f2002 100644 --- a/README.md +++ b/README.md @@ -1 +1,283 @@ -# .github \ No newline at end of file +# config-etcd (*This is a community driven project*) + +[中文](./README_CN.md) + +etcd as config centre for service governance. + +## Usage + +### Basic + +#### Server + +```go +package main + +import ( + "context" + "log" + + "github.com/cloudwego/kitex-examples/kitex_gen/api" + "github.com/cloudwego/kitex-examples/kitex_gen/api/echo" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/cloudwego/kitex/pkg/rpcinfo" + "github.com/cloudwego/kitex/server" + "github.com/kitex-contrib/config-etcd/etcd" + etcdServer "github.com/kitex-contrib/config-etcd/server" +) + +var _ api.Echo = &EchoImpl{} + +// EchoImpl implements the last service interface defined in the IDL. +type EchoImpl struct{} + +// Echo implements the Echo interface. +func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Response, err error) { + klog.Info("echo called") + return &api.Response{Message: req.Message}, nil +} + +func main() { + klog.SetLevel(klog.LevelDebug) + serviceName := "ServiceName" + etcdClient, _ := etcd.NewClient(etcd.Options{}) + svr := echo.NewServer( + new(EchoImpl), + server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}), + server.WithSuite(etcdServer.NewSuite(serviceName, etcdClient)), + ) + if err := svr.Run(); err != nil { + log.Println("server stopped with error:", err) + } else { + log.Println("server stopped") + } +} + +``` + +#### Client + +```go +package main + +import ( + "context" + "log" + "time" + + "github.com/cloudwego/kitex-examples/kitex_gen/api" + "github.com/cloudwego/kitex-examples/kitex_gen/api/echo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/pkg/klog" + etcdclient "github.com/kitex-contrib/config-etcd/client" + "github.com/kitex-contrib/config-etcd/etcd" + "github.com/kitex-contrib/config-etcd/utils" +) + +type configLog struct{} + +func (cl *configLog) Apply(opt *utils.Options) { + fn := func(k *etcd.Key) { + klog.Infof("etcd config %v", k) + } + opt.EtcdCustomFunctions = append(opt.EtcdCustomFunctions, fn) +} + +func main() { + klog.SetLevel(klog.LevelDebug) + + etcdClient, err := etcd.NewClient(etcd.Options{}) + if err != nil { + panic(err) + } + + cl := &configLog{} + + serviceName := "ServiceName" + clientName := "ClientName" + client, err := echo.NewClient( + serviceName, + client.WithHostPorts("0.0.0.0:8888"), + client.WithSuite(etcdclient.NewSuite(serviceName, clientName, etcdClient, cl)), + ) + if err != nil { + log.Fatal(err) + } + for { + req := &api.Request{Message: "my request"} + resp, err := client.Echo(context.Background(), req) + if err != nil { + klog.Errorf("take request error: %v", err) + } else { + klog.Infof("receive response %v", resp) + } + time.Sleep(time.Second * 10) + } +} +``` + +### Etcd Configuration + +The client is initialized according to the parameters of `Options` and connects to the etcd server. After the connection is established, the suite subscribes the appropriate configuration based on `Prefix`, `ServerPathFormat` and `ClientPathFormat` to updates its own policy dynamically. See the `Options` variables below for specific parameters. + +The configuration format only supports `json`. You can use the [SetParser](https://github.com/kitex-contrib/config-etcd/blob/fef1947d99ee8df270ae39f661069b47a3ab284f/etcd/etcd.go#L122) function to customise the format parsing method, and the `CustomFunction` function to customise the format of the subscription function during `NewSuite`. +#### + +#### CustomFunction + +Provide the mechanism to custom the etcd parameter `Key`. +```go +type Key struct { + Prefix string + Path string +} +``` + +#### Options Variable + +| Variable Name | Default Value | Introduction | +|------------------|-------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Address | 127.0.0.1 | Etcd server address | +| Port | 2379 | Etcd server port | +| Prefix | /KitexConfig | The prefix of Etcd | +| ClientPathFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ClientServiceName` `ServiceName` `Category` three metadata that can be customised | +| ServerPathFormat | {{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ServiceName` `Category` two metadatas that can be customised | + +#### Governance Policy +> The configPath and configPrefix in the following example use default values, the service name is `ServiceName` and the client name is `ClientName`. + +##### Rate Limit Category=limit +> Currently, current limiting only supports the server side, so ClientServiceName is empty. + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/limiter/item_limiter.go#L33) + +| Variable | Introduction | +|------------------|------------------------------------| +| connection_limit | Maximum concurrent connections | +| qps_limit | Maximum request number every 100ms | + +Example: + +> configPath: ServiceName/limit + +```json +{ + "connection_limit": 100, + "qps_limit": 2000 +} +``` + +Note: + +- The granularity of the current limit configuration is server global, regardless of client or method. +- Not configured or value is 0 means not enabled. +- connection_limit and qps_limit can be configured independently, e.g. connection_limit = 100, qps_limit = 0 + +##### Retry Policy Category=retry +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/retry/policy.go#L63) + +| Variable | Introduction | +|-------------------------------|------------------------------------------------| +| type | 0: failure_policy 1: backup_policy | +| failure_policy.backoff_policy | Can only be set one of `fixed` `none` `random` | + +Example: + +> configPath: ClientName/ServiceName/retry + +```json +{ + "*": { + "enable": true, + "type": 0, + "failure_policy": { + "stop_policy": { + "max_retry_times": 3, + "max_duration_ms": 2000, + "cb_policy": { + "error_rate": 0.5 + } + }, + "backoff_policy": { + "backoff_type": "fixed", + "cfg_items": { + "fix_ms": 50 + } + }, + "retry_same_node": false + } + }, + "echo": { + "enable": true, + "type": 1, + "backup_policy": { + "retry_delay_ms": 100, + "retry_same_node": false, + "stop_policy": { + "max_retry_times": 2, + "max_duration_ms": 300, + "cb_policy": { + "error_rate": 0.2 + } + } + } + } +} +``` +Note: retry.Container has built-in support for specifying the default configuration using the `*` wildcard (see the [getRetryer](https://github.com/cloudwego/kitex/blob/v0.5.1/pkg/retry/retryer.go#L240) method for details). + +##### RPC Timeout Category=rpc_timeout + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/rpctimeout/item_rpc_timeout.go#L42) + +Example: + +> configPath: ClientName/ServiceName/rpc_timeout + +```json +{ + "*": { + "conn_timeout_ms": 100, + "rpc_timeout_ms": 3000 + }, + "echo": { + "conn_timeout_ms": 50, + "rpc_timeout_ms": 1000 + } +} +``` +Note: The circuit breaker implementation of kitex does not currently support changing the global default configuration (see [initServiceCB](https://github.com/cloudwego/kitex/blob/v0.5.1/pkg/circuitbreak/cbsuite.go#L195) for details). + +##### Circuit Break: Category=circuit_break + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/circuitbreak/item_circuit_breaker.go#L30) + +| 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) + +> configPath: `ClientName/ServiecName/circuit_break` + +```json +{ + "echo": { + "enable": true, + "err_rate": 0.3, + "min_sample": 100 + } +} +``` +### More Info + +Refer to [example](https://github.com/kitex-contrib/config-etcd/tree/main/example) for more usage. + +## Compatibility + +For grpc compatibility, the version of Go must >=1.19 + +maintained by: [ViolaPioggia](https://github.com/violapioggia) + diff --git a/README_CN.md b/README_CN.md new file mode 100644 index 0000000..d153bee --- /dev/null +++ b/README_CN.md @@ -0,0 +1,282 @@ +# config-etcd (*这是一个社区驱动的项目*) + +[English](./README.md) + +使用 **etcd** 作为 **Kitex** 的服务治理配置中心 + +## 用法 + +### 基本使用 + +#### 服务端 + +```go +package main + +import ( + "context" + "log" + + "github.com/cloudwego/kitex-examples/kitex_gen/api" + "github.com/cloudwego/kitex-examples/kitex_gen/api/echo" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/cloudwego/kitex/pkg/rpcinfo" + "github.com/cloudwego/kitex/server" + "github.com/kitex-contrib/config-etcd/etcd" + etcdServer "github.com/kitex-contrib/config-etcd/server" +) + +var _ api.Echo = &EchoImpl{} + +// EchoImpl implements the last service interface defined in the IDL. +type EchoImpl struct{} + +// Echo implements the Echo interface. +func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Response, err error) { + klog.Info("echo called") + return &api.Response{Message: req.Message}, nil +} + +func main() { + klog.SetLevel(klog.LevelDebug) + serviceName := "ServiceName" + etcdClient, _ := etcd.NewClient(etcd.Options{}) + svr := echo.NewServer( + new(EchoImpl), + server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}), + server.WithSuite(etcdServer.NewSuite(serviceName, etcdClient)), + ) + if err := svr.Run(); err != nil { + log.Println("server stopped with error:", err) + } else { + log.Println("server stopped") + } +} + +``` + +#### Client + +```go +package main + +import ( + "context" + "log" + "time" + + "github.com/cloudwego/kitex-examples/kitex_gen/api" + "github.com/cloudwego/kitex-examples/kitex_gen/api/echo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/pkg/klog" + etcdclient "github.com/kitex-contrib/config-etcd/client" + "github.com/kitex-contrib/config-etcd/etcd" + "github.com/kitex-contrib/config-etcd/utils" +) + +type configLog struct{} + +func (cl *configLog) Apply(opt *utils.Options) { + fn := func(k *etcd.Key) { + klog.Infof("etcd config %v", k) + } + opt.EtcdCustomFunctions = append(opt.EtcdCustomFunctions, fn) +} + +func main() { + klog.SetLevel(klog.LevelDebug) + + etcdClient, err := etcd.NewClient(etcd.Options{}) + if err != nil { + panic(err) + } + + cl := &configLog{} + + serviceName := "ServiceName" + clientName := "ClientName" + client, err := echo.NewClient( + serviceName, + client.WithHostPorts("0.0.0.0:8888"), + client.WithSuite(etcdclient.NewSuite(serviceName, clientName, etcdClient, cl)), + ) + if err != nil { + log.Fatal(err) + } + for { + req := &api.Request{Message: "my request"} + resp, err := client.Echo(context.Background(), req) + if err != nil { + klog.Errorf("take request error: %v", err) + } else { + klog.Infof("receive response %v", resp) + } + time.Sleep(time.Second * 10) + } +} +``` + +### Etcd 配置 + +根据 Options 的参数初始化 client,建立链接之后 suite 会根据 `Prefix` 以及 `ServerPathFormat` 或者 `ClientPathFormat` 订阅对应的配置并动态更新自身策略,具体参数参考下面 `Options` 变量。 + +配置的格式默认仅支持 `json`,可以使用函数 [SetParser](https://github.com/kitex-contrib/config-nacos/blob/eb006978517678dd75a81513142d3faed6a66f8d/nacos/nacos.go#L68) 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。 +#### + +#### CustomFunction + +允许用户自定义 etcd 的参数来自定义参数 `Key`. +```go +type Key struct { + Prefix string + Path string +} +``` + +#### Options 默认值 + +| 参数 | 变量默认值 | 作用 | +|------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------| +| Address | 127.0.0.1 | Etcd 服务器地址 | +| Port | 2379 | Etcd 服务器端口 | +| Prefix | /KitexConfig | Etcd 中的 prefix | +| ClientPathFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ClientServiceName` `ServiceName` `Category` 三个元数据 | +| ServerPathFormat | {{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ServiceName` `Category` 两个元数据 | + +#### 治理策略 +下面例子中的 configPath 以及 configPrefix 均使用默认值,服务名称为 ServiceName,客户端名称为 ClientName + +##### 限流 Category=limit +> 限流目前只支持服务端,所以 ClientServiceName 为空。 + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/limiter/item_limiter.go#L33) + +| 字段 | 说明 | +|------------------|------------------| +| connection_limit | 最大并发数量 | +| qps_limit | 每 100ms 内的最大请求数量 | + +例子: + +> configPath: ServiceName.limit + +```json +{ + "connection_limit": 100, + "qps_limit": 2000 +} +``` +注: + +- 限流配置的粒度是 Server 全局,不分 client、method +- 「未配置」或「取值为 0」表示不开启 +- connection_limit 和 qps_limit 可以独立配置,例如 connection_limit = 100, qps_limit = 0 + +##### 重试 Category=retry + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/retry/policy.go#L63) + +| 参数 | 说明 | +|-------------------------------|------------------------------------| +| type | 0: failure_policy 1: backup_policy | +| failure_policy.backoff_policy | 可以设置的策略: `fixed` `none` `random` | + +例子: + +> configPath: ClientName.ServiceName.retry + +```json +{ + "*": { + "enable": true, + "type": 0, + "failure_policy": { + "stop_policy": { + "max_retry_times": 3, + "max_duration_ms": 2000, + "cb_policy": { + "error_rate": 0.5 + } + }, + "backoff_policy": { + "backoff_type": "fixed", + "cfg_items": { + "fix_ms": 50 + } + }, + "retry_same_node": false + } + }, + "echo": { + "enable": true, + "type": 1, + "backup_policy": { + "retry_delay_ms": 100, + "retry_same_node": false, + "stop_policy": { + "max_retry_times": 2, + "max_duration_ms": 300, + "cb_policy": { + "error_rate": 0.2 + } + } + } + } +} +``` +注:retry.Container 内置支持用 * 通配符指定默认配置(详见 [getRetryer](https://github.com/cloudwego/kitex/blob/v0.5.1/pkg/retry/retryer.go#L240) 方法) + +##### 超时 Category=rpc_timeout + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/rpctimeout/item_rpc_timeout.go#L42) + +例子: + +> configPath: ClientName.ServiceName.rpc_timeout + +```json +{ + "*": { + "conn_timeout_ms": 100, + "rpc_timeout_ms": 3000 + }, + "echo": { + "conn_timeout_ms": 50, + "rpc_timeout_ms": 1000 + } +} +``` +注:kitex 的熔断实现目前不支持修改全局默认配置(详见 [initServiceCB](https://github.com/cloudwego/kitex/blob/v0.5.1/pkg/circuitbreak/cbsuite.go#L195)) + +##### 熔断: Category=circuit_break + +[JSON Schema](https://github.com/cloudwego/kitex/blob/develop/pkg/circuitbreak/item_circuit_breaker.go#L30) + +| 参数 | 说明 | +|------------|----------| +| min_sample | 最小的统计样本数 | + +例子: + +echo 方法使用下面的配置(0.3、100),其他方法使用全局默认配置(0.5、200) + +> configPath: `ClientName.ServiceName.circuit_break` + +```json +{ + "echo": { + "enable": true, + "err_rate": 0.3, + "min_sample": 100 + } +} +``` +### 更多信息 + +更多示例请参考 [example](https://github.com/kitex-contrib/config-etcd/tree/main/example) + +## Compatibility +因为 grpc 兼容的问题,Go 的版本必须 >= 1.19 + +主要贡献者: [ViolaPioggia](https://github.com/violapioggia) + diff --git a/etcd/etcd.go b/etcd/etcd.go index e0cc0e4..c0c2b9f 100644 --- a/etcd/etcd.go +++ b/etcd/etcd.go @@ -60,7 +60,7 @@ type Options struct { Node []string Prefix string ServerPathFormat string - clientPathFormat string + ClientPathFormat string Timeout time.Duration LoggerConfig *zap.Config ConfigParser ConfigParser @@ -85,8 +85,8 @@ func NewClient(opts Options) (Client, error) { if opts.ServerPathFormat == "" { opts.ServerPathFormat = EtcdDefaultServerPath } - if opts.clientPathFormat == "" { - opts.clientPathFormat = EtcdDefaultClientPath + if opts.ClientPathFormat == "" { + opts.ClientPathFormat = EtcdDefaultClientPath } etcdClient, err := clientv3.New(clientv3.Config{ Endpoints: opts.Node, @@ -103,7 +103,7 @@ func NewClient(opts Options) (Client, error) { if err != nil { return nil, err } - clientNameTemplate, err := template.New("clientName").Parse(opts.clientPathFormat) + clientNameTemplate, err := template.New("clientName").Parse(opts.ClientPathFormat) if err != nil { return nil, err } From 7907835bd69bebec9590da70bdb4d3574117f727 Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Sat, 18 Nov 2023 17:03:10 +0800 Subject: [PATCH 2/7] docs:update README_CN.md --- README_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_CN.md b/README_CN.md index d153bee..303c2ca 100644 --- a/README_CN.md +++ b/README_CN.md @@ -120,7 +120,7 @@ func main() { 根据 Options 的参数初始化 client,建立链接之后 suite 会根据 `Prefix` 以及 `ServerPathFormat` 或者 `ClientPathFormat` 订阅对应的配置并动态更新自身策略,具体参数参考下面 `Options` 变量。 -配置的格式默认仅支持 `json`,可以使用函数 [SetParser](https://github.com/kitex-contrib/config-nacos/blob/eb006978517678dd75a81513142d3faed6a66f8d/nacos/nacos.go#L68) 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。 +配置的格式默认仅支持 `json`,可以使用函数 [SetParser](https://github.com/kitex-contrib/config-etcd/blob/fef1947d99ee8df270ae39f661069b47a3ab284f/etcd/etcd.go#L122) 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。 #### #### CustomFunction From 109f7c61c10d0dc0e0b325449ded7c3c57d88a44 Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Sun, 19 Nov 2023 18:40:30 +0800 Subject: [PATCH 3/7] docs:adjust README.md --- README.md | 7 +------ README_CN.md | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index a3f2002..1d3eb8c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [中文](./README_CN.md) -etcd as config centre for service governance. +etcd as config center for service governance. ## Usage @@ -118,11 +118,6 @@ func main() { ### Etcd Configuration -The client is initialized according to the parameters of `Options` and connects to the etcd server. After the connection is established, the suite subscribes the appropriate configuration based on `Prefix`, `ServerPathFormat` and `ClientPathFormat` to updates its own policy dynamically. See the `Options` variables below for specific parameters. - -The configuration format only supports `json`. You can use the [SetParser](https://github.com/kitex-contrib/config-etcd/blob/fef1947d99ee8df270ae39f661069b47a3ab284f/etcd/etcd.go#L122) function to customise the format parsing method, and the `CustomFunction` function to customise the format of the subscription function during `NewSuite`. -#### - #### CustomFunction Provide the mechanism to custom the etcd parameter `Key`. diff --git a/README_CN.md b/README_CN.md index 303c2ca..9cc071e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -118,11 +118,6 @@ func main() { ### Etcd 配置 -根据 Options 的参数初始化 client,建立链接之后 suite 会根据 `Prefix` 以及 `ServerPathFormat` 或者 `ClientPathFormat` 订阅对应的配置并动态更新自身策略,具体参数参考下面 `Options` 变量。 - -配置的格式默认仅支持 `json`,可以使用函数 [SetParser](https://github.com/kitex-contrib/config-etcd/blob/fef1947d99ee8df270ae39f661069b47a3ab284f/etcd/etcd.go#L122) 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。 -#### - #### CustomFunction 允许用户自定义 etcd 的参数来自定义参数 `Key`. From 4f82dfdaa5f2e0ba87ab0de41c9cb210af8f7491 Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Mon, 20 Nov 2023 18:45:17 +0800 Subject: [PATCH 4/7] docs:update configPath --- README.md | 15 +++++++++------ README_CN.md | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1d3eb8c..cb524ad 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,10 @@ func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Respon func main() { klog.SetLevel(klog.LevelDebug) serviceName := "ServiceName" - etcdClient, _ := etcd.NewClient(etcd.Options{}) + etcdClient, err := etcd.NewClient(etcd.Options{}) + if err!=nil { + panic(err) + } svr := echo.NewServer( new(EchoImpl), server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}), @@ -153,7 +156,7 @@ type Key struct { Example: -> configPath: ServiceName/limit +> configPath: /KitexConfig/ServiceName/limit ```json { @@ -178,7 +181,7 @@ Note: Example: -> configPath: ClientName/ServiceName/retry +> configPath: /KitexConfig/ClientName/ServiceName/retry ```json { @@ -190,7 +193,7 @@ Example: "max_retry_times": 3, "max_duration_ms": 2000, "cb_policy": { - "error_rate": 0.5 + "error_rate": 0.3 } }, "backoff_policy": { @@ -227,7 +230,7 @@ Note: retry.Container has built-in support for specifying the default configurat Example: -> configPath: ClientName/ServiceName/rpc_timeout +> configPath: /KitexConfig/ClientName/ServiceName/rpc_timeout ```json { @@ -255,7 +258,7 @@ Example: The echo method uses the following configuration (0.3, 100) and other methods use the global default configuration (0.5, 200) -> configPath: `ClientName/ServiecName/circuit_break` +> configPath: /KitexConfig/ClientName/ServiceName/circuit_break ```json { diff --git a/README_CN.md b/README_CN.md index 9cc071e..0e447f5 100644 --- a/README_CN.md +++ b/README_CN.md @@ -40,7 +40,10 @@ func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Respon func main() { klog.SetLevel(klog.LevelDebug) serviceName := "ServiceName" - etcdClient, _ := etcd.NewClient(etcd.Options{}) + etcdClient, err := etcd.NewClient(etcd.Options{}) + if err!=nil { + panic(err) + } svr := echo.NewServer( new(EchoImpl), server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}), @@ -153,7 +156,7 @@ type Key struct { 例子: -> configPath: ServiceName.limit +> configPath: /KitexConfig/ServiceName/limit ```json { @@ -178,7 +181,7 @@ type Key struct { 例子: -> configPath: ClientName.ServiceName.retry +> configPath: /KitexConfig/ClientName/ServiceName/retry ```json { @@ -190,7 +193,7 @@ type Key struct { "max_retry_times": 3, "max_duration_ms": 2000, "cb_policy": { - "error_rate": 0.5 + "error_rate": 0.3 } }, "backoff_policy": { @@ -227,7 +230,7 @@ type Key struct { 例子: -> configPath: ClientName.ServiceName.rpc_timeout +> configPath: /KitexConfig/ClientName/ServiceName/rpc_timeout ```json { @@ -255,7 +258,7 @@ type Key struct { echo 方法使用下面的配置(0.3、100),其他方法使用全局默认配置(0.5、200) -> configPath: `ClientName.ServiceName.circuit_break` +> configPath: /KitexConfig/ClientName/ServiceName/circuit_break ```json { From b878d31d37527e38d19a5c3f0fb0c4b3acfb13be Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Mon, 20 Nov 2023 19:15:12 +0800 Subject: [PATCH 5/7] docs:update configPath --- README.md | 4 ++-- README_CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb524ad..4e6a07c 100644 --- a/README.md +++ b/README.md @@ -138,8 +138,8 @@ type Key struct { | Address | 127.0.0.1 | Etcd server address | | Port | 2379 | Etcd server port | | Prefix | /KitexConfig | The prefix of Etcd | -| ClientPathFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ClientServiceName` `ServiceName` `Category` three metadata that can be customised | -| ServerPathFormat | {{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ServiceName` `Category` two metadatas that can be customised | +| ClientPathFormat | {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ClientServiceName` `ServiceName` `Category` three metadata that can be customised | +| ServerPathFormat | {{.ServerServiceName}}/{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ServiceName` `Category` two metadatas that can be customised | #### Governance Policy > The configPath and configPrefix in the following example use default values, the service name is `ServiceName` and the client name is `ClientName`. diff --git a/README_CN.md b/README_CN.md index 0e447f5..328bf1e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -138,8 +138,8 @@ type Key struct { | Address | 127.0.0.1 | Etcd 服务器地址 | | Port | 2379 | Etcd 服务器端口 | | Prefix | /KitexConfig | Etcd 中的 prefix | -| ClientPathFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ClientServiceName` `ServiceName` `Category` 三个元数据 | -| ServerPathFormat | {{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ServiceName` `Category` 两个元数据 | +| ClientPathFormat | {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ClientServiceName` `ServiceName` `Category` 三个元数据 | +| ServerPathFormat | {{.ServerServiceName}}/{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ServiceName` `Category` 两个元数据 | #### 治理策略 下面例子中的 configPath 以及 configPrefix 均使用默认值,服务名称为 ServiceName,客户端名称为 ClientName From 730a0b7d8eff01517beea25b08ba55abaa33d58b Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Mon, 20 Nov 2023 20:02:42 +0800 Subject: [PATCH 6/7] chore:add etcd license --- LICENSE-etcd-client-go | 202 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 LICENSE-etcd-client-go diff --git a/LICENSE-etcd-client-go b/LICENSE-etcd-client-go new file mode 100644 index 0000000..7a4a3ea --- /dev/null +++ b/LICENSE-etcd-client-go @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file From a43b472ee8a25b0d0d956b34e242c578ed46efd1 Mon Sep 17 00:00:00 2001 From: violapioggia <2604296771@qq.com> Date: Mon, 20 Nov 2023 20:10:51 +0800 Subject: [PATCH 7/7] chore:move licenses dir --- .../LICENSE-etcd-client-go | 0 licenses/LICENSE-zap | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) rename LICENSE-etcd-client-go => licenses/LICENSE-etcd-client-go (100%) create mode 100644 licenses/LICENSE-zap diff --git a/LICENSE-etcd-client-go b/licenses/LICENSE-etcd-client-go similarity index 100% rename from LICENSE-etcd-client-go rename to licenses/LICENSE-etcd-client-go diff --git a/licenses/LICENSE-zap b/licenses/LICENSE-zap new file mode 100644 index 0000000..2cf1638 --- /dev/null +++ b/licenses/LICENSE-zap @@ -0,0 +1,19 @@ +Copyright (c) 2016-2017 Uber Technologies, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file