gatherer

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

Documentation

Overview

Package gatherer buffers incoming events in-process and flushes them to ClickHouse in batches (ADRs 0004, 0018). It implements model.Ingester: Ingest validates each row, quarantines the bad ones, buffers the good ones, and acks immediately (the API returns 202) — a single background flusher drains the buffer on max(flushSize rows, flushInterval). On graceful Close the remaining buffer is drained so nothing is lost on clean shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gatherer

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

Gatherer is the in-process event buffer + flusher.

func New

func New(ins model.CHInserter, reg model.DatasourceRegistry, opts ...Option) *Gatherer

New builds a Gatherer and starts its background flusher. Call Close to drain.

func (*Gatherer) Close

func (g *Gatherer) Close(ctx context.Context) error

Close stops the flusher and drains the buffer, returning when the final flush completes or ctx expires (graceful drain, ADR 0004). Safe to call once.

func (*Gatherer) Ingest

func (g *Gatherer) Ingest(ctx context.Context, datasource string, rows []json.RawMessage) (successful, quarantined int, err error)

Ingest validates rows for a datasource and buffers them (ack-on-buffer, ADR 0004). Bad rows are quarantined rather than rejecting the batch (ADR 0018); an unknown datasource is the only per-call error (the API maps it to 4xx).

type Option

type Option func(*Gatherer)

Option configures a Gatherer.

func WithFlushInterval

func WithFlushInterval(d time.Duration) Option

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

func WithFlushSize

func WithFlushSize(n int) Option

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

func WithLogger

func WithLogger(l *slog.Logger) Option

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

Jump to

Keyboard shortcuts

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