예제 #1
0
파일: failrate.go 프로젝트: FoxComm/vulcan
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()
	}
}
예제 #2
0
파일: cbreaker.go 프로젝트: FoxComm/vulcan
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())
	}
}
예제 #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)
}
예제 #4
0
파일: roundtrip.go 프로젝트: FoxComm/vulcan
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
}
예제 #5
0
파일: roundtrip.go 프로젝트: FoxComm/vulcan
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)
	}
}
예제 #6
0
파일: failrate.go 프로젝트: FoxComm/vulcan
func IsNetworkError(attempt request.Attempt) bool {
	return attempt != nil && attempt.GetError() != nil
}