forked from go-chassis/go-chassis
/
panel.go
executable file
·78 lines (63 loc) · 2.23 KB
/
panel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package archaius
import (
"github.com/go-chassis/go-chassis/control"
"github.com/go-chassis/go-chassis/core/archaius"
"github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/config/model"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/core/qpslimiter"
"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
"strings"
)
//Panel pull configs from archaius
type Panel struct {
}
func newPanel(options control.Options) control.Panel {
SaveToLBCache(config.GetLoadBalancing())
SaveToCBCache(config.GetHystrixConfig())
return &Panel{}
}
//GetCircuitBreaker return command , and circuit breaker settings
func (p *Panel) GetCircuitBreaker(inv invocation.Invocation, serviceType string) (string, hystrix.CommandConfig) {
key := GetCBCacheKey(inv.MicroServiceName, serviceType)
command := serviceType
if inv.MicroServiceName != "" {
command = strings.Join([]string{serviceType, inv.MicroServiceName}, ".")
}
c, ok := CBConfigCache.Get(key)
if !ok {
c, _ := CBConfigCache.Get(serviceType)
return command, c.(hystrix.CommandConfig)
}
return command, c.(hystrix.CommandConfig)
}
//GetLoadBalancing get load balancing config
func (p *Panel) GetLoadBalancing(inv invocation.Invocation) control.LoadBalancingConfig {
c, ok := LBConfigCache.Get(inv.MicroServiceName)
if !ok {
c, ok := LBConfigCache.Get("")
if !ok {
return DefaultLB
}
return c.(control.LoadBalancingConfig)
}
return c.(control.LoadBalancingConfig)
}
//GetRateLimiting get rate limiting config
func (p *Panel) GetRateLimiting(inv invocation.Invocation, serviceType string) control.RateLimitingConfig {
rl := control.RateLimitingConfig{}
rl.Enabled = archaius.GetBool("cse.flowcontrol."+serviceType+".qps.enabled", true)
operationMeta := qpslimiter.InitSchemaOperations(&inv)
rl.Rate, rl.Key = qpslimiter.GetQPSTrafficLimiter().GetQPSRateWithPriority(operationMeta)
return rl
}
//GetFaultInjection get Fault injection config
func (p *Panel) GetFaultInjection(inv invocation.Invocation) model.Fault {
return model.Fault{}
}
//GetEgressRule get egress config
func (p *Panel) GetEgressRule(inv invocation.Invocation) {
}
func init() {
control.InstallPlugin("archaius", newPanel)
}