memorylimiter

package
v0.98.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDataRefused will be returned to callers of ConsumeTraceData to indicate
	// that data is being refused due to high memory usage.
	ErrDataRefused = errors.New("data refused due to high memory usage")

	// ErrShutdownNotStarted indicates no memorylimiter has not start when shutdown
	ErrShutdownNotStarted = errors.New("no existing monitoring routine is running")

	// GetMemoryFn and ReadMemStatsFn make it overridable by tests
	GetMemoryFn    = iruntime.TotalMemory
	ReadMemStatsFn = runtime.ReadMemStats
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// CheckInterval is the time between measurements of memory usage for the
	// purposes of avoiding going over the limits. Defaults to zero, so no
	// checks will be performed.
	CheckInterval time.Duration `mapstructure:"check_interval"`

	// MemoryLimitMiB is the maximum amount of memory, in MiB, targeted to be
	// allocated by the process.
	MemoryLimitMiB uint32 `mapstructure:"limit_mib"`

	// MemorySpikeLimitMiB is the maximum, in MiB, spike expected between the
	// measurements of memory usage.
	MemorySpikeLimitMiB uint32 `mapstructure:"spike_limit_mib"`

	// MemoryLimitPercentage is the maximum amount of memory, in %, targeted to be
	// allocated by the process. The fixed memory settings MemoryLimitMiB has a higher precedence.
	MemoryLimitPercentage uint32 `mapstructure:"limit_percentage"`

	// MemorySpikePercentage is the maximum, in percents against the total memory,
	// spike expected between the measurements of memory usage.
	MemorySpikePercentage uint32 `mapstructure:"spike_limit_percentage"`
}

Config defines configuration for memory memoryLimiter processor.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks if the processor configuration is valid

type MemoryLimiter

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

MemoryLimiter is used to prevent out of memory situations on the collector.

func NewMemoryLimiter

func NewMemoryLimiter(cfg *Config, logger *zap.Logger) (*MemoryLimiter, error)

NewMemoryLimiter returns a new memory limiter component

func (*MemoryLimiter) CheckMemLimits

func (ml *MemoryLimiter) CheckMemLimits()

CheckMemLimits inspects current memory usage against threshold and toggle mustRefuse when threshold is exceeded

func (*MemoryLimiter) MustRefuse

func (ml *MemoryLimiter) MustRefuse() bool

MustRefuse returns if the caller should deny because memory has reached it's configured limits

func (*MemoryLimiter) Shutdown

func (ml *MemoryLimiter) Shutdown(context.Context) error

Shutdown resets MemoryLimiter monitoring ticker and stop monitoring

func (*MemoryLimiter) Start

func (ml *MemoryLimiter) Start(_ context.Context, host component.Host) error

Jump to

Keyboard shortcuts

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