Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comments and do a little modification #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions hystrix/hystrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type command struct {
ticket *struct{}
start time.Time
errChan chan error
finished chan bool
finished chan struct{}
fallbackOnce *sync.Once
circuit *CircuitBreaker
run runFunc
Expand Down Expand Up @@ -58,11 +58,11 @@ func Go(name string, run runFunc, fallback fallbackFunc) chan error {
fallback: fallback,
start: time.Now(),
errChan: make(chan error, 1),
finished: make(chan bool, 1),
finished: make(chan struct{}, 1),
fallbackOnce: &sync.Once{},
}

// dont have methods with explicit params and returns
// don't have methods with explicit params and returns
// let data come in and out naturally, like with any closure
// explicit error return to give place for us to kill switch the operation (fallback)

Expand All @@ -74,11 +74,11 @@ func Go(name string, run runFunc, fallback fallbackFunc) chan error {
cmd.circuit = circuit

go func() {
defer func() { cmd.finished <- true }()
defer func() { cmd.finished <- struct{}{} }()

// Circuits get opened when recent executions have shown to have a high error rate.
// Rejecting new executions allows backends to recover, and the circuit will allow
// new traffic when it feels a healthly state has returned.
// new traffic when it feels a healthy state has returned.
if !cmd.circuit.AllowRequest() {
cmd.errorWithFallback(ErrCircuitOpen)
return
Expand Down
2 changes: 1 addition & 1 deletion hystrix/metric_collector/metric_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (m *metricCollectorRegistry) Register(initMetricCollector func(string) Metr
}

// MetricCollector represents the contract that all collectors must fulfill to gather circuit statistics.
// Implementations of this interface do not have to maintain locking around thier data stores so long as
// Implementations of this interface do not have to maintain locking around their data stores so long as
// they are not modified outside of the hystrix context.
type MetricCollector interface {
// IncrementAttempts increments the number of updates.
Expand Down
12 changes: 7 additions & 5 deletions hystrix/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ type CommandConfig struct {
ErrorPercentThreshold int `json:"error_percent_threshold"`
}

var circuitSettings map[string]*Settings
var settingsMutex *sync.RWMutex
var (
circuitSettings map[string]*Settings
settingsMutex *sync.RWMutex
)

func init() {
circuitSettings = make(map[string]*Settings)
Expand All @@ -52,9 +54,6 @@ func Configure(cmds map[string]CommandConfig) {

// ConfigureCommand applies settings for a circuit
func ConfigureCommand(name string, config CommandConfig) {
settingsMutex.Lock()
defer settingsMutex.Unlock()

timeout := DefaultTimeout
if config.Timeout != 0 {
timeout = config.Timeout
Expand All @@ -80,6 +79,9 @@ func ConfigureCommand(name string, config CommandConfig) {
errorPercent = config.ErrorPercentThreshold
}

settingsMutex.Lock()
defer settingsMutex.Unlock()

circuitSettings[name] = &Settings{
Timeout: time.Duration(timeout) * time.Millisecond,
MaxConcurrentRequests: max,
Expand Down