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 ¶
- type Reader
- func (r *Reader) Count(_ context.Context, q usage.EventQuery, limit int) (int64, error)
- func (r *Reader) Events(_ context.Context, q usage.EventQuery) ([]usage.Event, error)
- func (r *Reader) Facet(_ context.Context, q usage.FacetQuery) ([]usage.FacetValue, error)
- func (r *Reader) Summary(_ context.Context, q usage.SummaryQuery) (usage.SummaryResult, error)
- func (r *Reader) TimeSeries(_ context.Context, q usage.TimeSeriesQuery) (usage.TimeSeriesResult, error)
- type Sink
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) Count ¶ added in v0.11.1
Count streams the file and counts the events Events would match, up to limit.
func (*Reader) Events ¶
Events streams the file, applies filters, returns the newest matching events up to q.Limit.
func (*Reader) Facet ¶ added in v0.11.1
func (r *Reader) Facet(_ context.Context, q usage.FacetQuery) ([]usage.FacetValue, error)
Facet streams the file, applies filters, and counts q.Dim's values via usage.TopValues.
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.
Nothing is buffered across calls: every Write and WriteBatch has reached the writer when it returns, so a process crash loses nothing accepted.
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).
func Stdout ¶
func Stdout() *Sink
Stdout is a convenience Sink wired to os.Stdout. Useful for development and CI where structured logs go to stdout for the container runtime to capture.