auditqueue

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auditqueue is a durable, queue-backed auditlog.Recorder: Record enqueues the audit entry onto a skit queue (one cheap INSERT on the request path) and the workers of the queue (NewWorkers) drain it into the audit core. Use it when audit loss on a crash is unacceptable or to smooth write spikes; for the lowest latency with strict per-model ordering use auditlog.AsyncRecorder instead.

Ordering note: the queue does not guarantee per-model order across consumers. Core.Create retries on a version collision (so no row is lost), but if two changes to one model are processed out of order their stored version order can differ from real time. Run a single consumer, or use AsyncRecorder, when strict ordering matters.

Index

Constants

View Source
const (
	// Queue is the queue the audit entries go through.
	Queue = "auditlog"
	// Kind is the queue task kind for audit entries.
	Kind = "auditlog.record"
)

Variables

This section is empty.

Functions

func NewWorkers added in v0.14.0

func NewWorkers(q *queue.PG, core *auditlog.Core, log *slog.Logger, cfg WorkerConfig) ([]worker.Runnable, error)

NewWorkers returns the workers of Queue (queue.Workers), which record the audit entries through core. A payload that does not decode goes to the dead letters; a failed record is retried with backoff. Supervise the workers in a worker.Group. log may be nil.

It returns an error only if wiring the queue fails — which cannot happen here, as the single registration uses a constant Kind and a non-nil handler.

Types

type Enqueuer added in v0.14.0

type Enqueuer interface {
	Schedule(ctx context.Context, p queue.Params) (inserted bool, err error)
}

Enqueuer schedules a task on a queue; *queue.PG implements it.

type Recorder

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

Recorder enqueues audit entries onto a queue. It implements auditlog.Recorder.

func NewRecorder

func NewRecorder(q Enqueuer, log *slog.Logger) *Recorder

NewRecorder builds a queue-backed recorder.

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, entry auditlog.NewAuditLog)

Record enqueues entry as a task of Queue (best-effort: a failed enqueue is logged, not returned). The workers later write it through the audit core.

type WorkerConfig

type WorkerConfig struct {
	// Interval is the wait after a poll that found no entry (default 1s).
	Interval time.Duration
	// Batch caps the entries claimed at once (default 100).
	Batch int
	// Metrics is the registry for the skit_queue_* metrics of the audit queue
	// and the skit_worker_* metrics of its loops; nil — metrics off.
	Metrics prometheus.Registerer
}

WorkerConfig configures the workers of the audit queue.

Jump to

Keyboard shortcuts

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