Etcd
Install
go get github.com/kitex-contrib/config-etcd
Suite
The configuration center adapter of etcd, kitex uses WithSuite
to convert the configuration in etcd into the governance feature configuration of kitex.
The following is a complete usage example:
Server
Function Signature:
func NewSuite(service string, cli etcd.Client, opts ...utils.Option,) *EtcdServerSuite
Sample code:
Client
Function Signature:
func NewSuite(service,client string, cli etcd.Client, opts ...utils.Option,) *EtcdServerSuite
Sample code:
NewClient
Create client.
Function Signature:
func NewClient(opts Options) (Client, error)
Sample code:
SetParser
Set a custom parser for deserializing etcd configuration. If not specified, it will be the default parser.
The default parser parses configuration in json format.
Function Signature:
func (c *client) SetParser(parser ConfigParser)
Sample code:
Set the configuration for parsing yaml types.
Etcd Configuration
Options Struct
Options Variable
The key in etcd consists of prefix and path, where prefix is the prefix and path is the path.
Variable Name | Default Value | Introduction |
---|---|---|
Node | 127.0.0.1:2379 | Etcd server nodes |
Prefix | /KitexConfig | The prefix of Etcd |
ClientPathFormat | {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} | Use go template syntax rendering to generate the appropriate ID, and use ClientServiceName ServiceName Category three metadata that can be customised, used with Prefix to form the key in etcd |
ServerPathFormat | {{.ServerServiceName}}/{{.Category}} | Use go template syntax rendering to generate the appropriate ID, and use ServiceName Category two metadatas that can be customised, used with Prefix to form the key in etcd |
Timeout | 5 * time.Second | five seconds timeout |
LoggerConfig | NULL | Default Logger |
ConfigParser | defaultConfigParser | The default parser, which defaults to parsing json format data |
Governance Policy
The configPath and configPrefix in the following example use default values, the service name is
ServiceName
and the client name isClientName
.
Rate Limit
Category=limit
Currently, current limiting only supports the server side, so ClientServiceName is empty.
Variable | Introduction |
---|---|
connection_limit | Maximum concurrent connections |
qps_limit | Maximum request number every 100ms |
Example:
configPath: /KitexConfig/ServiceName/limit
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
Variable | Introduction |
---|---|
type | 0: failure_policy 1: backup_policy |
failure_policy.backoff_policy | Can only be set one of fixed none random |
Example:
configPath: /KitexConfig/ClientName/ServiceName/retry
Note: retry.Container has built-in support for specifying the default configuration using the *
wildcard (see the getRetryer method for details).
RPC Timeout
Category=rpc_timeout
Example:
configPath: /KitexConfig/ClientName/ServiceName/rpc_timeout
Note: The circuit breaker implementation of kitex does not currently support changing the global default configuration (see initServiceCB for details).
Circuit Break
Category=circuit_break
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: /KitexConfig/ClientName/ServiceName/circuit_break
Degradation
Variable | Introduction |
---|---|
enable | Whether to enable degradation |
percentage | The percentage of dropped requests |
Example:
configPath: /KitexConfig/ClientName/ServiceName/degradation
Note: Degradation is not enabled by default.
Compatibility
For grpc compatibility, the version of Go must >=1.19