Documentation
¶
Overview ¶
Package requestlog records simulated-API request/response traffic to SQLite. Writes are asynchronous (off the request hot path) and bounded (ring + size cap).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a fan-out publisher of captured entries. Subscribers receive only events published AFTER they subscribe (no history); slow subscribers have events dropped (non-blocking) so a parked client never blocks recorders.
type Entry ¶
type Entry struct {
ID int64 `json:"id"`
Seq int64 `json:"seq"`
Ts string `json:"ts"` // RFC3339
Service string `json:"service"`
Transport string `json:"transport"` // http | grpc | ws
Method string `json:"method"`
Path string `json:"path"`
Status int `json:"status"`
DurationUs int64 `json:"duration_us"` // microseconds (sub-ms resolution)
ReqHeaders string `json:"req_headers"` // JSON, sensitive values redacted
ReqBody string `json:"req_body"` // capped
RespHeaders string `json:"resp_headers"` // JSON
RespBody string `json:"resp_body"` // capped
}
Entry is one captured request/response.
type Options ¶
type Options struct {
Ring int // keep at most this many newest entries (0 = unlimited)
MaxBytes int64 // rotate (delete oldest) when DB exceeds this (0 = unlimited)
WriteQueue int // async enqueue buffer size (default 1024)
}
Options configures the store.
type Query ¶
type Query struct {
Service string
Method string
Path string // substring match
Status int // 0 = any
Q string // free-text over path+req_body+resp_body
Since int64 // only entries with seq > Since (0 = no filter; gap-free backfill)
Limit int
Offset int
}
Query filters the history list.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder wraps a handler to capture req/resp into the store.
func NewRecorder ¶
NewRecorder builds a recorder bound to a service name. seq is a shared, engine-wide monotonic counter so entry Seq values are globally unique (needed for the live-feed gap-free ordering in Plan 2 and unique row labels).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the SQLite-backed request log.
func Open ¶
Open opens (or creates) the request log at path with the given options. Without options it defaults to Ring=1000, WriteQueue=1024.
func (*Store) Clear ¶
Clear removes every captured request (used by reset for deterministic runs). It waits for in-flight writes first so the table isn't cleared mid-write.
func (*Store) Close ¶
Close drains the async writer (if running), stops it, then closes the DB. It is idempotent. Draining before close guarantees in-flight writes are persisted and the single connection is released, so a caller reopening the same DB (e.g. a test restarting an engine in one state dir) does not hit SQLITE_BUSY.
func (*Store) Enqueue ¶
Enqueue hands an entry to the writer goroutine (non-blocking; drops on full). If no writer is running (store opened read-only), it persists synchronously.
func (*Store) Flush ¶
func (s *Store) Flush()
Flush blocks until all enqueued entries have been written by the writer goroutine. It is a no-op for read-only stores.