embedded

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

Documentation

Overview

Package embedded implements observe.LogStore as a lightweight in-process store that ships in runed by default. It is Core-tier: label match, line substring/regex grep, and count_over_time histograms (optionally grouped by a label dimension). It backs "every cluster gets persistent logs with zero extra services" (plan §2, §4.3).

The MVP keeps records in a bounded in-memory ring with a background retention sweeper. It is intentionally simple and lives entirely behind the observe.LogStore interface, so a purpose-built segment store (or the existing Badger store) can replace it later without touching any caller. See plan §8 (open question: embedded store engine).

Index

Constants

View Source
const (
	// DefaultMaxRecords bounds the in-memory ring. On overflow the oldest
	// records are evicted first (drop-oldest), mirroring the Outbox policy.
	DefaultMaxRecords = 500_000

	// DefaultRetention is the maximum age a record is kept before the sweeper
	// evicts it. Matches the runefile default of 7 days.
	DefaultRetention = 7 * 24 * time.Hour

	// DefaultQueryLimit caps returned log lines when a Query sets Limit=0.
	DefaultQueryLimit = 1000
)

Defaults can be overridden via Config.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxRecords bounds the in-memory ring. Zero uses DefaultMaxRecords.
	MaxRecords int

	// Retention is the max record age. Zero uses DefaultRetention; negative
	// disables age-based eviction (only the size bound applies).
	Retention time.Duration

	// Logger; defaults to the global logger with component "observe.embedded".
	Logger log.Logger

	// Dir, when non-empty, enables disk persistence: the store writes a
	// write-ahead log under this directory (node-local, under the runed data
	// dir) and replays it on startup so logs survive a runed restart. Empty =
	// in-memory only (tests, ephemeral). Persistence is best-effort — a disk
	// failure logs a warning and degrades to in-memory rather than erroring.
	Dir string

	// MaxDiskBytes is the hard cap on WAL disk usage (drop-oldest segments).
	// Zero uses the package default. Only applies when Dir is set.
	MaxDiskBytes int64
	// contains filtered or unexported fields
}

Config configures the embedded store.

type Store

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

Store is the embedded, in-process observe.LogStore.

func New

func New(cfg Config) *Store

New constructs an embedded store and starts its retention sweeper. Call Close to stop the sweeper.

func (*Store) Capabilities

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

Capabilities reports the embedded store handshake: Core tier only. No raw SQL, no percentiles, no cheap high-cardinality filters.

func (*Store) Close

func (s *Store) Close() error

Close stops the retention sweeper. Safe to call multiple times.

func (*Store) Execute

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

Execute runs a Core-tier query against the in-memory ring. RawSQL is rejected (Advanced tier only). Metric queries (Aggregation set) yield a count/rate/ bytes histogram; everything else yields filtered log rows.

func (*Store) Health

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

Health is always healthy for the in-process store.

func (*Store) Labels

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

Labels enumerates label names (Selector.Name == "") or the values of a named dimension, ranked by occurrence count. Honours Selector.Match and the time window.

func (*Store) Len

func (s *Store) Len() int

Len returns the current record count. Useful for metrics and tests.

func (*Store) Stats

func (s *Store) Stats() observe.StoreStats

Stats reports the store's current footprint for the dashboard Sources page.

func (*Store) Write

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

Write appends a batch to the ring, evicting the oldest records if the size bound is exceeded. Safe for concurrent callers.

Jump to

Keyboard shortcuts

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