Esempio n. 1
0
func (c *CircuitBreaker) checkCondition(r request.Request) bool {
	if !c.timeToCheck() {
		return false
	}

	c.m.Lock()
	defer c.m.Unlock()

	// Other goroutine could have updated the lastCheck variable before we grabbed mutex
	if !c.tm.UtcNow().After(c.lastCheck) {
		return false
	}
	c.lastCheck = c.tm.UtcNow().Add(c.checkPeriod)
	// Each requests holds a context attached to it, we use it to attach the metrics to the request
	// so condition checker function can use it for analysis on the next line.
	r.SetUserData(cbreakerMetrics, c.metrics)
	return c.condition(r)
}
Esempio n. 2
0
func (c *CircuitBreaker) markToRecordMetrics(r request.Request) {
	r.SetUserData(cbreakerRecordMetrics, true)
}