util

package
v0.0.0-...-fe78417 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: AGPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSyscallConn is reported when GetConnTCPInfo is passed a connection that doesn't satisfy the syscall.Conn interface.
	ErrNotSyscallConn = errors.New("conn doesn't satisfy syscall.Conn")
	// ErrTCPInfoUnsupported is reported if TCP information is not available for this platform.
	ErrTCPInfoUnsupported = errors.New("GetConnRTT not supported on this platform")
	// ErrNoTCPInfo is reported if getsockopt returned no TCP info for some reason.
	ErrNoTCPInfo = errors.New("getsockopt returned no TCP info")
)
View Source
var ErrWatchdogStreamReaderReaderReachedDataLimit = fmt.Errorf("watchdog stream reader reached data limit")

ErrWatchdogStreamReaderReaderReachedDataLimit is returned when watchdogStreamReader was asked to read beyond the designated data limits

View Source
var ErrWatchdogStreamReaderTimerElapsed = fmt.Errorf("watchdog stream reader timer elapsed")

ErrWatchdogStreamReaderTimerElapsed is returned when the watchdogStreamReader was not reset in the past readaheadDuration and read was attempted

Functions

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile uses io.Copy() to copy a file to another location This was copied from https://opensource.com/article/18/6/copying-files-go

func CopyFolder

func CopyFolder(source, dest string) error

CopyFolder recursively copies an entire directory to another location (ignoring symlinks)

func CopyFolderWithFilter

func CopyFolderWithFilter(source, dest string, includeFilter IncludeFilter) (err error)

CopyFolderWithFilter recursively copies an entire directory to another location (ignoring symlinks) with an optional filter function to include/exclude folders or files

func ExeDir

func ExeDir() (string, error)

ExeDir returns the absolute path to the current executing binary (not including the filename)

func ExecAndCaptureOutput

func ExecAndCaptureOutput(command string, args ...string) (string, string, error)

ExecAndCaptureOutput runs the specified command and args and captures stdout into a string, returning the string or an error upon completion.

func FileExists

func FileExists(filePath string) bool

FileExists checks to see if the specified file (or directory) exists

func FindProcess

func FindProcess(pid int) (*os.Process, error)

FindProcess looks for a running process by its pid

func GetCurrentProcessTimes

func GetCurrentProcessTimes() (utime int64, stime int64, err error)

GetCurrentProcessTimes gets current process kernel and usermode times

func GetFdLimits

func GetFdLimits() (soft uint64, hard uint64, err error)

GetFdLimits returns a current values for file descriptors limits.

func GetFirstLineFromFile

func GetFirstLineFromFile(netFile string) (string, error)

GetFirstLineFromFile retrieves the first line of the specified file.

func Getrusage

func Getrusage(who int, rusage *syscall.Rusage) (err error)

Getrusage gets file descriptors usage statistics

func IsDir

func IsDir(path string) bool

IsDir returns true if the specified directory is valid

func IsEmpty

func IsEmpty(path string) bool

IsEmpty recursively check path for files and returns true if there are none.

func KillProcess

func KillProcess(pid int, sig syscall.Signal) error

KillProcess kills a running OS process

func MoveFile

func MoveFile(src, dst string) error

MoveFile moves a file from src to dst. The advantages of using this over os.Rename() is that it can move files across different filesystems.

func NanoAfter

func NanoAfter(d time.Duration) <-chan time.Time

NanoAfter waits for the duration to elapse and then sends the current time on the returned channel.

func NanoSleep

func NanoSleep(d time.Duration)

NanoSleep sleeps for the given d duration.

func NewREDCongestionManager

func NewREDCongestionManager(d time.Duration, bsize int) *redCongestionManager

NewREDCongestionManager creates a Congestion Manager which will watches capacityGuard activity, and regularly calculates a Target Service Rate, and can give "Should Drop" suggestions

func RunFuncWithSpinningCursor

func RunFuncWithSpinningCursor(asyncFunc func())

RunFuncWithSpinningCursor runs a given function in a go-routine, while displaying a spinning cursor to the CLI

func SetFdSoftLimit

func SetFdSoftLimit(newLimit uint64) error

SetFdSoftLimit sets a new file descriptors soft limit.

Types

type CongestionManager

type CongestionManager interface {
	Start()
	Stop()
	Consumed(c ErlClient, t time.Time)
	Served(t time.Time)
	ShouldDrop(c ErlClient) bool
}

CongestionManager is an interface for tracking events which happen to capacityQueues

type ElasticRateLimiter

type ElasticRateLimiter struct {
	MaxCapacity            int
	CapacityPerReservation int
	// contains filtered or unexported fields
}

ElasticRateLimiter holds and distributes capacity through capacityQueues Capacity consumers are given an error if there is no capacity available for them, and a "capacityGuard" structure they can use to return the capacity when finished

func NewElasticRateLimiter

func NewElasticRateLimiter(
	maxCapacity int,
	reservedCapacity int,
	cmWindow time.Duration,
	conmanCount *metrics.Counter) *ElasticRateLimiter

NewElasticRateLimiter creates an ElasticRateLimiter and initializes maps maxCapacity: the total (absolute maximum) number of capacity units vended by this ERL at a given time reservedCapacity: the number of capacity units to be reserved per client cmWindow: the window duration of data collection for congestion management, passed to the congestion manager conmanCount: the metric to increment when the congestion manager proposes dropping a request

func (*ElasticRateLimiter) ConsumeCapacity

func (erl *ElasticRateLimiter) ConsumeCapacity(c ErlClient) (*ErlCapacityGuard, error)

ConsumeCapacity will dispense one capacity from either the resource's reservedCapacity, and will return a guard who can return capacity when the client is ready Returns an error if the capacity could not be vended, which could be: - there is not sufficient free capacity to assign a reserved capacity block - there is no reserved or shared capacity available for the client

func (*ElasticRateLimiter) DisableCongestionControl

func (erl *ElasticRateLimiter) DisableCongestionControl()

DisableCongestionControl turns off the flag that the ERL uses to check with its CongestionManager

func (*ElasticRateLimiter) EnableCongestionControl

func (erl *ElasticRateLimiter) EnableCongestionControl()

EnableCongestionControl turns on the flag that the ERL uses to check with its CongestionManager

func (*ElasticRateLimiter) Start

func (erl *ElasticRateLimiter) Start()

Start will start any underlying component of the ElasticRateLimiter

func (*ElasticRateLimiter) Stop

func (erl *ElasticRateLimiter) Stop()

Stop will stop any underlying component of the ElasticRateLimiter

type ErlCapacityGuard

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

ErlCapacityGuard is the structure returned to clients so they can release the capacity when needed they also inform the congestion manager of events

func (*ErlCapacityGuard) Release

func (cg *ErlCapacityGuard) Release() error

Release will put capacity back into the queue attached to this capacity guard

func (*ErlCapacityGuard) Served

func (cg *ErlCapacityGuard) Served()

Served will notify the CongestionManager that this resource has been served, informing the Service Rate

type ErlClient

type ErlClient interface {
	OnClose(func())
}

ErlClient clients must support OnClose for reservation closing

type IncludeFilter

type IncludeFilter func(name string, info os.FileInfo) bool

IncludeFilter is a callback for filtering files and folders encountered while copying with CopyFileWithFilter()

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. must initiate with NewList.

func NewList

func NewList[T any]() *List[T]

NewList creates a new list for storing values of type T.

func (*List[T]) AllocateFreeNodes

func (l *List[T]) AllocateFreeNodes(numAllocs int) *List[T]

AllocateFreeNodes adds N nodes to the free list

func (*List[T]) Back

func (l *List[T]) Back() *ListNode[T]

Back returns the last element of list l or nil if the list is empty.

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *ListNode[T])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) PushFront

func (l *List[T]) PushFront(v T) *ListNode[T]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List[T]) Remove

func (l *List[T]) Remove(e *ListNode[T])

Remove removes e from l if e is an element of list l. The element must not be nil.

type ListNode

type ListNode[T any] struct {
	Value T
	// contains filtered or unexported fields
}

ListNode represent a list node holding next/prev pointers and a value of type T.

type Set

type Set[T comparable] map[T]struct{}

Set is a type alias for map with empty struct{}, where keys are comparable We don't attempt to move even forward for the generics, for keys being comparable should be sufficient for most cases. (Though we actually want compare byte slices, but seems not achievable at this moment)

func MakeSet

func MakeSet[T comparable](elems ...T) Set[T]

MakeSet constructs a set instance directly from elements.

func (Set[T]) Add

func (s Set[T]) Add(elems ...T) Set[T]

Add adds variate number of elements to the set.

func (Set[T]) Contains

func (s Set[T]) Contains(elem T) (exists bool)

Contains checks the membership of an element in the set.

type TCPInfo

type TCPInfo struct {
	RTT            uint32 `json:",omitempty"` // smoothed RTT
	RTTVar         uint32 `json:",omitempty"` // RTT variance
	RTTMin         uint32 `json:",omitempty"` // smallest observed RTT on the connection
	SndMSS, RcvMSS uint32 `json:",omitempty"` // send and receive maximum segment size
	SndCwnd        uint32 `json:",omitempty"` // sender congestion window
	SndWnd         uint32 `json:",omitempty"` // send window advertised to receiver
	RcvWnd         uint32 `json:",omitempty"` // receive window advertised to sender
	//  tcpi_delivery_rate: The most recent goodput, as measured by
	//    tcp_rate_gen(). If the socket is limited by the sending
	//    application (e.g., no data to send), it reports the highest
	//    measurement instead of the most recent. The unit is bytes per
	//    second (like other rate fields in tcp_info).
	Rate uint64 `json:",omitempty"`
	//  tcpi_delivery_rate_app_limited: A boolean indicating if the goodput
	//    was measured when the socket's throughput was limited by the
	//    sending application.
	AppLimited bool `json:",omitempty"`
}

TCPInfo provides socket-level TCP information.

func GetConnTCPInfo

func GetConnTCPInfo(conn net.Conn) (*TCPInfo, error)

GetConnTCPInfo returns statistics for a TCP connection collected by the underlying network implementation, using a system call on Linux and Mac and returning an error for unsupported platforms.

type WatchdogStreamReader

type WatchdogStreamReader interface {
	Reset() error
	Read(p []byte) (n int, err error)
	Close()
}

WatchdogStreamReader is the public interface for the watchdogStreamReader implementation.

func MakeWatchdogStreamReader

func MakeWatchdogStreamReader(underlayingReader io.Reader, readSize uint64, readaheadSize uint64, readaheadDuration time.Duration) WatchdogStreamReader

MakeWatchdogStreamReader creates a watchdogStreamReader and initializes it.

Directories

Path Synopsis
Package bloom implements Bloom filters.
Package bloom implements Bloom filters.
Package db defines database utility functions.
Package db defines database utility functions.
Package metrics provides a metric logging wrappers for Prometheus server.
Package metrics provides a metric logging wrappers for Prometheus server.
Package timers provides a Clock abstraction useful for simulating timeouts.
Package timers provides a Clock abstraction useful for simulating timeouts.

Jump to

Keyboard shortcuts

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