clickhouse

package
v0.0.1-dev.137 Latest Latest
Warning

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

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

Documentation

Overview

Package clickhouse implements observe.LogStore against a ClickHouse backend (the analytical optional sink). It lowers the Query AST to SQL (see sql.go) and writes via batched INSERT. It supports both the Core and Advanced capability tiers: raw SQL mode, percentiles on arbitrary fields, and high-cardinality field filters.

Hot fields (namespace, service, instance, node, level, stream) are promoted to typed columns; the remaining labels live in a Map(String, String) column and the raw line carries a token bloom-filter skip index. Unlike Loki, ClickHouse is local-disk-first, so long retention uses S3 *tiering* — a TTL move-to-volume against a server-configured storage policy (see schema.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DSN is the ClickHouse connection string
	// (e.g. clickhouse://user:pass@host:9000/runesight).
	DSN string

	// Table is the target MergeTree table for log rows (default "logs").
	Table string

	// Database is the target database (default "runesight").
	Database string

	// DialTimeout bounds connection establishment. Zero uses the driver default.
	DialTimeout time.Duration

	// AutoMigrate runs EnsureSchema (CREATE DATABASE/TABLE) on first connect so
	// the backend works zero-config. Operators who manage their own schema can
	// leave it false.
	AutoMigrate bool

	// StoragePolicy is the server-configured ClickHouse storage policy that
	// defines the hot (local) and cold (s3) volumes. Empty disables tiering and
	// the move-to-volume TTL.
	StoragePolicy string

	// S3Volume is the volume name within StoragePolicy that aged parts move to
	// (default "s3"). Only used when HotDays > 0.
	S3Volume string

	// HotDays moves parts older than this to the S3 volume. Zero keeps all parts
	// on the hot disk.
	HotDays int

	// RetentionDays deletes parts older than this. Zero keeps data indefinitely.
	RetentionDays int
}

Config configures the ClickHouse store.

type Store

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

Store is the ClickHouse-backed observe.LogStore.

func New

func New(cfg Config) (*Store, error)

New constructs a ClickHouse store. It does not dial; call Health (or any I/O method) to establish the connection lazily.

func (*Store) Capabilities

func (s *Store) Capabilities() observe.Capabilities

Capabilities reports the ClickHouse capability handshake: Advanced tier (which implies Core). Enables the dashboard's SQL mode and advanced widgets.

func (*Store) Close

func (s *Store) Close() error

Close releases the connection pool.

func (*Store) EnsureSchema

func (s *Store) EnsureSchema(ctx context.Context) error

EnsureSchema creates the database and log table (idempotent). Safe to call at startup; AutoMigrate calls it lazily on first use.

func (*Store) Execute

func (s *Store) Execute(ctx context.Context, q *observe.Query) (observe.ResultStream, error)

Execute lowers the AST to SQL and streams rows or samples. RawSQL is run verbatim (Advanced tier) with a generic column scan.

func (*Store) Health

func (s *Store) Health(ctx context.Context) error

Health pings the ClickHouse pool.

func (*Store) Labels

func (s *Store) Labels(ctx context.Context, sel observe.Selector) ([]observe.LabelValue, error)

Labels enumerates label names (sel.Name=="") or the ranked values of a named dimension via GROUP BY ... ORDER BY count() DESC.

func (*Store) Write

func (s *Store) Write(ctx context.Context, batch []observe.LogRecord) error

Write persists a batch via a single batched INSERT. The clickhouse-go std driver accumulates the prepared statement's Exec calls and ships them as one native block on Commit.

Jump to

Keyboard shortcuts

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