file

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

func NewReader(path string) *Reader

NewReader constructs a Reader for path. Path must match the Sink the relay is currently writing to.

func (*Reader) Events

func (r *Reader) Events(_ context.Context, q usage.EventQuery) ([]usage.Event, error)

Events streams the file, applies filters, returns the newest matching events up to q.Limit.

func (*Reader) Summary

Summary streams the file, applies filters, builds per-group aggregates including latency percentiles.

func (*Reader) TimeSeries

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

func NewSink(path string) (*Sink, error)

NewSink opens (creating, append-mode) the given path for the Sink. Caller is responsible for fsync semantics if needed.

func NewSinkFromWriter

func NewSinkFromWriter(w io.Writer) *Sink

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.

func (*Sink) Write

func (s *Sink) Write(ev usage.Event) error

Write encodes ev as one JSON line. The json.Encoder appends '\n' after each value, so output is JSONL-compatible.

Jump to

Keyboard shortcuts

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