storage

package
v2.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxFacetValuesPerKey = 50

MaxFacetValuesPerKey caps the values FacetCounts returns for one key.

View Source
const MaxHistogramBuckets = 1440

MaxHistogramBuckets caps the buckets of one histogram: a wider window gets a wider bucket.

Variables

View Source
var CoreMigrations embed.FS

Functions

func DeleteAttachmentRows

func DeleteAttachmentRows(ctx context.Context, db *sql.DB, table string, eventUUIDs []string) error

DeleteAttachmentRows removes the rows of an attachments table (columns event_uuid, …) that belong to the given events. Modules call it from OnEventsDeleted; the files themselves are removed by AttachmentStore.

func InitFacets added in v2.14.0

func InitFacets(ctx context.Context, db *sql.DB) error

InitFacets creates the trigger that removes an event's facets with the event, whatever path deletes it (store, retention, module cleanup). It is not in the migration: the migration splitter cuts at ';'.

func InitSearch added in v2.14.0

func InitSearch(ctx context.Context, db *sql.DB) error

InitSearch creates the trigger that removes an event's search rows with the event (see InitFacets).

func Open

func Open(dsn string) (*sql.DB, error)

Open creates a new SQLite database connection with a single connection.

func OpenPooled

func OpenPooled(dsn string, maxOpen int) (*sql.DB, error)

OpenPooled opens the database with a pool of maxOpen connections.

A single connection is only required for writing: in WAL mode readers block neither the writer nor each other, while one shared connection turns every heavy SELECT into a queue for ingestion — the UI and the incoming events wait for each other.

There is one correctness requirement: WAL still allows a single writer, so with maxOpen > 1 the DSN needs busy_timeout, otherwise a second write fails with SQLITE_BUSY instead of waiting. Both that and _txlock=immediate are added when absent.

Types

type AttachmentStore

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

AttachmentStore provides file storage for attachments. Supports in-memory (default) and filesystem modes.

func NewAttachmentStore

func NewAttachmentStore(mode, dir string) *AttachmentStore

NewAttachmentStore creates an attachment store. mode: "memory" (default) or "filesystem" dir: base directory for filesystem mode (ignored for memory)

func (*AttachmentStore) DeleteByEvent

func (s *AttachmentStore) DeleteByEvent(eventUUID string)

DeleteByEvent removes all files for an event. An empty UUID or one that is not a single path element is ignored, so a bad value can never remove the base directory or a path outside it.

func (*AttachmentStore) Get

func (s *AttachmentStore) Get(path string) ([]byte, error)

Get retrieves attachment content.

func (*AttachmentStore) GetReader

func (s *AttachmentStore) GetReader(path string) (io.ReadCloser, error)

GetReader returns a reader for the attachment.

func (*AttachmentStore) Store

func (s *AttachmentStore) Store(path string, content []byte) error

Store saves attachment content. path format: "{eventUUID}/{filename}"

type FacetFunc added in v2.14.0

type FacetFunc func(eventType string, payload json.RawMessage) []event.Facet

FacetFunc returns the filterable values of a payload of an event type.

type HistogramBucket added in v2.14.0

type HistogramBucket struct {
	// T is the bucket start, unix seconds.
	T      int64          `json:"t"`
	Count  int            `json:"count"`
	Levels map[string]int `json:"levels"`
}

HistogramBucket is the number of events in one time bucket, split by level.

type Migration

type Migration struct {
	Name    string // e.g., "2024_01_01_000000_create_events_table.sql"
	Module  string // e.g., "core", "profiler"
	Content string
}

Migration represents a single SQL migration file.

type Migrator

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

Migrator collects and runs SQL migrations from all modules.

func NewMigrator

func NewMigrator(db *sql.DB) *Migrator

func (*Migrator) AddFromFS

func (m *Migrator) AddFromFS(moduleName string, fsys embed.FS, dir string) error

AddFromFS registers all .sql files from an embedded filesystem. Files are expected to be named like: 2024_01_01_000000_description.sql

func (*Migrator) AddSQL

func (m *Migrator) AddSQL(moduleName, name, content string)

AddSQL registers a raw SQL migration with a given name and module.

func (*Migrator) Run

func (m *Migrator) Run() error

Run executes all collected migrations sorted by filename. Uses a migrations tracking table to avoid re-running.

type SQLiteStore

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

SQLiteStore implements event.Store using SQLite.

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) *SQLiteStore

func (*SQLiteStore) BackfillFacets added in v2.14.0

func (s *SQLiteStore) BackfillFacets(ctx context.Context) error

BackfillFacets indexes the facets of events stored before facets existed.

func (*SQLiteStore) BackfillSearch added in v2.14.0

func (s *SQLiteStore) BackfillSearch(ctx context.Context) error

BackfillSearch indexes the search text of events stored before search existed.

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, uuid string) error

func (*SQLiteStore) DeleteAll

func (s *SQLiteStore) DeleteAll(ctx context.Context, opts event.DeleteOptions) error

func (*SQLiteStore) FacetCounts added in v2.14.0

func (s *SQLiteStore) FacetCounts(ctx context.Context, opts event.FindOptions, perKey int) (map[string][]event.FacetCount, error)

FacetCounts returns, per facet key, its values with the number of events matching opts (type, project, window, filters), most frequent first, at most perKey values per key (0 = MaxFacetValuesPerKey). A key's counts ignore the filter on that same key, so picking one host still shows the others. Limit and Offset of opts are ignored.

func (*SQLiteStore) FindAll

func (s *SQLiteStore) FindAll(ctx context.Context, opts event.FindOptions) ([]event.Event, error)

func (*SQLiteStore) FindByUUID

func (s *SQLiteStore) FindByUUID(ctx context.Context, uuid string) (*event.Event, error)

func (*SQLiteStore) Histogram added in v2.14.0

func (s *SQLiteStore) Histogram(ctx context.Context, opts event.FindOptions, bucketSec int64) ([]HistogramBucket, int64, error)

Histogram counts the events matching opts (type, project, window, filters, search) per bucket of bucketSec seconds, split by their level facet; events without a level only add to Count. Empty buckets are left out. It returns the bucket width used: bucketSec, or wider so the selection spans at most MaxHistogramBuckets buckets.

func (*SQLiteStore) OnDelete

func (s *SQLiteStore) OnDelete(fn func(uuids []string))

OnDelete registers fn to run after Delete or DeleteAll removed events. fn gets the UUIDs of the removed rows, so files kept outside SQLite (attachments, trace files) can be removed with them. Register hooks at startup, before the store is used.

func (*SQLiteStore) Pin

func (s *SQLiteStore) Pin(ctx context.Context, uuid string) error

func (*SQLiteStore) SetFacetFunc added in v2.14.0

func (s *SQLiteStore) SetFacetFunc(fn FacetFunc)

SetFacetFunc makes Store and UpdatePayload index the facets fn returns. Set it at startup, before the store is used; nil indexes nothing.

func (*SQLiteStore) SetSearchFunc added in v2.14.0

func (s *SQLiteStore) SetSearchFunc(fn SearchFunc)

SetSearchFunc makes Store and UpdatePayload index the text fn returns for GET /api/events?q=. Set it at startup; nil indexes nothing.

func (*SQLiteStore) Store

func (s *SQLiteStore) Store(ctx context.Context, ev event.Event) error

func (*SQLiteStore) Unpin

func (s *SQLiteStore) Unpin(ctx context.Context, uuid string) error

func (*SQLiteStore) UpdatePayload

func (s *SQLiteStore) UpdatePayload(ctx context.Context, uuid string, payload json.RawMessage) error

type SearchFunc added in v2.14.0

type SearchFunc func(eventType string, payload json.RawMessage) string

SearchFunc returns the text full-text search finds an event by, "" for none.

Jump to

Keyboard shortcuts

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