util

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvK8SNamespace = "NAMESPACE"
)
View Source
const EnvLogFormat = "ARKE_LOG_FORMAT"
View Source
const EnvLogLevel = "ARKE_LOG_LEVEL"

Variables

View Source
var (

	// LogOutputFile is the default output destination for the logger
	LogOutputFile = os.Stderr
)

Functions

func GenUUID

func GenUUID() string

GenUUID Generate a UUID and return the string representation

func GetClientAddr

func GetClientAddr(ctx context.Context) (string, error)

GetClientAddr gets the client-id from the context metadata

func GetClientIdentifier

func GetClientIdentifier(ctx context.Context) (string, error)

GetClientIdentifier retrieves or generates the client identifier

func GetConfig

func GetConfig(key string, def interface{}) interface{}

func MonitorHPA

func MonitorHPA(healthChan chan pb.HealthStatus_Code, arkeHpaName string)

MonitorHPA monitors the HPA for changes and sends a GOAWAY signal to the health check channel when the replica count is increased

func MonitorProcessStats

func MonitorProcessStats()

func NewTimestampPB

func NewTimestampPB() *timestamppb.Timestamp

func RecoverPanic

func RecoverPanic()

func RemoveClientIdentifier

func RemoveClientIdentifier(ctx context.Context)

func ResetLogger

func ResetLogger()

func ServceNameFromClientAddr

func ServceNameFromClientAddr(clientAddr string) string

ServceNameFromClientAddr returns the service name from the client address. The client address typically looks like <service-name>-<random-string>. The random string almost always contain numbers, so we can use that to to determine the service it came from.

func SetClientIdentifier

func SetClientIdentifier(ctx context.Context, name string) (string, error)

func SleepRandom

func SleepRandom(sleepMin int, sleepMax int)

Types

type ArkeLogger

type ArkeLogger struct {
	T func(messageID string, args ...interface{}) string
	// contains filtered or unexported fields
}
var (
	Logger *ArkeLogger
)

func NewArkeFileLogger

func NewArkeFileLogger(file *os.File) *ArkeLogger

func NewArkeLogger

func NewArkeLogger() *ArkeLogger

func (*ArkeLogger) Debug

func (l *ArkeLogger) Debug(messageID string, args ...interface{})

Debug - Log a debug level message with translation and parameter substitution

func (*ArkeLogger) Debugf

func (l *ArkeLogger) Debugf(format string, args ...interface{})

Debugf - Log a debug level message with format string and parameters

func (*ArkeLogger) Error

func (l *ArkeLogger) Error(messageID string, args ...interface{})

Error - Log an error level message with translation and parameter substitution

func (*ArkeLogger) Fatal

func (l *ArkeLogger) Fatal(messageID string, args ...interface{})

Fatal - Log a fatal level message with translation and parameter substitution

func (*ArkeLogger) Info

func (l *ArkeLogger) Info(messageID string, args ...interface{})

Info - Log an info level message with translation and parameter substitution

func (*ArkeLogger) Trace

func (l *ArkeLogger) Trace(messageID string, args ...interface{})

Trace - Log a trace level message with translation and parameter substitution

func (*ArkeLogger) Tracef

func (l *ArkeLogger) Tracef(format string, args ...interface{})

Tracef - Log a trace level message with format string and parameters

func (*ArkeLogger) Warn

func (l *ArkeLogger) Warn(messageID string, args ...interface{})

Warn - Log a warn level message with translation and parameter substitution

type BlockingLatch

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

func NewBlockingLatch

func NewBlockingLatch(ctx context.Context, m uint) *BlockingLatch

func (*BlockingLatch) Count

func (bl *BlockingLatch) Count() uint

func (*BlockingLatch) Decrement

func (bl *BlockingLatch) Decrement()

func (*BlockingLatch) GetMax

func (bl *BlockingLatch) GetMax() uint

func (*BlockingLatch) Increment

func (bl *BlockingLatch) Increment() error

func (*BlockingLatch) SetMax

func (bl *BlockingLatch) SetMax(m uint)

func (*BlockingLatch) WaitForEmpty

func (bl *BlockingLatch) WaitForEmpty() error

type BlockingPool

type BlockingPool struct {
	New func() any
	// Validate is called on every item before it is handed to a caller (Get)
	// or accepted back from a caller (Put).  Return true if the item is still
	// healthy, false to retire it and let the pool allocate a fresh one.
	// If Validate is nil all items are considered valid.
	Validate func(any) bool
	// contains filtered or unexported fields
}

func NewBlockingPool

func NewBlockingPool(ctx context.Context, limit int, constructor func() any) *BlockingPool

func (*BlockingPool) Get

func (p *BlockingPool) Get() any

func (*BlockingPool) Put

func (p *BlockingPool) Put(x any) error

type CgroupVersion

type CgroupVersion int

CgroupVersion represents the cgroup version in use

const (
	CgroupV1 CgroupVersion = iota
	CgroupV2
)

type ConcurrentMap

type ConcurrentMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrentMap A map[string]interface{} with a mutex to prevent concurrent access errors

func NewConcurrentMap

func NewConcurrentMap() *ConcurrentMap

NewConcurrentMap Creates a new ConcurrentMap

func (*ConcurrentMap) Add

func (cm *ConcurrentMap) Add(key string, item interface{})

Add Add a key/value to the map

func (*ConcurrentMap) Delete

func (cm *ConcurrentMap) Delete(key string)

Delete Delete a key from the map

func (*ConcurrentMap) Get

func (cm *ConcurrentMap) Get(key string) (interface{}, bool)

Get Return the value for a given key in the map

func (*ConcurrentMap) GetList

func (cm *ConcurrentMap) GetList() []string

GetList Return a list of all keys in the map

func (*ConcurrentMap) Length

func (cm *ConcurrentMap) Length() int

Length Return the length of the map

type ProcessStats

type ProcessStats struct {
	CPUAvailability    float32 // CPU availability as a ratio (0.0 to 1.0)
	MemoryAvailability float32 // Memory availability as a ratio (0.0 to 1.0)
}

func GetProcessStats

func GetProcessStats() *ProcessStats

func (*ProcessStats) IsUnhealthyUsage

func (ps *ProcessStats) IsUnhealthyUsage() bool

type SafeBuffer

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

SafeBuffer is a thread-safe circular buffer that utilizes a ring structure.

func NewSafeBuffer

func NewSafeBuffer(size int) *SafeBuffer

NewSafeBuffer initializes a new SafeBuffer with the specified size.

func (*SafeBuffer) Add

func (sr *SafeBuffer) Add(val interface{})

Add inserts a new value into the SafeBuffer in a thread-safe manner.

func (*SafeBuffer) GetData

func (sr *SafeBuffer) GetData() []any

GetData retrieves all non-nil entries from the SafeBuffer in a thread-safe manner.

func (*SafeBuffer) GetMostRecent

func (sr *SafeBuffer) GetMostRecent() any

GetMostRecent retrieves the most recently added entry from the SafeBuffer in a thread-safe manner.

type TestLogger

type TestLogger struct {
	*ArkeLogger
	// contains filtered or unexported fields
}

func GetTestLoggerWithCleanup

func GetTestLoggerWithCleanup() (*TestLogger, func())

GetTestLoggerWithCleanup should only be used in tests when you need to capture the log output

func (*TestLogger) GetOutput

func (l *TestLogger) GetOutput() []byte

GetOutput reads the log output from the TestLogger's reader and returns it as a byte slice Note that this will close the writer and reader, so it should only be called once per TestLogger instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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