Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteAttachmentRows(ctx context.Context, db *sql.DB, table string, eventUUIDs []string) error
- func InitFacets(ctx context.Context, db *sql.DB) error
- func InitSearch(ctx context.Context, db *sql.DB) error
- func Open(dsn string) (*sql.DB, error)
- func OpenPooled(dsn string, maxOpen int) (*sql.DB, error)
- type AttachmentStore
- type FacetFunc
- type HistogramBucket
- type Migration
- type Migrator
- type SQLiteStore
- func (s *SQLiteStore) BackfillFacets(ctx context.Context) error
- func (s *SQLiteStore) BackfillSearch(ctx context.Context) error
- func (s *SQLiteStore) Delete(ctx context.Context, uuid string) error
- func (s *SQLiteStore) DeleteAll(ctx context.Context, opts event.DeleteOptions) error
- func (s *SQLiteStore) FacetCounts(ctx context.Context, opts event.FindOptions, perKey int) (map[string][]event.FacetCount, error)
- func (s *SQLiteStore) FindAll(ctx context.Context, opts event.FindOptions) ([]event.Event, error)
- func (s *SQLiteStore) FindByUUID(ctx context.Context, uuid string) (*event.Event, error)
- func (s *SQLiteStore) Histogram(ctx context.Context, opts event.FindOptions, bucketSec int64) ([]HistogramBucket, int64, error)
- func (s *SQLiteStore) OnDelete(fn func(uuids []string))
- func (s *SQLiteStore) Pin(ctx context.Context, uuid string) error
- func (s *SQLiteStore) SetFacetFunc(fn FacetFunc)
- func (s *SQLiteStore) SetSearchFunc(fn SearchFunc)
- func (s *SQLiteStore) Store(ctx context.Context, ev event.Event) error
- func (s *SQLiteStore) Unpin(ctx context.Context, uuid string) error
- func (s *SQLiteStore) UpdatePayload(ctx context.Context, uuid string, payload json.RawMessage) error
- type SearchFunc
Constants ¶
const MaxFacetValuesPerKey = 50
MaxFacetValuesPerKey caps the values FacetCounts returns for one key.
const MaxHistogramBuckets = 1440
MaxHistogramBuckets caps the buckets of one histogram: a wider window gets a wider bucket.
Variables ¶
var CoreMigrations embed.FS
Functions ¶
func DeleteAttachmentRows ¶
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
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
InitSearch creates the trigger that removes an event's search rows with the event (see InitFacets).
func OpenPooled ¶
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.
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 (*Migrator) AddFromFS ¶
AddFromFS registers all .sql files from an embedded filesystem. Files are expected to be named like: 2024_01_01_000000_description.sql
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) 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 (*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) 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) 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.