@@ -77,27 +77,29 @@ func (l *Limiter) HeadSeriesLimiter() headSeriesLimiter {
7777 return l .headSeriesLimiter
7878}
7979
80- func (l * Limiter ) ShouldRejectNewRequest () bool {
80+ func (l * Limiter ) ShouldRejectNewRequest () ( bool , string ) {
8181 // maxPendingRequests doesn't change once set when a limiter instance is created.
8282 // So, it's safe to read it without a lock.
83- if l .maxPendingRequests > 0 && l .pendingRequests .Load () >= l .maxPendingRequests {
84- if l .maxPendingRequestLimitHit != nil {
85- l .maxPendingRequestLimitHit .Inc ()
83+ if l .maxPendingRequests > 0 {
84+ if pendingRequests := l .pendingRequests .Load (); pendingRequests >= l .maxPendingRequests {
85+ if l .maxPendingRequestLimitHit != nil {
86+ l .maxPendingRequestLimitHit .Inc ()
87+ }
88+ if l .pendingRequestsGauge != nil {
89+ l .pendingRequestsGauge .Set (float64 (pendingRequests ))
90+ }
91+ return true , fmt .Sprintf ("too many pending write requests: %d >= %d" , l .pendingRequests .Load (), l .maxPendingRequests )
8692 }
87- return true
8893 }
8994 newValue := l .pendingRequests .Add (1 )
9095 if l .pendingRequestsGauge != nil {
9196 l .pendingRequestsGauge .Set (float64 (newValue ))
9297 }
93- return false
98+ return false , ""
9499}
95100
96101func (l * Limiter ) DecrementPendingRequests () {
97- newValue := l .pendingRequests .Add (- 1 )
98- if l .pendingRequestsGauge != nil {
99- l .pendingRequestsGauge .Set (float64 (newValue ))
100- }
102+ l .pendingRequests .Add (- 1 )
101103}
102104
103105// NewLimiter creates a new *Limiter given a configuration and prometheus
0 commit comments