events

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package events owns operator telemetry: append-only event records with free-form metadata keys, retention pruning, and filtered queries for GET /api/events. All writes run through one service; no other package touches the events tables directly.

Index

Constants

View Source
const (
	SeverityDebug = 0
	SeverityInfo  = 1
	SeverityWarn  = 2
	SeverityError = 3
	SeverityFatal = 4
)

Severity levels for event records.

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 500
)

DefaultLimit bounds parameterless queries. MaxLimit caps clients.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID        int64      `json:"id"`
	Timestamp time.Time  `json:"timestamp"`
	Severity  int        `json:"severity"`
	Message   string     `json:"message"`
	Keys      []KeyValue `json:"keys"`
}

Entry is one event record with its metadata keys.

type KeyFilter

type KeyFilter struct {
	Key   string
	Value *string
}

KeyFilter is one filter.<key>[=<value>] or exclude.<key>[=<value>] predicate. A nil Value checks key existence only.

type KeyValue

type KeyValue struct {
	Key   string  `json:"key"`
	Value *string `json:"value"`
}

KeyValue is one metadata entry on an event.

type Query

type Query struct {
	Severity *int
	ID       *int64
	Start    *time.Time
	End      *time.Time
	Filters  []KeyFilter
	Excludes []KeyFilter
	Limit    int
}

Query carries the GET /api/events parameters.

type Service

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

Service persists and queries events on the events handle.

func New

func New(database *db.Database, retentionDays int) (*Service, error)

New builds a Service on the events handle. RetentionDays must be at least 1; construction fails otherwise so miswiring surfaces at startup.

func (*Service) Append

func (s *Service) Append(ctx context.Context, timestamp time.Time, severity int, message string, keys map[string]string) error

Append persists one event with its metadata keys in one transaction.

func (*Service) Prune

func (s *Service) Prune(ctx context.Context) error

Prune deletes rows older than the retention window and reclaims pages.

func (*Service) Query

func (s *Service) Query(ctx context.Context, query Query) ([]Entry, error)

Query runs a filtered event query. ID mode returns at most one entry. Otherwise severity/start/end narrow the record scan, inclusions resolve to record IDs in bounded chunks, exclusions drop rows in Go, and keys assemble per record. Limit defaults to DefaultLimit and clamps to MaxLimit.

func (*Service) SetLogger

func (s *Service) SetLogger(l *slog.Logger)

SetLogger wires structured logging.

func (*Service) Start

func (s *Service) Start(ctx context.Context)

Start launches hourly retention pruning. It stops when ctx is cancelled.

Jump to

Keyboard shortcuts

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