Skip to content

Commit

Permalink
fix: mod to github.com/kitex-contrib/config-consul (#2)
Browse files Browse the repository at this point in the history
* fix: mod to github.com/kitex-contrib/config-consul

Signed-off-by: rogerogers <[email protected]>

* chore: upgrade action version

Signed-off-by: rogerogers <[email protected]>

* chore: quote golang version 1.20

Signed-off-by: rogerogers <[email protected]>

---------

Signed-off-by: rogerogers <[email protected]>
  • Loading branch information
rogerogers committed Feb 29, 2024
1 parent 7841251 commit 5bff48d
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 163 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Pull Request Check

on: [ pull_request ]
on: [pull_request]

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

Expand All @@ -17,13 +17,13 @@ jobs:
uses: crate-ci/typos@master

staticcheck:
runs-on: [ self-hosted, X64 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version: "1.20"

- uses: actions/cache@v3
with:
Expand All @@ -45,16 +45,17 @@ jobs:
staticcheck_flags: -checks=inherit,-SA1029

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

go-version: "1.20"
- name: Golangci Lint
# https://golangci-lint.run/
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout 30m -E gofumpt --go 1.20
skip-pkg-cache: true
23 changes: 11 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
name: Tests

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

jobs:
unit-benchmark-test:
strategy:
matrix:
go: [ 1.19 ]
os: [ X64, ARM64 ]
runs-on: ${{ matrix.os }}
go: ["1.20"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

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

# 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-
# 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 ./...
Expand Down
126 changes: 69 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# config-consul
# config-consul

[中文](./README_CN.md)

etcd as config center for service governance.
consul as config center for service governance.

## Install

`go get github.com/kitex-contrib/config-consul`

## Usage

Expand All @@ -14,11 +19,11 @@ etcd as config center for service governance.
package main

import (
"config-consul/consul"
"github.com/kitex-contrib/config-consul/consul"
"context"
"log"

consulserver "config-consul/server"
consulserver "github.com/kitex-contrib/config-consul/server"

"github.com/cloudwego/kitex-examples/kitex_gen/api"
"github.com/cloudwego/kitex-examples/kitex_gen/api/echo"
Expand All @@ -41,11 +46,11 @@ func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Respon
func main() {
klog.SetLevel(klog.LevelDebug)
serviceName := "ServiceName" // your server-side service name
etcdClient, _ := consul.NewClient(consul.Options{})
consulClient, _ := consul.NewClient(consul.Options{})
svr := echo.NewServer(
new(EchoImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}),
server.WithSuite(consulserver.NewSuite(serviceName, etcdClient)),
server.WithSuite(consulserver.NewSuite(serviceName, consulClient)),
)
if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
Expand All @@ -56,20 +61,21 @@ func main() {


```

#### Client

```go

package main

import (
"config-consul/consul"
"config-consul/utils"
"github.com/kitex-contrib/config-consul/consul"
"github.com/kitex-contrib/config-consul/utils"
"context"
"log"
"time"

consulclient "config-consul/client"
consulclient "github.com/kitex-contrib/config-consul/client"

"github.com/cloudwego/kitex-examples/kitex_gen/api"
"github.com/cloudwego/kitex-examples/kitex_gen/api/echo"
Expand Down Expand Up @@ -118,11 +124,13 @@ func main() {
}

```

### Consul Configuration

#### CustomFunction

Provide the mechanism to custom the etcd parameter `Key`.
Provide the mechanism to custom the consul parameter `Key`.

```go
type Key struct {
Type ConfigType
Expand All @@ -131,35 +139,36 @@ Path string
}
```


#### Options Variable

| Variable Name | Default Value |
|------------------|-------------------------------------------------------------|
| ---------------- | ----------------------------------------------------------- |
| Addr | 127.0.0.1:8500 |
| Prefix | /KitexConfig |
| ServerPathFormat | {{.ServerServiceName}}/{{.Category}} |
| ClientPathFormat | {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} |
| DataCenter | dc1 |
| Timeout | 5 * time.Second |
| Timeout | 5 \* time.Second |
| NamespaceId | |
| Token | |
| Partition | |
| LoggerConfig | NULL |
| ConfigParser | defaultConfigParser |

#### 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 |
| ---------------- | ---------------------------------- |
| connection_limit | Maximum concurrent connections |
| qps_limit | Maximum request number every 100ms |

Example:

Expand All @@ -179,56 +188,58 @@ Note:
- 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` |
| ----------------------------- | ---------------------------------------------- |
| 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
```json
{
"*": {
"enable": true,
"type": 0,
"failure_policy": {
"stop_policy": {
"max_retry_times": 3,
"max_duration_ms": 2000,
"cb_policy": {
"error_rate": 0.3
}
},
"backoff_policy": {
"backoff_type": "fixed",
"cfg_items": {
"fix_ms": 50
}
},
"retry_same_node": false
"*": {
"enable": true,
"type": 0,
"failure_policy": {
"stop_policy": {
"max_retry_times": 3,
"max_duration_ms": 2000,
"cb_policy": {
"error_rate": 0.3
}
},
"backoff_policy": {
"backoff_type": "fixed",
"cfg_items": {
"fix_ms": 50
}
},
"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_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
Expand All @@ -251,15 +262,16 @@ Example:
}
}
```

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 |
| ---------- | --------------------------------- |
| min_sample | Minimum statistical sample number |

Example:

Expand All @@ -271,18 +283,18 @@ The echo method uses the following configuration (0.3, 100) and other methods us
{
"echo": {
"enable": true,
"err_rate": 0.3,
"min_sample": 100
"err_rate": 0.3,
"min_sample": 100
}
}
```

### More Info

Refer to [example](https://github.com/kitex-contrib/config-consul/tree/main/example) for more usage.

## Compatibility

the version of Go must >=1.19
the version of Go must >=1.20

maintained by: [hiahia12](https://github.com/hiahia12)

Loading

0 comments on commit 5bff48d

Please sign in to comment.