app

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bit      Bitrate = 1
	Kilobit          = 1000 * Bit
	Megabit          = 1000 * Kilobit
	Gigabit          = 1000 * Megabit
	Terabit          = 1000 * Gigabit
	Petabit          = 1000 * Terabit
	Byte             = 8 * Bit
	Kilobyte         = 1000 * Byte
	Megabyte         = 1000 * Kilobyte
	Gigabyte         = 1000 * Megabyte
	Terabyte         = 1000 * Gigabyte
	Petabyte         = 1000 * Terabyte
)
View Source
const MaxByteCount = math.MaxInt64 / bitsPerByte

MaxByteCount is the largest byte count that has an exact bit count.

Variables

View Source
var (
	ErrNotRegistered = errors.New("debuglet has not been registered")
	ErrNotInPolicy   = errors.New("address has not been registered/not in policy")
)

Functions

This section is empty.

Types

type Bitrate

type Bitrate int64

Bitrate in bits/s.

Can also be used to generally indicate size.

func FromBytes

func FromBytes(b int) Bitrate

FromBytes converts a byte count into bits. A count beyond MaxByteCount in either direction has no exact bit count and saturates, rather than wrapping into a bitrate of the opposite sign.

func Parse

func Parse(s string) (Bitrate, error)

func (Bitrate) Bytes

func (b Bitrate) Bytes() int

Bytes is the buffer size that holds b bits, rounded up to a whole byte. It is a size, so it is defined for a non-negative bitrate: a negative one is a debt, has no buffer size and reports zero. Use Bitrate.SignedBytes to convert a signed token balance.

func (Bitrate) SignedBytes

func (b Bitrate) SignedBytes() int

SignedBytes converts a signed bit count into whole bytes, rounding towards negative infinity. Applied to a token balance it reports only bytes that are fully covered and never erases part of a debt: -8 bits is one byte owed and -1 bit is still one byte owed, where rounding towards zero reports none of either and grants the next reservation early. It is exact for every int64.

func (Bitrate) String

func (b Bitrate) String() string

type Limit

type Limit struct {
	Executor Bitrate
	Address  Bitrate
	Updated  bool
}

type Limiter

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

Limiter keeps track of the bandwidth being used by individual debuglets as well as the maximum bandwidth any debuglet is allowed to use on a executor level as well as per destination.

func NewLimiter

func NewLimiter(l *zap.Logger) *Limiter

func (*Limiter) ExecutorCapacity

func (l *Limiter) ExecutorCapacity() Bitrate

func (*Limiter) GetAddrLimit

func (l *Limiter) GetAddrLimit(ID uuid.UUID, addr string) (Bitrate, bool, error)

func (*Limiter) GetExecLimit

func (l *Limiter) GetExecLimit(ID uuid.UUID) (Bitrate, bool, error)

func (*Limiter) GetLimit

func (l *Limiter) GetLimit(ID uuid.UUID, addr string) (Limit, error)

func (*Limiter) InsertDebuglet

func (l *Limiter) InsertDebuglet(ID uuid.UUID, minimum, maximum Bitrate, addrs []string) error

func (*Limiter) RemoveDebuglet

func (l *Limiter) RemoveDebuglet(ID uuid.UUID)

func (*Limiter) SetAddrCapacity

func (l *Limiter) SetAddrCapacity(addr string, c Bitrate)

func (*Limiter) SetExecutorCapacity

func (l *Limiter) SetExecutorCapacity(c Bitrate)

func (*Limiter) Wait

func (l *Limiter) Wait(ctx context.Context, direction TransferDirection, ID uuid.UUID, addr string, size Bitrate) error

type TransferDirection

type TransferDirection = int
const (
	TransferIn TransferDirection = iota
	TransferOut
)

type UsageLimits

type UsageLimits struct {
	ExecutorRatelimit    Bitrate
	ExecutorBurst        Bitrate
	DestinationRatelimit Bitrate
	DestinationBurst     Bitrate
}

type UsageTracker

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

UsageTracker tracks the amount of bandwidth that is being used by an individual debuglet. The idea is to set the executor and destination specific limit that is allowed by the debuglet and then UsageTracker.Wait will block the caller for the amount of time to ratelimit the bandwidth usage.

func NewUsageTracker

func NewUsageTracker(l *zap.Logger) *UsageTracker

func (*UsageTracker) Upsert

func (u *UsageTracker) Upsert(destination string, limits UsageLimits)

func (*UsageTracker) Wait

func (u *UsageTracker) Wait(ctx context.Context, dir TransferDirection, destination string, size Bitrate) error

Wait uses a token bucket to sleep until either the context finishes or a packet of a given size has enough space

Jump to

Keyboard shortcuts

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