mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-24 03:46:37 +02:00
rm breaker config sleep & ratio
This commit is contained in:
parent
c175bc7c9f
commit
5d99a2e79a
@ -38,11 +38,6 @@
|
||||
```go
|
||||
type Config struct {
|
||||
SwitchOff bool // 熔断器开关,默认关 false.
|
||||
|
||||
//目前熔断器只实现了 sreBreaker 所以以下2个参数暂时没用到
|
||||
Ratio float32
|
||||
Sleep xtime.Duration
|
||||
|
||||
|
||||
K float64 //触发熔断的错误率(K = 1 - 1/错误率)
|
||||
|
||||
|
@ -3,8 +3,8 @@ package auth_test
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
bm "github.com/bilibili/kratos/pkg/net/http/blademaster"
|
||||
"github.com/bilibili/kratos/example/blademaster/middleware/auth"
|
||||
bm "github.com/bilibili/kratos/pkg/net/http/blademaster"
|
||||
"github.com/bilibili/kratos/pkg/net/metadata"
|
||||
)
|
||||
|
||||
|
@ -41,8 +41,8 @@ func codeFromErr(err error) string {
|
||||
code = "connot_find_region"
|
||||
case gohbase.TableNotFound:
|
||||
code = "table_not_found"
|
||||
//case gohbase.ErrRegionUnavailable:
|
||||
// code = "region_unavailable"
|
||||
//case gohbase.ErrRegionUnavailable:
|
||||
// code = "region_unavailable"
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ package etcd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
"github.com/bilibili/kratos/pkg/naming"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
"google.golang.org/grpc"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
|
@ -49,7 +49,6 @@ type Context struct {
|
||||
RoutePath string
|
||||
|
||||
Params Params
|
||||
|
||||
}
|
||||
|
||||
/************************************/
|
||||
@ -67,7 +66,6 @@ func (c *Context) Next() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Abort prevents pending handlers from being called. Note that this will not stop the current handler.
|
||||
// Let's say you have an authorization middleware that validates that the current request is authorized.
|
||||
// If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers
|
||||
|
@ -68,7 +68,7 @@ func InternalIP() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// isUp Interface is up
|
||||
// isUp Interface is up
|
||||
func isUp(v net.Flags) bool {
|
||||
return v&net.FlagUp == net.FlagUp
|
||||
return v&net.FlagUp == net.FlagUp
|
||||
}
|
||||
|
@ -11,10 +11,9 @@
|
||||
> 4. 默认配置如下所示:
|
||||
_conf = &Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(100 * time.Millisecond),
|
||||
Bucket: 10,
|
||||
Ratio: 0.5,
|
||||
Request: 100,
|
||||
K:1.5,
|
||||
}
|
||||
|
||||
##### 测试
|
||||
|
@ -11,10 +11,6 @@ import (
|
||||
type Config struct {
|
||||
SwitchOff bool // breaker switch,default off.
|
||||
|
||||
// Hystrix
|
||||
Ratio float32
|
||||
Sleep xtime.Duration
|
||||
|
||||
// Google
|
||||
K float64
|
||||
|
||||
@ -30,12 +26,6 @@ func (conf *Config) fix() {
|
||||
if conf.Request == 0 {
|
||||
conf.Request = 100
|
||||
}
|
||||
if conf.Ratio == 0 {
|
||||
conf.Ratio = 0.5
|
||||
}
|
||||
if conf.Sleep == 0 {
|
||||
conf.Sleep = xtime.Duration(500 * time.Millisecond)
|
||||
}
|
||||
if conf.Bucket == 0 {
|
||||
conf.Bucket = 10
|
||||
}
|
||||
@ -84,8 +74,6 @@ var (
|
||||
Bucket: 10,
|
||||
Request: 100,
|
||||
|
||||
Sleep: xtime.Duration(500 * time.Millisecond),
|
||||
Ratio: 0.5,
|
||||
// Percentage of failures must be lower than 33.33%
|
||||
K: 1.5,
|
||||
|
||||
|
@ -28,9 +28,7 @@ func TestGroup(t *testing.T) {
|
||||
g := NewGroup(_conf)
|
||||
c := &Config{
|
||||
Window: xtime.Duration(1 * time.Second),
|
||||
Sleep: xtime.Duration(100 * time.Millisecond),
|
||||
Bucket: 10,
|
||||
Ratio: 0.5,
|
||||
Request: 100,
|
||||
SwitchOff: !_conf.SwitchOff,
|
||||
}
|
||||
@ -44,9 +42,7 @@ func TestInit(t *testing.T) {
|
||||
switchOff := _conf.SwitchOff
|
||||
c := &Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(100 * time.Millisecond),
|
||||
Bucket: 10,
|
||||
Ratio: 0.5,
|
||||
Request: 100,
|
||||
SwitchOff: !switchOff,
|
||||
}
|
||||
@ -69,9 +65,7 @@ func TestGo(t *testing.T) {
|
||||
|
||||
_group.Reload(&Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(100 * time.Millisecond),
|
||||
Bucket: 10,
|
||||
Ratio: 0.5,
|
||||
Request: 100,
|
||||
SwitchOff: true,
|
||||
})
|
||||
|
@ -12,9 +12,8 @@ import (
|
||||
func ExampleGroup() {
|
||||
c := &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(100 * time.Millisecond),
|
||||
K: 1.5,
|
||||
Bucket: 10,
|
||||
Ratio: 0.5,
|
||||
Request: 100,
|
||||
}
|
||||
// init default config
|
||||
|
@ -60,9 +60,8 @@ func ExampleClient() {
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
K: 1.5,
|
||||
Request: 20,
|
||||
},
|
||||
})
|
||||
|
@ -39,10 +39,9 @@ func wardenCli() proto.HelloClient {
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
K: 1.5,
|
||||
},
|
||||
},
|
||||
grpc.WithInitialWindowSize(iws),
|
||||
|
@ -21,10 +21,9 @@ var (
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
K: 1.5,
|
||||
},
|
||||
}
|
||||
cli pb.GreeterClient
|
||||
|
@ -55,10 +55,9 @@ func createTestClient(t *testing.T, connStr string) pb.GreeterClient {
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
K: 1.5,
|
||||
},
|
||||
})
|
||||
conn, err := client.Dial(context.TODO(), connStr)
|
||||
|
@ -74,10 +74,9 @@ func createTestClient(t *testing.T) pb.GreeterClient {
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
K: 1.5,
|
||||
},
|
||||
})
|
||||
conn, err := client.Dial(context.TODO(), "mockdiscovery://authority/main.test")
|
||||
|
@ -41,11 +41,9 @@ var (
|
||||
Dial: xtime.Duration(time.Second * 10),
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
K: 1.5,
|
||||
},
|
||||
}
|
||||
clientConfig2 = ClientConfig{
|
||||
@ -53,10 +51,9 @@ var (
|
||||
Timeout: xtime.Duration(time.Second * 10),
|
||||
Breaker: &breaker.Config{
|
||||
Window: xtime.Duration(3 * time.Second),
|
||||
Sleep: xtime.Duration(3 * time.Second),
|
||||
Bucket: 10,
|
||||
Ratio: 0.3,
|
||||
Request: 20,
|
||||
K: 1.5,
|
||||
},
|
||||
Method: map[string]*ClientConfig{`/testproto.Greeter/SayHello`: {Timeout: xtime.Duration(time.Millisecond * 200)}},
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func TestZipkin(t *testing.T) {
|
||||
t2 := trace.NewTracer("service2", report, true)
|
||||
sp1 := t1.New("option_1")
|
||||
sp2 := sp1.Fork("service3", "opt_client")
|
||||
sp2.SetLog(trace.Log("log_k","log_v"))
|
||||
sp2.SetLog(trace.Log("log_k", "log_v"))
|
||||
// inject
|
||||
header := make(http.Header)
|
||||
t1.Inject(sp2, trace.HTTPFormat, header)
|
||||
|
@ -32,7 +32,7 @@ func init() {
|
||||
go cpuproc()
|
||||
}
|
||||
|
||||
// cpu = cpuᵗ⁻¹ * decay + cpuᵗ * (1 - decay)
|
||||
// cpu = cpuᵗ⁻¹ * decay + cpuᵗ * (1 - decay)
|
||||
func cpuproc() {
|
||||
ticker := time.NewTicker(time.Millisecond * 250)
|
||||
defer func() {
|
||||
|
@ -3,9 +3,9 @@ package gen
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"log"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||
@ -70,7 +70,6 @@ func writeResponse(w io.Writer, resp *plugin.CodeGeneratorResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fail log and exit
|
||||
func Fail(msgs ...string) {
|
||||
s := strings.Join(msgs, " ")
|
||||
@ -85,10 +84,9 @@ func Info(msgs ...string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
// Error log and exit
|
||||
func Error(err error, msgs ...string) {
|
||||
s := strings.Join(msgs, " ") + ":" + err.Error()
|
||||
log.Print("error:", s)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
@ -95,4 +94,4 @@ func AlphaDigitize(r rune) rune {
|
||||
// letters, numbers, and underscore.
|
||||
func CleanIdentifier(s string) string {
|
||||
return strings.Map(AlphaDigitize, s)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user