memorylimiter

package module
v0.161.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 11 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")

	// 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"`

	// MinGCIntervalWhenSoftLimited minimum interval between forced GC when in soft (=limit_mib - spike_limit_mib) limited mode.
	// Zero value means no minimum interval.
	// GCs is a CPU-heavy operation and executing it too frequently may affect the recovery capabilities of the collector.
	MinGCIntervalWhenSoftLimited time.Duration `mapstructure:"min_gc_interval_when_soft_limited"`

	// MinGCIntervalWhenHardLimited minimum interval between forced GC when in hard (=limit_mib) limited mode.
	// Zero value means no minimum interval.
	// GCs is a CPU-heavy operation and executing it too frequently may affect the recovery capabilities of the collector.
	MinGCIntervalWhenHardLimited time.Duration `mapstructure:"min_gc_interval_when_hard_limited"`

	// MaxGCIntervalWhenSoftLimited caps the exponential backoff between forced
	// GC calls in soft-limited mode. When a forced GC fails to reclaim memory
	// (e.g., held by live references in exporter queues during a downstream
	// outage), the interval doubles starting from min_gc_interval_when_soft_limited
	// (or 95% of check_interval, whichever is larger) up to this cap. It resets
	// to zero whenever a GC is effective or memory drops on its own.
	// Set to 0 to disable the exponential backoff on this path; the interval
	// will not grow beyond the configured min.
	MaxGCIntervalWhenSoftLimited time.Duration `mapstructure:"max_gc_interval_when_soft_limited"`

	// MaxGCIntervalWhenHardLimited caps the exponential backoff between forced
	// GC calls in hard-limited mode. Same semantics as
	// MaxGCIntervalWhenSoftLimited but applies to the hard-limit path.
	// Set to 0 to disable the exponential backoff on this path.
	MaxGCIntervalWhenHardLimited time.Duration `mapstructure:"max_gc_interval_when_hard_limited"`

	// 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 NewDefaultConfig added in v0.121.0

func NewDefaultConfig() *Config

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 toggles mustRefuse when threshold is exceeded

func (*MemoryLimiter) MustRefuse

func (ml *MemoryLimiter) MustRefuse() bool

MustRefuse returns true if memory has reached its 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

Directories

Path Synopsis
Package cgroups provides utilities to access Linux control group (CGroups) parameters (total memory, for example) for a given process.
Package cgroups provides utilities to access Linux control group (CGroups) parameters (total memory, for example) for a given process.

Jump to

Keyboard shortcuts

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