buffer

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: 3 Imported by: 0

Documentation

Overview

Package buffer holds the per-event-kind drop-oldest ring buffer the agent uses to absorb backpressure on an OPEN stream.

When the stream's send path cannot keep up (a slow server, a burst of events), the stream layer parks events here and drains them as soon as the send path frees up, so a burst is smoothed instead of dropped. Buffers are bounded; on overflow the oldest entry is evicted (drop-oldest), and the agent's events_dropped_total{reason="buffer_full"} counter is bumped by the agent layer.

It does NOT bridge disconnects: the agent subscribes to the observability bus only while a stream is open, so events that occur between a disconnect and the next accepted stream are not captured anywhere. This is also not a replay log — it does not persist across restarts and does not survive process death.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is an opaque per-kind drop-oldest store. Use Set to provision a per-kind buffer at agent boot, Push when the stream is down, Drain when the stream comes back. Snapshot is a read-only view that does not consume the buffer (used by metrics).

func New

func New(capacity int) *Buffer

New constructs a buffer with the given capacity. Capacity ≤ 0 falls back to the default of 64 entries.

func (*Buffer) Capacity

func (b *Buffer) Capacity() int

Capacity returns the configured maximum.

func (*Buffer) Drain

func (b *Buffer) Drain(limit int) []*adminv1.Event

Drain removes and returns up to limit entries, oldest first. Pass a negative or zero limit to drain everything currently buffered. Drain does not block — it is a snapshot operation done under the buffer's own lock.

func (*Buffer) Dropped

func (b *Buffer) Dropped() uint64

Dropped returns the cumulative number of evictions since construction.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the current number of buffered events.

func (*Buffer) Push

func (b *Buffer) Push(e *adminv1.Event) (evicted bool)

Push adds e at the head, evicting the oldest entry if the buffer is full. Returns true when the push displaced an older entry. The caller (agent) maps that to "events_dropped_total{reason=buffer_full}".

type PerKind

type PerKind struct {
	HTTP    *Buffer
	SQL     *Buffer
	Session *Buffer
	Custom  *Buffer
}

PerKind groups four buffers (one per EventKind) so callers can route by kind without an extra map lookup at the call site.

func NewPerKind

func NewPerKind(capacities map[observability.EventKind]int) *PerKind

NewPerKind constructs four buffers with the given capacities. Pass capacities ≤ 0 to use the per-kind default.

func (*PerKind) DrainAll

func (p *PerKind) DrainAll() []*adminv1.Event

DrainAll empties every buffer and returns the events oldest-first, interleaved by kind in declaration order (HTTP, SQL, Session, Custom). Used during graceful drain on shutdown and on reconnect.

func (*PerKind) For

For returns the buffer for the given kind, or nil for unknown kinds.

func (*PerKind) LenSnapshot

func (p *PerKind) LenSnapshot() map[observability.EventKind]int

LenSnapshot returns the per-kind count, intended for periodic Prometheus gauge updates.

Jump to

Keyboard shortcuts

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