Ejemplo n.º 1
0
func (r *RollingMeter) ObserveResponse(req request.Request, lastAttempt request.Attempt) {
	if lastAttempt == nil || lastAttempt.GetEndpoint() != r.endpoint {
		return
	}

	if r.isError(lastAttempt) {
		r.errors.Inc()
	} else {
		r.successes.Inc()
	}
}
Ejemplo n.º 2
0
func (c *CircuitBreaker) ProcessResponse(r request.Request, a request.Attempt) {
	// We should not record metrics for the requests intercepted by circuit breaker
	// otherwise our metrics would be incorrect
	if c.shouldRecordMetrics(r) {
		c.metrics.RecordMetrics(a)
	}

	// Note that this call is less expensive than it looks -- checkCondition only performs the real check
	// periodically. Because of that we can afford to call it here on every single response.
	if c.checkCondition(r) {
		c.setTripped(a.GetEndpoint())
	}
}
Ejemplo n.º 3
0
func (rr *RoundRobin) ObserveResponse(req request.Request, a request.Attempt) {
	rr.mutex.Lock()
	defer rr.mutex.Unlock()

	if a == nil || a.GetEndpoint() == nil {
		return
	}
	we, _ := rr.findEndpointByUrl(a.GetEndpoint().GetUrl())
	if we == nil {
		return
	}

	// Update endpoint stats: failure count and request roundtrip
	we.meter.ObserveResponse(req, a)
}
Ejemplo n.º 4
0
func (m *RoundTripMetrics) recordStatusCode(a request.Attempt) {
	if a.GetResponse() == nil {
		return
	}
	statusCode := a.GetResponse().StatusCode
	if c, ok := m.statusCodes[statusCode]; ok {
		c.Inc()
		return
	}
	c, err := m.newCounter()
	if err != nil {
		log.Errorf("failed to create a counter: %v", err)
		return
	}
	c.Inc()
	m.statusCodes[statusCode] = c
}
Ejemplo n.º 5
0
func (m *RoundTripMetrics) recordLatency(a request.Attempt) {
	if err := m.histogram.RecordLatencies(a.GetDuration(), 1); err != nil {
		log.Errorf("Failed to record latency: %v", err)
	}
}
Ejemplo n.º 6
0
func IsNetworkError(attempt request.Attempt) bool {
	return attempt != nil && attempt.GetError() != nil
}