sampler

package
v0.6.20 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sampler implements per-kind sampling and post-bus filtering for the agent.

The bus's own Filter narrows by EventKind and NodeID — coarse-grained, fast. The Sampler refines this with two further dimensions the bus deliberately does not know about:

  • Per-kind sampling rate (0.0–1.0). The admin server may say "ship 10 % of SQL events but 100 % of HTTP" because SQL volume can overwhelm the channel during normal load.
  • HTTP-specific filters (path glob, method, status class) and SQL- specific filters (model name) that the bus is intentionally agnostic about. Forwarding these to the bus would couple it to wire concepts it does not own.

Sampler is goroutine-safe; the rate map and the filter are read on every event. Rates and filters can be updated atomically via Update.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision uint8

Decision is the outcome of running the sampler over one event.

const (
	// Accept means the event passes; the agent should forward it.
	Accept Decision = iota
	// DropSampled means the per-kind rate randomly excluded this event.
	DropSampled
	// DropFiltered means a wire-level filter rejected it.
	DropFiltered
)

type Sampler

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

Sampler groups one filter and its sampling rates, behind an RWMutex so the server-driven Subscribe can update it without tearing.

func New

func New(filter *adminv1.Filter, rates map[string]float32) *Sampler

New constructs a Sampler with the given starting filter and rate map. Pass nil filter for "no constraint" and nil rates for "100 % all kinds".

func (*Sampler) Decide

func (s *Sampler) Decide(e observability.Event) Decision

Decide runs the rate roll first (cheap), then the filter (more work). Returns one of Accept / DropSampled / DropFiltered. The caller is responsible for incrementing the right counter.

func (*Sampler) Update

func (s *Sampler) Update(filter *adminv1.Filter, rates map[string]float32)

Update replaces the filter and rates atomically.

Jump to

Keyboard shortcuts

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