Documentation
¶
Overview ¶
Package dumps receives, buffers, and fans out PHP `dump()`/`dd()` events captured by the lerd dump bridge (auto_prepend_file). The wire format is newline-delimited JSON. Production lerd-ui listens on a per-user Unix socket; tests bind TCP loopback. See docs/features/dumps.md.
Index ¶
- Constants
- type Context
- type Event
- type FilterOpts
- type Hub
- type Ring
- type Server
- func (s *Server) Addr() string
- func (s *Server) Clear()
- func (s *Server) Close() error
- func (s *Server) Filter(opts FilterOpts) []Event
- func (s *Server) Len() int
- func (s *Server) Push(e Event)
- func (s *Server) Snapshot() []Event
- func (s *Server) Subscribe() (<-chan Event, func())
- func (s *Server) Subscribers() int
- type Source
Constants ¶
const DefaultAddr = "127.0.0.1:9913"
DefaultAddr is the loopback bind address the receiver listens on when callers ask for tcp. Picked to avoid clashing with Symfony's `var-dump-server` default (9912) so users who already run it for some other purpose don't see surprise interceptions.
const DefaultCapacity = 500
DefaultCapacity is the maximum number of events the ring keeps before it overwrites the oldest entry. Sized to match the web LogViewer's 500-line cap so the in-memory budget for either feed is similar.
const DefaultNetwork = "unix"
DefaultNetwork is the listen network used by lerd-ui. Unix sockets are the default because the FPM containers can already reach the host home directory via the %h:%h bind mount — using a TCP loopback listener would mean opening the receiver to the entire host network ring just so containers could route through host.containers.internal.
const KindDump = "dump"
KindDump is the only event kind PR1 emits. Reserved values like "query"/"job" will be added by future PRs without bumping ProtocolVersion.
const ( // MaxLineBytes caps a single dump payload before bufio drops the line. // Sized to absorb VarCloner output for moderately large objects without // letting a runaway dump pin memory unboundedly. MaxLineBytes = 4 << 20 // 4 MiB )
const ProtocolVersion = 1
ProtocolVersion is the wire-format version this package understands. Events with a different `v` are dropped.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Type string `json:"type"`
Site string `json:"site,omitempty"`
Branch string `json:"branch,omitempty"`
Domain string `json:"domain,omitempty"`
Request string `json:"request,omitempty"`
PID int `json:"pid,omitempty"`
}
Context describes where a dump came from. Type is "fpm" (web request) or "cli" (artisan, tinker, queue worker). Empty fields are omitted on the wire. Branch is non-empty only when the event originated inside a git worktree (set by the bridge from LERD_BRANCH, injected by nginx for worktree vhosts and by lerd's CLI helpers when shelling into a worktree path).
type Event ¶
type Event struct {
V int `json:"v"`
ID string `json:"id"`
TS string `json:"ts"`
Kind string `json:"kind"`
Ctx Context `json:"ctx"`
Src Source `json:"src"`
Label string `json:"label,omitempty"`
Text string `json:"text,omitempty"`
Tree json.RawMessage `json:"tree,omitempty"`
Trunc bool `json:"trunc,omitempty"`
}
Event is one dump payload. Tree is opaque JSON (the bridge sends a pre-walked tree from VarCloner in a future PR; PR1 ships only `text`).
type FilterOpts ¶
type FilterOpts struct {
// Site exact-matches Ctx.Site when non-empty.
Site string
// Ctx exact-matches Ctx.Type ("fpm" or "cli") when non-empty.
Ctx string
// SinceID drops events whose ID is lexicographically <= SinceID.
SinceID string
// Limit caps the returned slice to the most recent N entries.
// Zero or negative means no limit.
Limit int
}
FilterOpts narrows a Snapshot. Zero-value fields are ignored.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub fans Events out to subscribers. Publish is non-blocking; subscribers that don't drain fast enough drop events instead of stalling the listener.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is a fixed-size ring buffer of Events safe for concurrent use. Snapshots are taken under a read lock and returned in insertion order.
func NewRing ¶
NewRing returns a ring with the given capacity. Non-positive capacity is replaced with DefaultCapacity.
func (*Ring) Clear ¶
func (r *Ring) Clear()
Clear empties the ring. Subsequent Snapshot() returns an empty slice.
func (*Ring) Filter ¶
func (r *Ring) Filter(opts FilterOpts) []Event
Filter returns a Snapshot filtered by opts, preserving insertion order.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server accepts loopback NDJSON connections from the PHP dump bridge, validates each line against ProtocolVersion, appends valid events to the ring, and publishes them to subscribers. Close once via Close().
func Listen ¶
Listen binds a TCP listener on addr and starts the accept loop. If addr is empty, DefaultAddr is used. The returned Server keeps running until Close is called or ctx is cancelled. Kept for tests and existing callers that already pass a TCP address; production lerd-ui uses ListenOn with "unix" so the receiver isn't reachable from the host network ring.
func ListenOn ¶
ListenOn binds on the given network and address. network is either "tcp" or "unix"; for "unix", any pre-existing socket at addr is removed first so a previous lerd-ui crash doesn't pin the path forever.
func (*Server) Clear ¶
func (s *Server) Clear()
Clear empties the ring. Active subscribers continue to receive events.
func (*Server) Close ¶
Close stops accepting connections, closes in-flight reads, and waits for outstanding goroutines to drain. Safe to call multiple times.
func (*Server) Filter ¶
func (s *Server) Filter(opts FilterOpts) []Event
Filter returns a filtered Snapshot.
func (*Server) Push ¶
Push injects an event as if it had arrived on the wire. Used by tests to avoid juggling sockets when only ring/hub semantics matter.
func (*Server) Subscribe ¶
Subscribe returns a buffered channel of new events plus an unsubscribe func.
func (*Server) Subscribers ¶
Subscribers returns the current subscriber count.