sampling

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sampling provides rate based sampling for use by components that need to include a fraction of items in a "sampled" set (e.g. loki.secretfilter for processing rate, loki.process.stages.sampling for drop rate).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRate

func ValidateRate(rate float64) error

ValidateRate returns an error if rate is not in [0.0, 1.0].

Types

type Sampler

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

Sampler decides probabilistically whether an item should be included in the sample (ShouldSample returns true). Rate is the probability of inclusion; 0 = never, 1 = always, 0.5 = ~50%.

func NewSampler

func NewSampler(rate float64) *Sampler

NewSampler returns a Sampler for the given rate. Rate must be in [0.0, 1.0]; call ValidateRate first or the sampler behavior for out-of-range rate is undefined.

func (*Sampler) ShouldSample

func (s *Sampler) ShouldSample() bool

ShouldSample returns true with probability equal to the rate used to create or update the sampler. Rate 0 → always false; rate 1 → always true; otherwise uses the same probabilistic algorithm as Jaeger's ProbabilisticSampler.

func (*Sampler) Update

func (s *Sampler) Update(rate float64)

Update updates the sampler for a new rate (e.g. on component config change). Rate must be in [0.0, 1.0]; call ValidateRate first or behavior is undefined.

Jump to

Keyboard shortcuts

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