general

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlockCoolingInterval = 6 * time.Second
	FlockTryLockMaxTimes = 10
)
View Source
const (
	SmoothWindowAggFuncAvg  = "average"
	SmoothWindowAggFuncPerc = "percentile"
)

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("not found")
)

common errors

View Source
var (
	// NativeEndian is the native endian
	NativeEndian binary.ByteOrder
)

Functions

func CheckHealthz

func CheckHealthz() map[HealthzCheckName]HealthzCheckResponse

CheckHealthz walks through the registered healthz functions to provide an insight about the running states of current process. if functions failed, returns HealthzCheckStateFailed as the returned state.

func CheckMapEqual

func CheckMapEqual(pre, cur map[string]string) bool

func Clamp

func Clamp(value, min, max float64) float64

Clamp returns value itself if min < value < max; min if value < min; max if value > max

func CmpBool

func CmpBool(a, b bool) int

CmpBool compares booleans, placing true before false

func CmpError

func CmpError(err1, err2 error) int

CmpError compares errors, placing not nil before nil

func CmpFloat64

func CmpFloat64(a, b float64) int

CmpFloat64 compares float64s, placing greater before smaller

func CmpInt32

func CmpInt32(a, b int32) int

CmpInt32 compares int32s, placing greater before smaller

func CovertInt64ToInt

func CovertInt64ToInt(numInt64 int64) (int, error)

func CovertUInt64ToInt

func CovertUInt64ToInt(numUInt64 uint64) (int, error)

func DeepCopyMap

func DeepCopyMap(origin map[string]string) map[string]string

func EnsureDirectory

func EnsureDirectory(dir string) error

func ErrorS

func ErrorS(err error, message string, params ...interface{})

func ErrorSPath

func ErrorSPath(pkg LoggingPKG, err error, message string, params ...interface{})

func Errorf

func Errorf(message string, params ...interface{})

func ErrorfPath

func ErrorfPath(pkg LoggingPKG, message string, params ...interface{})

func Fatalf

func Fatalf(message string, params ...interface{})

func FatalfPath

func FatalfPath(pkg LoggingPKG, message string, params ...interface{})

func FormatMemoryQuantity

func FormatMemoryQuantity(q float64) string

FormatMemoryQuantity aligned to Gi Mi Ki

func GenerateHash

func GenerateHash(data []byte, length int) string

func GetInt64PointerFromUint64Pointer

func GetInt64PointerFromUint64Pointer(v *uint64) (*int64, error)

func GetOneExistPath

func GetOneExistPath(paths []string) string

GetOneExistPath is to get one of exist paths

func GetSortedMapKeys

func GetSortedMapKeys(m map[string]int) []string

GetSortedMapKeys returns a slice containing sorted keys for the given map

func GetStringValueFromMap

func GetStringValueFromMap(m map[string]string, key string) string

func GetValueWithDefault

func GetValueWithDefault(m map[string]string, key, defaultV string) string

GetValueWithDefault gets value from the given map, and returns default if key not exist

func InfoS

func InfoS(message string, params ...interface{})

func InfoSPath

func InfoSPath(pkg LoggingPKG, message string, params ...interface{})

func Infof

func Infof(message string, params ...interface{})

func InfofPath

func InfofPath(pkg LoggingPKG, message string, params ...interface{})

func InfofV

func InfofV(level int, message string, params ...interface{})

func InfofVPath

func InfofVPath(pkg LoggingPKG, level int, message string, params ...interface{})

func IntSliceToStringSlice

func IntSliceToStringSlice(a []int) []string

func IsErrNotFound

func IsErrNotFound(err error) bool

func IsNameEnabled

func IsNameEnabled(name string, disabledByDefault sets.String, enableNames []string) bool

IsNameEnabled check if a specified name enabled or not.

func IsPathExists

func IsPathExists(path string) bool

IsPathExists is to check this path whether exists

func IsUnmarshalTypeError

func IsUnmarshalTypeError(err error) bool

IsUnmarshalTypeError check whether is json unmarshal type error

func JsonPathEmpty

func JsonPathEmpty(str []byte) bool

JsonPathEmpty is used to check whether the given str is empty for json-patch

func Max

func Max(a, b int) int

func MaxFloat64

func MaxFloat64(a, b float64) float64

func MaxInt64

func MaxInt64(a, b int64) int64

func MaxTimePtr

func MaxTimePtr(a, b *time.Time) *time.Time

func MaxUInt64

func MaxUInt64(a, b uint64) uint64

func MergeMap

func MergeMap(src, override map[string]string) map[string]string

MergeMap merges the contents from override into the src

func MergeMapInt

func MergeMapInt(src, override map[string]int) map[string]int

MergeMapInt merges the contents from override into the src

func Min

func Min(a, b int) int

func MinUInt32

func MinUInt32(a, b uint32) uint32

func MinUInt64

func MinUInt64(a, b uint64) uint64

func ParseMapWithPrefix

func ParseMapWithPrefix(prefix, selector string) (map[string]string, error)

ParseMapWithPrefix converts selector string to label map and validates keys and values

func ParseStringToUint64Pointer

func ParseStringToUint64Pointer(s string) (*uint64, error)

func ParseUint64PointerToString

func ParseUint64PointerToString(v *uint64) string

func ReadFileIntoInt

func ReadFileIntoInt(filepath string) (int, error)

ReadFileIntoInt read contents from the given file, and parse them into integer

func ReadFileIntoLines

func ReadFileIntoLines(filepath string) ([]string, error)

ReadFileIntoLines read contents from the given file, and parse them into string slice; each string indicates a line in the file

func RegisterFileEventWatcher

func RegisterFileEventWatcher(stop <-chan struct{}, fileWatcherInfo FileWatcherInfo) (<-chan struct{}, error)

RegisterFileEventWatcher inotify the given file and report the changed information to the caller through returned channel

func RegisterHealthzCheckRules

func RegisterHealthzCheckRules(name HealthzCheckName, f HealthzCheckFunc)

RegisterHealthzCheckRules supports to register healthz check functions.

func ReleaseUniqueLock

func ReleaseUniqueLock(lock *Flock)

ReleaseUniqueLock release the given file lock

func SetDefaultLoggingPackage

func SetDefaultLoggingPackage(l LoggingPKG)

SetDefaultLoggingPackage should only be called by flags, and should not be alerted dynamically.

func SumUpMapValues

func SumUpMapValues(m map[string]int) int

SumUpMapValues accumulates total values for the given map

func SumUpMultipleMapValues

func SumUpMultipleMapValues(m map[string]map[string]int) int

SumUpMultipleMapValues accumulates total values for the given multi-level map

func ToString

func ToString(in interface{}) string

ToString transform to string for better display etc. in log

func UInt64PointerToFloat64

func UInt64PointerToFloat64(p *uint64) float64

func UIntPointerToFloat64

func UIntPointerToFloat64(p *uint) float64

func Warningf

func Warningf(message string, params ...interface{})

func WarningfPath

func WarningfPath(pkg LoggingPKG, message string, params ...interface{})

Types

type CappedSmoothWindow

type CappedSmoothWindow struct {
	sync.Mutex

	SmoothWindow
	// contains filtered or unexported fields
}

func NewCappedSmoothWindow

func NewCappedSmoothWindow(minStep resource.Quantity, maxStep resource.Quantity, smoothWindow SmoothWindow) *CappedSmoothWindow

NewCappedSmoothWindow creates a capped SmoothWindow, which

func (*CappedSmoothWindow) GetWindowedResources

func (m *CappedSmoothWindow) GetWindowedResources(value resource.Quantity) *resource.Quantity

GetWindowedResources cap the value return by smooth window min to max

type CmpFunc

type CmpFunc func(i1, i2 interface{}) int

func ReverseCmpFunc

func ReverseCmpFunc(cmpFunc CmpFunc) CmpFunc

type FileWatcherInfo

type FileWatcherInfo struct {
	// if Filename is empty, it means that we should watch all file events in all paths,
	// otherwise, watch this specific file in all paths
	Filename string
	Path     []string
	Op       fsnotify.Op
}

type Flock

type Flock struct {
	LockFile string
	// contains filtered or unexported fields
}

func GetUniqueLock

func GetUniqueLock(filename string) (*Flock, error)

GetUniqueLock is a wrapper function for getUniqueLockWithTimeout with default configurations

func (*Flock) Lock

func (f *Flock) Lock() (e error)

func (*Flock) Release

func (f *Flock) Release()

func (*Flock) Unlock

func (f *Flock) Unlock()

type HealthzCheckFunc

type HealthzCheckFunc func() (HealthzCheckResponse, error)

HealthzCheckFunc defined as a common function to define whether the corresponding component is healthy.

type HealthzCheckName

type HealthzCheckName string

HealthzCheckName describes which rule name for this check

type HealthzCheckResponse

type HealthzCheckResponse struct {
	State   HealthzCheckState `json:"state"`
	Message string            `json:"message"`
}

type HealthzCheckState

type HealthzCheckState string

HealthzCheckState describes the checking results

const (
	HealthzCheckStateReady    HealthzCheckState = "Ready"
	HealthzCheckStateNotReady HealthzCheckState = "NotReady"
	HealthzCheckStateUnknown  HealthzCheckState = "Unknown"
	HealthzCheckStateFailed   HealthzCheckState = "Failed"
)

type Logger

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

func LoggerWithPrefix

func LoggerWithPrefix(prefix string, pkg LoggingPKG) Logger

func (Logger) ErrorS

func (l Logger) ErrorS(err error, message string, params ...interface{})

func (Logger) Errorf

func (l Logger) Errorf(message string, params ...interface{})

func (Logger) Fatalf

func (l Logger) Fatalf(message string, params ...interface{})

func (Logger) InfoS

func (l Logger) InfoS(message string, params ...interface{})

func (Logger) Infof

func (l Logger) Infof(message string, params ...interface{})

func (Logger) InfofV

func (l Logger) InfofV(level int, message string, params ...interface{})

func (Logger) Warningf

func (l Logger) Warningf(message string, params ...interface{})

type LoggingPKG

type LoggingPKG int
const (
	LoggingPKGNone LoggingPKG = iota
	LoggingPKGShort
	LoggingPKGFull
)

func (*LoggingPKG) Set

func (l *LoggingPKG) Set(value string) error

func (*LoggingPKG) String

func (l *LoggingPKG) String() string

func (*LoggingPKG) Type

func (l *LoggingPKG) Type() string

type MultiSorter

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

MultiSorter implements the Sort interface, sorting changes within.

func NewMultiSorter

func NewMultiSorter(cmp ...CmpFunc) *MultiSorter

NewMultiSorter returns a Sorter that sorts using the cmp functions, in order. Call its Sort method to sort the data.

func (*MultiSorter) Sort

func (ms *MultiSorter) Sort(sources SourceList)

Sort sorts the argument slice according to the Less functions passed to NewMultiSorter.

type ResourceList

type ResourceList v1.ResourceList

func (*ResourceList) Set

func (r *ResourceList) Set(value string) error

func (*ResourceList) String

func (r *ResourceList) String() string

func (*ResourceList) Type

func (r *ResourceList) Type() string

type SmoothWindow

type SmoothWindow interface {
	// GetWindowedResources receives a sample and returns the result after smoothing,
	// it can return nil if there are not enough samples in this window
	GetWindowedResources(value resource.Quantity) *resource.Quantity
}

SmoothWindow is used to smooth the resource

func NewAggregatorSmoothWindow

func NewAggregatorSmoothWindow(opts SmoothWindowOpts) SmoothWindow

func NewAverageWithTTLSmoothWindow

func NewAverageWithTTLSmoothWindow(windowSize int, ttl time.Duration, usedMillValue bool) SmoothWindow

NewAverageWithTTLSmoothWindow create a smooth window with ttl and window size, and the window size is the sample count while the ttl is the valid lifetime of each sample, and the usedMillValue means whether calculate the result with milli-value.

func NewPercentileWithTTLSmoothWindow

func NewPercentileWithTTLSmoothWindow(windowSize int, ttl time.Duration, percentile float64, usedMillValue bool) SmoothWindow

NewPercentileWithTTLSmoothWindow create a smooth window with ttl and window size, and the window size is the sample count while the ttl is the valid lifetime of each sample, and the usedMillValue means whether calculate the result with milli-value.

type SmoothWindowOpts

type SmoothWindowOpts struct {
	WindowSize    int
	TTL           time.Duration
	UsedMillValue bool
	AggregateFunc string
	AggregateArgs string
}

type SourceList

type SourceList interface {
	Len() int
	GetSource(index int) interface{}
	SetSource(index int, s interface{})
}

Jump to

Keyboard shortcuts

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