logsdb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
}

DB wraps *sql.DB with the domain-specific queries the daemon needs.

func Open

func Open(path string) (*DB, error)

Open creates or opens the SQLite database at path and applies the schema. path may be ":memory:" for tests.

func (*DB) CountByService

func (d *DB) CountByService(ctx context.Context, since int64) (map[string]int, error)

CountByService returns a map of serviceID → 7-day error count, used for the left-rail badges.

func (*DB) ErrorByID

func (d *DB) ErrorByID(ctx context.Context, id int64) (*ErrorEvent, error)

ErrorByID returns a single event for the detail view.

func (*DB) InsertErrorEvent

func (d *DB) InsertErrorEvent(ctx context.Context, e ErrorEvent) (bool, error)

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

func (d *DB) ListServices(ctx context.Context) ([]Service, error)

ListServices returns services ordered by ID for stable UI rendering.

func (*DB) LoadCursor

func (d *DB) LoadCursor(ctx context.Context, serviceID string) (int64, bool, error)

LoadCursor returns the last persisted polling cursor for serviceID. Returns (0, false, nil) when no cursor exists yet.

func (*DB) PruneServices

func (d *DB) PruneServices(ctx context.Context, keep []string) error

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

func (d *DB) RecentErrors(ctx context.Context, serviceID string, limit int) ([]ErrorEvent, error)

RecentErrors returns up to limit events for serviceID, newest first.

func (*DB) SaveCursor

func (d *DB) SaveCursor(ctx context.Context, serviceID string, lastTS int64) error

SaveCursor persists the polling cursor for serviceID.

func (*DB) Sweep

func (d *DB) Sweep(ctx context.Context, olderThan int64) (int64, error)

Sweep deletes events older than olderThan (ms epoch). Returns rows removed.

func (*DB) UpsertService

func (d *DB) UpsertService(ctx context.Context, s Service) error

UpsertService replaces the row for s.ID. Called at daemon startup for every registered service after log group resolution.

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.

type Service

type Service struct {
	ID       string
	Name     string
	Env      string
	Region   string
	Runtime  string
	LogGroup string
	RepoPath string
}

Service is the row stored in the services table.

Jump to

Keyboard shortcuts

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