data

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataError

type DataError struct {
	*utils.BaseError
}

DataError represents an error related to the underlying data structure used by the tracker.

func NewDataError

func NewDataError(wrapped error, msg string, args ...any) *DataError

NewDataError wraps the given error with additional context for data layer issues.

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) GetID

func (s *Structure) GetID() uint64

GetID returns the identifier of this data 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL