Documentation
¶
Overview ¶
Package clickhouse provides a ClickHouse-backed implementation of payload.Sink, payload.Reader, and payload.Closer — the "text bodies in ClickHouse" backend for the Logs view. Metadata + bodies live in one MergeTree table (bodies as ZSTD String columns); List projects only the metadata columns, Get fetches the body columns by request_id.
Durability comes from a WAL-segment queue (pkg/wal): records append to an active segment; full segments rotate and flush to ClickHouse; a segment is deleted only after CH confirms the insert; leftover segments are drained on boot. Rotation also triggers on a byte threshold — payload bodies are MB-scale, so a line-count cap alone would let a segment grow to gigabytes.
Out of scope: schema migrations (IF NOT EXISTS), dedup of replayed segments (idempotency is the caller's concern), multi-node coordination (each pod runs its own WAL in its own directory).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var InsertSQL = "INSERT INTO " + chTable + " (" + strings.Join(insertColumns, ", ") + ")"
InsertSQL is the INSERT statement matching insertColumns, shared with tools that write the table directly.
Functions ¶
func InsertValues ¶ added in v0.10.1
InsertValues returns r's column values in InsertSQL order.
Types ¶
type Config ¶
type Config struct {
// DSN is the ClickHouse connection string (clickhouse://host:port/db).
DSN string
// RetentionDays is the row TTL in days; 0 keeps rows forever.
RetentionDays int
// WALDir is the directory for WAL segment files.
WALDir string
// MaxLines is the number of records per WAL segment before rotation.
// Default 2000 (lower than usage's 10k — records are large).
MaxLines int
// MaxBytes rotates the active segment once it exceeds this size,
// whichever comes first with MaxLines. Default 64 MiB.
MaxBytes int
// FlushInterval is how often the background goroutine rotates and
// flushes pending segments. Default 10s.
FlushInterval time.Duration
// MaxSegments caps how many pending segment files may accumulate on
// disk. When exceeded, the oldest are dropped and counted in Dropped().
// Default 256.
MaxSegments int
// Dedup makes the sink write request bodies as skeletons plus shared
// pieces (payload_requests + payload_pieces) instead of whole rows in
// payload_logs. Readers serve both regardless.
Dedup bool
}
Config holds all tunables for the ClickHouse payload sink. It mirrors the usage CH sink's config; the WAL knobs are shared, plus a byte-based rotation threshold since payload bodies are MB-scale (a line-count cap alone would let a segment grow to gigabytes before rotating).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is the read-only half: a ClickHouse connection serving List/Get with no WAL. The /payloads endpoints use this so the read path carries none of the write-side machinery (segment queue, recovery). Implements payload.Reader + payload.Closer.
func NewReader ¶
NewReader opens a read-only connection (no WAL). ensureSchema runs so the Logs page works against an empty table before the first write.
func (*Reader) Erase ¶ added in v0.10.3
func (s *Reader) Erase(ctx context.Context, f payload.EraseFilter) (payload.EraseResult, error)
Erase deletes the request rows (both layouts) matching f, then the pieces of the affected projects that no remaining request references and that were last written before the erase began. Each delete waits until ClickHouse has rewritten the affected parts, so the bodies are unreadable when Erase returns.
type Sink ¶
type Sink struct {
*Reader
// contains filtered or unexported fields
}
Sink is the write half: Reader + a WAL-backed insert path. Implements payload.Sink (and, via the embedded Reader, payload.Reader) + payload.Closer.
func New ¶
New opens a ClickHouse connection, ensures the schema, constructs the WAL segment queue, and drains any segments left from a previous run.
func (*Sink) Dropped ¶
Dropped returns the number of records dropped due to the WAL maxSegments cap.