logstore

package
v0.2.1 Latest Latest
Warning

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

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

Documentation

Overview

Package logstore is the dedicated, bounded, append-only persistence layer for ingested node log lines. It owns its own bbolt database (logs.db) and is deliberately NOT part of the whole-file JSON state store: log volume must never trigger a full state rewrite. Storage is append-O(record), time-ordered by a server-assigned per-source sequence, and bounded by a per-source byte cap with oldest-first eviction so disk can never grow unbounded.

Index

Constants

View Source
const (
	// DefaultMaxSourceBytes caps stored (post-encode) bytes per source; the
	// oldest chunks are evicted on append once exceeded.
	DefaultMaxSourceBytes = 64 << 20 // 64 MiB
	// DefaultQueryLimit / MaxQueryLimit bound a single query's line count.
	DefaultQueryLimit = 200
	MaxQueryLimit     = 1000
)

Variables

This section is empty.

Functions

func EnvMaxSourceBytes

func EnvMaxSourceBytes(raw string) int64

EnvMaxSourceBytes parses an optional per-source byte cap override.

Types

type Filter

type Filter struct {
	SourceID  string
	Since     time.Time
	Until     time.Time
	Contains  string // case-insensitive substring; empty matches all
	Limit     int    // clamped to [1, MaxQueryLimit]; 0 => DefaultQueryLimit
	BeforeSeq uint64 // cursor: only chunks with Seq < BeforeSeq (0 => from newest)
}

Filter is a per-source query. Cross-source merge is the server's job.

type Meta

type Meta struct {
	FirstSeq     uint64    `json:"first_seq"`
	LastSeq      uint64    `json:"last_seq"`
	Bytes        uint64    `json:"bytes"`
	Lines        uint64    `json:"lines"`
	RotID        string    `json:"rot_id"`
	LastOff      uint64    `json:"last_off"`
	LastIngestAt time.Time `json:"last_ingest_at"`
}

Meta is the per-source bookkeeping record (also the stats projection).

type Result

type Result struct {
	Lines         []model.LogLine
	NextBeforeSeq uint64 // pass back as Filter.BeforeSeq to page older; 0 => no more
	Truncated     bool   // a stored chunk failed to decode and was skipped
}

Result is a newest-first page of lines.

type Store

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

Store is a bbolt-backed bounded log store.

func Open

func Open(path string, cipher secret.Cipher, maxSourceBytes int64) (*Store, error)

Open opens (creating if needed) the log store at path. A nil or disabled cipher stores chunks in plaintext; an enabled cipher seals each chunk as a unit. maxSourceBytes<=0 uses DefaultMaxSourceBytes.

func (*Store) Append

func (s *Store) Append(sourceID string, lines []model.LogLine, rotID string, lastOff uint64, at time.Time) (uint64, error)

Append packs lines into one chunk under the next sequence for sourceID, updates the source meta (rotID/lastOff/lastIngestAt from the batch context), and evicts oldest chunks until the per-source byte cap is honored. It returns the assigned chunk sequence. lines must already be truncated/validated by the caller; their Seq field is overwritten with the assigned sequence.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database.

func (*Store) FileSize

func (s *Store) FileSize() int64

FileSize returns the current on-disk size of the database in bytes.

func (*Store) Path

func (s *Store) Path() string

Path returns the on-disk path of the database file.

func (*Store) PurgeSource

func (s *Store) PurgeSource(sourceID string) error

PurgeSource drops a source's data bucket and meta (used on source delete).

func (*Store) Query

func (s *Store) Query(f Filter) (Result, error)

Query returns a newest-first page of lines for one source.

func (*Store) SourceBytesCap

func (s *Store) SourceBytesCap() uint64

SourceBytesCap reports the configured per-source byte cap (for diagnostics).

func (*Store) Stats

func (s *Store) Stats(sourceID string) (Meta, time.Time, time.Time, bool)

Stats returns the meta projection for a source (with computed first/last At).

Jump to

Keyboard shortcuts

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