Documentation
¶
Overview ¶
Package eventlog is the durable record of what Kivgraph did: when it indexed and for how long, which tool a client called and whether it answered, and when a server came up or went down.
It exists because none of that survived the process. The per-tool latency in internal/metrics is atomics in a map, minted fresh by every serve and discarded when it exits; the stage durations of a rebuild are printed to stderr and dropped. A reader that runs as its own process -- which is what `kivgraph logs` and `kivgraph tool-stats` are -- could observe neither.
The store is one append-only JSON-lines file. That choice is what makes it safe for the several processes that write it at once: a record is a single write of well under a pipe buffer to a file opened O_APPEND, which POSIX keeps whole and unmixed. Nothing here holds a lock across processes, and nothing here reads before writing.
Index ¶
Constants ¶
const ( // StatusOK marks work that finished as asked. StatusOK = "ok" // StatusError marks work that failed. StatusError = "error" )
Status is the outcome of a completed unit of work.
const DefaultMaxBytes = 8 << 20
DefaultMaxBytes is the size at which the live file is rotated. One rotation is kept, so the store costs at most twice this on disk.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Time time.Time `json:"ts"`
Level Level `json:"level"`
Kind Kind `json:"kind"`
Message string `json:"msg"`
// PID names the process that emitted the event, so a machine running
// three servers can be told apart from one running a single server.
PID int `json:"pid,omitempty"`
// Tool, Status and DurationMS describe a completed call or pass. A
// duration is a pointer because zero milliseconds is a real answer and
// "not timed" is a different one.
Tool string `json:"tool,omitempty"`
Status string `json:"status,omitempty"`
DurationMS *float64 `json:"duration_ms,omitempty"`
Stage string `json:"stage,omitempty"`
Repository string `json:"repository,omitempty"`
Generation string `json:"generation,omitempty"`
// Results is what a tool returned, Symbols what a pass produced.
Results *int64 `json:"results,omitempty"`
Symbols *int64 `json:"symbols,omitempty"`
// Error carries the rendered failure. Tool failures arrive as
// "CODE: message", so the stable code survives without a second field.
Error string `json:"error,omitempty"`
}
Event is one record. Its fields are a closed set rather than a free-form attribute bag: every producer is in this repository, and a fixed shape is what lets a reader render columns in a stable order and aggregate without guessing at types.
func Read ¶
func Read(path string, options ReadOptions) ([]Event, error)
Read answers the matching events in chronological order. A store that does not exist yet is not an error: it is a machine that has not run anything.
A line that does not parse is skipped rather than failing the read. The file is written by several processes at once and may hold a record from a version that knew fields this one does not; refusing to show the rest would turn a harmless unknown into an outage of the only view a reader has.
func (Event) WithDuration ¶
WithDuration returns the event carrying elapsed, in milliseconds.
func (Event) WithResults ¶
WithResults returns the event carrying a returned-row count.
func (Event) WithSymbols ¶
WithSymbols returns the event carrying a produced-symbol count.
type Kind ¶
type Kind string
Kind is the subsystem an event came from. It is what a reader filters on and what decides the badge a rendered line carries.
type Level ¶
type Level string
Level is the severity of an event, kept as a string so the file stays readable without this package.
type ReadOptions ¶
type ReadOptions struct {
// Since drops events older than this instant.
Since time.Time
// Kinds keeps only these kinds. Empty keeps every kind.
Kinds []Kind
// Tool keeps only events naming this tool. Empty keeps every tool.
Tool string
// FailuresOnly keeps only events that did not answer.
FailuresOnly bool
// Limit keeps at most this many of the newest matching events. Zero or
// less keeps all of them.
Limit int
}
ReadOptions narrows a read. The zero value reads everything the store holds.
type Summary ¶
type Summary struct {
Tools []ToolSummary `json:"tools"`
Calls int `json:"calls"`
OK int `json:"ok"`
Failed int `json:"failed"`
First time.Time `json:"first,omitempty"`
Last time.Time `json:"last,omitempty"`
}
Summary is the whole aggregation, ordered so a reader sees the busiest tool first and so two runs over the same events render identically.
type ToolSummary ¶
type ToolSummary struct {
Tool string `json:"tool"`
Calls int `json:"calls"`
OK int `json:"ok"`
Failed int `json:"failed"`
Mean time.Duration `json:"mean_ns"`
Median time.Duration `json:"median_ns"`
P95 time.Duration `json:"p95_ns"`
Max time.Duration `json:"max_ns"`
Last time.Time `json:"last"`
LastFail string `json:"last_failure,omitempty"`
}
ToolSummary is what one tool did over the events it was summarised from.
Percentiles are here because the store keeps every individual call rather than a running sum: internal/metrics deliberately retains latency as count, total and maximum to avoid an unbounded sample list in a live process, which buys a mean and a worst case and nothing in between. A reader over the file pays for the sample once, so it can answer the question a mean hides -- a tool whose median is fast and whose tail is not.
func (ToolSummary) SuccessRate ¶
func (summary ToolSummary) SuccessRate() (float64, bool)
SuccessRate answers the share of calls that answered, in the range 0..1. A tool with no calls has no rate, so it answers 0 alongside false.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer appends events to the store. A nil *Writer is a working sink that discards, so a caller that could not open the file needs no branch.
func OpenWithLimit ¶
OpenWithLimit is Open with an explicit rotation threshold.