tsdb

package
v0.1.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tsdb defines the embedded time-series store contract (spec §3.10): per-series ring buffers, 15s raw resolution for 24h + 5m downsampled for 30d. Implementation is task T-59; the fake lives in testutil.

Index

Constants

View Source
const (
	RawStep       = 15 * time.Second
	RawRetention  = 24 * time.Hour
	DownStep      = 5 * time.Minute
	DownRetention = 30 * 24 * time.Hour
)

Resolutions stored by the ring TSDB.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path is the flat file the rings persist to. Empty disables persistence
	// (in-memory only, e.g. tests).
	Path   string
	Clock  clock.Clock
	Logger *slog.Logger
}

Config configures a RingStore.

type Point

type Point struct {
	Time  time.Time
	Value float64
}

Point is one sample.

type RingStore

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

RingStore is the on-node ring TSDB (spec §3.10). Zero series persist to a flat file; a background goroutine flushes every 60s until Close.

func Open

func Open(cfg Config) *RingStore

Open builds a RingStore, loading any existing file (a missing or corrupt file starts empty with a warning) and starting the periodic flusher.

func (*RingStore) Close

func (s *RingStore) Close() error

Close stops the flusher and performs a final flush.

func (*RingStore) Flush

func (s *RingStore) Flush() error

Flush garbage-collects stale series then persists the rings to disk. A no-op when persistence is disabled (empty Path).

func (*RingStore) Keys

func (s *RingStore) Keys(scope, scopeID string) []SeriesKey

Keys lists series matching a scope filter. Empty scope matches all; empty scopeID matches all ids within the scope.

func (*RingStore) Query

func (s *RingStore) Query(key SeriesKey, since, until time.Time, step time.Duration) []Point

Query returns points in [since, until] at the resolution best fitting step: the 5m ring when step is at least DownStep, else the raw 15s ring.

func (*RingStore) Record

func (s *RingStore) Record(key SeriesKey, p Point)

Record adds a sample. Samples in the current or a newer raw slot are kept (same-slot re-samples overwrite last-write-wins); an older slot is dropped.

type SeriesKey

type SeriesKey struct {
	// Metric name: "cpu_percent", "memory_bytes", "rps", ...
	Metric string
	// Scope: "node", "instance", "env", "app".
	Scope string
	// ID of the scoped object.
	ScopeID string
}

SeriesKey identifies one series.

type Store

type Store interface {
	// Record adds a sample (typically every 15s per series). Out-of-order
	// samples older than the current slot are dropped.
	Record(key SeriesKey, p Point)
	// Query returns points in [since, until] at the best-fitting resolution
	// for step (RawStep or DownStep).
	Query(key SeriesKey, since, until time.Time, step time.Duration) []Point
	// Keys lists series matching a scope filter ("" matches all).
	Keys(scope, scopeID string) []SeriesKey
	// Flush persists ring state to disk (called periodically and on stop).
	Flush() error
	Close() error
}

Store is the per-node TSDB.

Jump to

Keyboard shortcuts

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