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 ¶
New constructs a buffer with the given capacity. Capacity ≤ 0 falls back to the default of 64 entries.
func (*Buffer) Drain ¶
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.
type PerKind ¶
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 ¶
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 ¶
func (p *PerKind) For(k observability.EventKind) *Buffer
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.