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 ¶
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 ¶
NewRecorder builds a queue-backed recorder.
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.