Documentation
¶
Index ¶
- type DataError
- type Structure
- func (s *Structure) Close()
- func (s *Structure) GetID() uint64
- func (s *Structure) PenaltyOccupancy(threshold float64) (penalizedByLevel []int, meanProbability float64)
- func (s *Structure) RegisterRequest(_ context.Context, clientIdentifier []byte) *request.RegisterRequestResult
- func (s *Structure) ReportOutcome(_ context.Context, clientIdentifier []byte, outcome request.Outcome) *request.ReportOutcomeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataError ¶
DataError represents an error related to the underlying data structure used by the tracker.
type Structure ¶
type Structure struct {
// contains filtered or unexported fields
}
Structure implements the Tracker interface using a multi-level Bloom filter style bucket layout. Each bucket tracks the probability that a request should be throttled based on the observed successes and failures for the hashed client identifier.
func NewStructure ¶
func NewStructure(config *config.FairnessTrackerConfig, id uint64) (*Structure, error)
NewStructure creates a Structure using the real system clock.
func NewStructureWithClock ¶
func NewStructureWithClock(input *config.FairnessTrackerConfig, id uint64, clock utils.IClock) (*Structure, error)
NewStructureWithClock creates a Structure using the provided clock. This is primarily used in tests and simulations where time needs to be controlled. Per-request stats are included when the config's IncludeStats is set.
func (*Structure) Close ¶
func (s *Structure) Close()
Close releases any resources associated with the Structure.
func (*Structure) PenaltyOccupancy ¶
func (s *Structure) PenaltyOccupancy(threshold float64) (penalizedByLevel []int, meanProbability float64)
PenaltyOccupancy reports how much of the structure is carrying penalties. For each level it counts the buckets whose probability, after decay, is at least threshold, and it returns the mean probability across all buckets. It reads every bucket without changing any, so its cost grows with L×M: call it from a metrics scrape, not per request.
func (*Structure) RegisterRequest ¶
func (s *Structure) RegisterRequest(_ context.Context, clientIdentifier []byte) *request.RegisterRequestResult
RegisterRequest records an incoming request from the client and returns the throttling decision based on current probabilities.
func (*Structure) ReportOutcome ¶
func (s *Structure) ReportOutcome(_ context.Context, clientIdentifier []byte, outcome request.Outcome) *request.ReportOutcomeResult
ReportOutcome updates the probabilities for the buckets associated with the given client identifier based on the observed outcome. An outcome other than OutcomeSuccess or OutcomeFailure is ignored.