Documentation
¶
Overview ¶
Package logsdb is the SQLite persistence layer for the citadel-logs daemon.
The store is intentionally small: services, ingest cursors, and error events. Raw, non-error log lines are not persisted (errors carry the raw line in their own column). The daemon owns the lifecycle of the database file at /data/citadel-logs.db inside the container.
Index ¶
- type DB
- func (d *DB) CountByService(ctx context.Context, since int64) (map[string]int, error)
- func (d *DB) ErrorByID(ctx context.Context, id int64) (*ErrorEvent, error)
- func (d *DB) InsertErrorEvent(ctx context.Context, e ErrorEvent) (bool, error)
- func (d *DB) ListServices(ctx context.Context) ([]Service, error)
- func (d *DB) LoadCursor(ctx context.Context, serviceID string) (int64, bool, error)
- func (d *DB) PruneServices(ctx context.Context, keep []string) error
- func (d *DB) RecentErrors(ctx context.Context, serviceID string, limit int) ([]ErrorEvent, error)
- func (d *DB) SaveCursor(ctx context.Context, serviceID string, lastTS int64) error
- func (d *DB) Sweep(ctx context.Context, olderThan int64) (int64, error)
- func (d *DB) UpsertService(ctx context.Context, s Service) error
- type ErrorEvent
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB wraps *sql.DB with the domain-specific queries the daemon needs.
func Open ¶
Open creates or opens the SQLite database at path and applies the schema. path may be ":memory:" for tests.
func (*DB) CountByService ¶
CountByService returns a map of serviceID → 7-day error count, used for the left-rail badges.
func (*DB) InsertErrorEvent ¶
InsertErrorEvent writes an event; ON CONFLICT(cw_event_id) DO NOTHING dedupes across daemon restarts that re-poll the same window. Returns true if a new row was actually inserted.
func (*DB) ListServices ¶
ListServices returns services ordered by ID for stable UI rendering.
func (*DB) LoadCursor ¶
LoadCursor returns the last persisted polling cursor for serviceID. Returns (0, false, nil) when no cursor exists yet.
func (*DB) PruneServices ¶
PruneServices removes service rows whose IDs are not in keep. The FK cascade also clears their cursors and error events. Used on registry hot-reload.
func (*DB) RecentErrors ¶
RecentErrors returns up to limit events for serviceID, newest first.
func (*DB) SaveCursor ¶
SaveCursor persists the polling cursor for serviceID.
type ErrorEvent ¶
type ErrorEvent struct {
ID int64
ServiceID string
TS int64
Status sql.NullInt64
Level sql.NullString
Message string
RequestID sql.NullString
Stack sql.NullString
Raw string
LogStream sql.NullString
CWEventID sql.NullString
}
ErrorEvent is one persisted 500-class event.