const maxRetryAfter … type DroppedRequestsTracker … type unixStat … type droppedRequestsStats … func newDroppedRequestsStats(nowUnix int64) *droppedRequestsStats { … } func (s *droppedRequestsStats) recordDroppedRequest(unixTime int64) { … } func (s *droppedRequestsStats) updateHistory(unixTime int64, count int64) { … } // updateRetryAfterIfNeededLocked updates the retryAfter based on the number of // dropped requests in the last `retryAfter` seconds: // - if there were less than `retryAfter` dropped requests, it decreases // retryAfter // - if there were at least 3*`retryAfter` dropped requests, it increases // retryAfter // // The rationale behind these numbers being fairly low is that APF is queuing // requests and rejecting (dropping) them is a last resort, which is not expected // unless a given priority level is actually overloaded. // // Additionally, we rate-limit the increases of retryAfter to wait at least // `retryAfter' seconds after the previous increase to avoid multiple bumps // on a single spike. // // We're working with the interval [unixTime-retryAfter, unixTime). func (s *droppedRequestsStats) updateRetryAfterIfNeededLocked(unixTime int64) { … } type droppedRequestsTracker … // NewDroppedRequestsTracker is creating a new instance of // DroppedRequestsTracker. func NewDroppedRequestsTracker() DroppedRequestsTracker { … } func newDroppedRequestsTracker(now func() time.Time) *droppedRequestsTracker { … } func (t *droppedRequestsTracker) RecordDroppedRequest(plName string) { … } func (t *droppedRequestsTracker) GetRetryAfter(plName string) int64 { … }