Documentation
¶
Overview ¶
Package file is the JSONL file backend for usage logging: a Sink that appends one event per line and a Reader that scans the same file. It is the zero-dependency default backend — durable enough for single-pod and dogfood deployments, and the on-disk WAL the ClickHouse backend replays from. Implements usage.Sink and usage.Reader.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a usage.Reader backed by the same JSONL file Sink writes to. Linear scan per query — fine for dogfood files (MB range, thousands of events). For production-scale (millions of events, GB-scale files), use the ClickHouse backend instead.
func NewReader ¶
NewReader constructs a Reader for path. Path must match the Sink the relay is currently writing to.
func (*Reader) Events ¶
Events streams the file, applies filters, returns the newest matching events up to q.Limit.
func (*Reader) Summary ¶
func (r *Reader) Summary(_ context.Context, q usage.SummaryQuery) (usage.SummaryResult, error)
Summary streams the file, applies filters, builds per-group aggregates including latency percentiles.
func (*Reader) TimeSeries ¶
func (r *Reader) TimeSeries(_ context.Context, q usage.TimeSeriesQuery) (usage.TimeSeriesResult, error)
TimeSeries streams the file, applies filters, and buckets the matching events into time series via usage.Bucketize.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink appends one JSONL line per event to an io.Writer. Safe for concurrent Write; uses an internal mutex around the encoder.
Buffering is the OS's job — we don't add a userland buffer because power-loss durability matters more than write throughput for usage events. Callers that want batched writes wrap with a buffered writer.
func NewSink ¶
NewSink opens (creating, append-mode) the given path for the Sink. Caller is responsible for fsync semantics if needed.
func NewSinkFromWriter ¶
NewSinkFromWriter wraps an existing writer (useful for tests that hand in *bytes.Buffer or io.Discard).