tracker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FairnessTracker

type FairnessTracker struct {
	// contains filtered or unexported fields
}

FairnessTracker is the main entry point for applications. It keeps track of client flows and determines when a request should be throttled to maintain fairness.

func NewFairnessTracker

func NewFairnessTracker(trackerConfig *config.FairnessTrackerConfig) (*FairnessTracker, error)

NewFairnessTracker creates a FairnessTracker using the real system clock and ticker.

func NewFairnessTrackerWithClockAndTicker

func NewFairnessTrackerWithClockAndTicker(trackerConfig *config.FairnessTrackerConfig, clock utils.IClock, ticker utils.ITicker) (*FairnessTracker, error)

NewFairnessTrackerWithClockAndTicker creates a FairnessTracker using the provided clock and ticker. It is primarily used for tests and simulations where time needs to be controlled.

func (*FairnessTracker) Close

func (ft *FairnessTracker) Close()

Close stops the background rotation goroutine and releases ticker resources.

func (*FairnessTracker) RegisterRequest

func (ft *FairnessTracker) RegisterRequest(ctx context.Context, clientIdentifier []byte) *request.RegisterRequestResult

RegisterRequest records an incoming request and returns whether it should be throttled.

func (*FairnessTracker) ReportOutcome

func (ft *FairnessTracker) ReportOutcome(ctx context.Context, clientIdentifier []byte, outcome request.Outcome) *request.ReportOutcomeResult

ReportOutcome updates the trackers with the outcome of the request from the given client identifier.

type FairnessTrackerBuilder

type FairnessTrackerBuilder struct {
	// contains filtered or unexported fields
}

FairnessTrackerBuilder helps configure and construct a FairnessTracker.

func NewFairnessTrackerBuilder

func NewFairnessTrackerBuilder() *FairnessTrackerBuilder

NewFairnessTrackerBuilder returns a new builder pre-populated with the default configuration.

func (*FairnessTrackerBuilder) Build

Build constructs a tracker using the configuration accumulated on the builder.

func (*FairnessTrackerBuilder) BuildWithConfig

func (bl *FairnessTrackerBuilder) BuildWithConfig(configuration *config.FairnessTrackerConfig) (*FairnessTracker, error)

BuildWithConfig builds a tracker using the supplied configuration.

func (*FairnessTrackerBuilder) BuildWithDefaultConfig

func (bl *FairnessTrackerBuilder) BuildWithDefaultConfig() (*FairnessTracker, error)

BuildWithDefaultConfig builds a tracker using DefaultFairnessTrackerConfig.

func (*FairnessTrackerBuilder) SetFinalProbabilityFunction

func (bl *FairnessTrackerBuilder) SetFinalProbabilityFunction(finalProbabilityFunction config.FinalProbabilityFunction)

SetFinalProbabilityFunction sets the function used to derive the final throttling probability from all buckets.

func (*FairnessTrackerBuilder) SetIncludeStats

func (bl *FairnessTrackerBuilder) SetIncludeStats(IncludeStats bool)

SetIncludeStats indicates whether the tracker should return detailed stats.

func (*FairnessTrackerBuilder) SetL

func (bl *FairnessTrackerBuilder) SetL(L uint32)

SetL sets the number of levels used by the tracker.

func (*FairnessTrackerBuilder) SetLambda

func (bl *FairnessTrackerBuilder) SetLambda(Lambda float64)

SetLambda sets the decay rate for bucket probabilities.

func (*FairnessTrackerBuilder) SetM

func (bl *FairnessTrackerBuilder) SetM(M uint32)

SetM sets the number of buckets per level.

func (*FairnessTrackerBuilder) SetPd

func (bl *FairnessTrackerBuilder) SetPd(Pd float64)

SetPd sets the decrement probability used on successful requests.

func (*FairnessTrackerBuilder) SetPi

func (bl *FairnessTrackerBuilder) SetPi(Pi float64)

SetPi sets the increment probability used on failed requests.

func (*FairnessTrackerBuilder) SetRotationFrequency

func (bl *FairnessTrackerBuilder) SetRotationFrequency(rotationFrequency time.Duration)

SetRotationFrequency configures how often the internal structures are rotated.

type FairnessTrackerError

type FairnessTrackerError struct {
	*utils.BaseError
}

FairnessTrackerError is returned when the tracker encounters a recoverable error that should be surfaced to the caller.

func NewFairnessTrackerError

func NewFairnessTrackerError(wrapped error, msg string, args ...any) *FairnessTrackerError

NewFairnessTrackerError creates a new FairnessTrackerError that wraps another error with additional context.

Jump to

Keyboard shortcuts

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