-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandproperties.go
71 lines (62 loc) · 4 KB
/
commandproperties.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
package cuirass
import (
"time"
"github.com/arjantop/cuirass/circuitbreaker"
"github.com/arjantop/vaquita"
)
type CommandProperties struct {
ExecutionTimeout vaquita.DurationProperty
ExecutionMaxConcurrentRequests vaquita.IntProperty
FallbackEnabled vaquita.BoolProperty
RequestCacheEnabled vaquita.BoolProperty
RequestLogEnabled vaquita.BoolProperty
CircuitBreaker *circuitbreaker.CircuitBreakerProperties
}
const (
ExecutionTimeoutDefault = 0
ExecutionMaxConcurrentRequestsDefault = 100
FallbackEnabledDefault = true
RequestCacheEnabledDefault = true
RequestLogEnabledDefault = true
CircuitBreakerEnabledDefault = true
CircuitBreakerRequestVolumeThresholdDefault = 20
CircuitBreakerSleepWindowDefault = 5000 * time.Millisecond
CircuitBreakerErrorThresholdPercentageDefault = 50
CircuitBreakerForceOpenDefault = false
CircuitBreakerForceClosedDefault = false
)
func newCommandProperties(cfg vaquita.DynamicConfig, commandName, commandGroup string) *CommandProperties {
pf := vaquita.NewPropertyFactory(cfg)
propertyPrefix := pf.GetStringProperty("cuirass.config.prefix", "cuirass").Get()
return &CommandProperties{
ExecutionTimeout: newDurationProperty(pf, propertyPrefix+".command", commandName, "execution.isolation.thread.timeoutInMilliseconds", ExecutionTimeoutDefault),
ExecutionMaxConcurrentRequests: newIntProperty(pf, propertyPrefix+".command", commandGroup, "execution.isolation.semaphore.maxConcurrentRequests", ExecutionMaxConcurrentRequestsDefault),
FallbackEnabled: newBoolProperty(pf, propertyPrefix+".command", commandName, "fallback.enabled", FallbackEnabledDefault),
RequestCacheEnabled: newBoolProperty(pf, propertyPrefix+".command", commandName, "requestCache.enabled", RequestCacheEnabledDefault),
RequestLogEnabled: newBoolProperty(pf, propertyPrefix+".command", commandName, "requestLog.enabled", RequestLogEnabledDefault),
CircuitBreaker: &circuitbreaker.CircuitBreakerProperties{
Enabled: newBoolProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.enabled", CircuitBreakerEnabledDefault),
RequestVolumeThreshold: newIntProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.requestVolumeThreshold", CircuitBreakerRequestVolumeThresholdDefault),
SleepWindow: newDurationProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.sleepWindowInMilliseconds", CircuitBreakerSleepWindowDefault),
ErrorThresholdPercentage: newIntProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.errorThresholdPercentage", CircuitBreakerErrorThresholdPercentageDefault),
ForceOpen: newBoolProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.forceOpen", CircuitBreakerForceOpenDefault),
ForceClosed: newBoolProperty(pf, propertyPrefix+".command", commandName, "circuitbreaker.forceClosed", CircuitBreakerForceClosedDefault),
},
}
}
func newBoolProperty(f *vaquita.PropertyFactory, prefix, commandName, propertyName string, defaultValue bool) vaquita.BoolProperty {
return vaquita.NewChainedBoolProperty(f,
prefix+"."+commandName+"."+propertyName,
f.GetBoolProperty(prefix+".default."+propertyName, defaultValue))
}
func newIntProperty(f *vaquita.PropertyFactory, prefix, commandName, propertyName string, defaultValue int) vaquita.IntProperty {
return vaquita.NewChainedIntProperty(f,
prefix+"."+commandName+"."+propertyName,
f.GetIntProperty(prefix+".default."+propertyName, defaultValue))
}
func newDurationProperty(f *vaquita.PropertyFactory, prefix, commandName, propertyName string, defaultValue time.Duration) vaquita.DurationProperty {
return vaquita.NewChainedDurationProperty(f,
prefix+"."+commandName+"."+propertyName,
time.Millisecond,
f.GetDurationProperty(prefix+".default."+propertyName, defaultValue, time.Millisecond))
}