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) ErrorCode ¶ added in v0.9.2
ErrorCode is the stable code a failed tool call carries.
It is read back out of Error rather than kept in a field of its own, which is the shape the writer chose on purpose: a tool failure is rendered as "CODE: message", so the classification already survives in the file. That makes it readable from logs written before anything knew to classify them, which is the only reason the five-day measurement in LUQUE-2235 can be checked against the code that answers it.
func (Event) Failed ¶
Failed reports whether the event describes work that did not answer.
A refusal is one of these: it returns no rows, so it takes the error path and is recorded here as one. Telling the two apart is the reader's job and needs the tool vocabulary, which this package does not have -- see ErrorCode and Summarize.
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"`
Refused int `json:"refused"`
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.
func Summarize ¶
Summarize aggregates the tool events among events. Events of another kind are ignored, so a caller may hand it an unfiltered read.
refusals are the error codes that mean the call declined by design rather than failed. They are a parameter because the vocabulary belongs to the tool surface and this package is below it; a caller that passes none gets the count that sums the two, which is what every caller got before the split and is the number LUQUE-2235 exists to stop publishing.
type ToolSummary ¶
type ToolSummary struct {
Tool string `json:"tool"`
Calls int `json:"calls"`
OK int `json:"ok"`
// Refused is the count of calls that declined by design. It is its own
// column and not a subtraction from Failed, because the two do not mean
// the same thing in either direction: a refusal that rises is people
// asking about common names, which is the tool working.
Refused int `json:"refused"`
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.