pipestats

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pipestats implements model.StatsRecorder: it records per-query observability rows and flushes them to ClickHouse in batches via the shared CHInserter, mirroring the gatherer's max(N, interval) flush (ADR 0014). Recording is non-blocking — observability must never slow or block the query path, so a full buffer drops stats rather than applying backpressure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Recorder)

Option configures a Recorder.

func WithBufferSize

func WithBufferSize(n int) Option

WithBufferSize sets the in-flight buffer capacity before Record drops (default 4096).

func WithFlushInterval

func WithFlushInterval(d time.Duration) Option

WithFlushInterval sets the max time a stat waits before flushing (default 5s).

func WithFlushSize

func WithFlushSize(n int) Option

WithFlushSize sets the row count that triggers an early flush (default 1000).

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the slog logger (default: slog.Default).

type Recorder

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

Recorder buffers QueryStats and flushes them to ClickHouse. Build with New; the background flusher starts immediately. Call Close to drain on shutdown.

func New

func New(ins model.CHInserter, opts ...Option) *Recorder

New builds a Recorder and starts its background flusher. ins writes the batched rows; the destination table is described by Schema().

func (*Recorder) Close

func (r *Recorder) Close(ctx context.Context) error

Close stops the flusher and drains buffered stats, returning when the final flush completes or ctx expires. Safe to call once.

func (*Recorder) Dropped

func (r *Recorder) Dropped() int64

Dropped returns how many stats have been dropped due to buffer overflow.

func (*Recorder) Record

func (r *Recorder) Record(stat model.QueryStat)

Record buffers a stat for async flush. It is non-blocking: if the buffer is full the stat is dropped (counted), never applying backpressure to the query path (ADR 0014 — best-effort observability).

ponytail: dropping is the intended overflow behavior; the dropped counter is in-memory only. A future build could expose it as a Prometheus gauge.

func (*Recorder) Schema

func (r *Recorder) Schema() *model.Datasource

Schema returns the synthetic Datasource describing the pipe_stats table, so the orchestrator/deploy can EnsureTable it before the first flush.

ponytail: Tinybird writes to db `tinybird.pipe_stats`; the MVP writes to a `pipe_stats` table in the active workspace database. Promote to a dedicated `tinybird` database when system-table parity matters.

Jump to

Keyboard shortcuts

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