Documentation
¶
Overview ¶
Package live tracks what the node is doing right now and what it did a moment ago: the requests in flight on each model and a bounded ring of the ones that finished. It answers "the GPU spiked two minutes ago — was that flockd, which model, and for whom?".
It records facts about a request, never its content: model, kind, origin, times, token counts and an outcome word. No prompt, no output, no error text (runtime errors can quote input) and no identifier from outside the node — the id is a counter local to this process.
The hot path is one mutex-guarded map insert at start, one atomic add per token chunk, and one ring write at the end.
Index ¶
Constants ¶
const ( KindChat = "chat" KindCompletion = "completion" KindEmbedding = "embedding" KindDecision = "decision" )
Kinds of request (api/openapi.yaml RequestKind).
const ( // OriginLocal is the local API on 127.0.0.1 (/v1/*): the operator's // own tools. OriginLocal = "local" // OriginMesh is a coordinator dispatch: a customer request, or a // canary — a node cannot tell the two apart, by design. OriginMesh = "mesh" // OriginChallenge is a fingerprint challenge from the coordinator. OriginChallenge = "challenge" )
Origins: who asked (api/openapi.yaml RequestOrigin).
const ( OutcomeOK = "ok" OutcomeError = "error" OutcomeCancelled = "cancelled" OutcomeInvalidInput = "invalid_input" )
Outcomes of a finished request (api/openapi.yaml RequestOutcome).
const ( EventStarted = "request_started" EventFinished = "request_finished" )
SSE event names.
const DefaultCapacity = 200
DefaultCapacity is how many finished requests a Tracker keeps.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finished ¶
type Finished struct {
ID string `json:"id"`
Model string `json:"model"`
Kind string `json:"kind"`
Origin string `json:"origin"`
StartedAt time.Time `json:"started_at"`
DurationMS int64 `json:"duration_ms"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
Outcome string `json:"outcome"`
}
Finished is a request that ended.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is one in-flight request. A nil *Handle is inert.
type InFlight ¶
type InFlight struct {
ID string `json:"id"`
Model string `json:"model"`
Kind string `json:"kind"`
Origin string `json:"origin"`
StartedAt time.Time `json:"started_at"`
ElapsedMS int64 `json:"elapsed_ms"`
Tokens int `json:"tokens"`
}
InFlight is a request being served. Tokens is what has been generated so far (0 for embeddings and decisions, which generate nothing).
type Tracker ¶
type Tracker struct {
// Events, when set before use, receives request_started and
// request_finished.
Events *events.Hub
// contains filtered or unexported fields
}
Tracker holds the in-flight set and the recent ring. Safe for concurrent use; a nil *Tracker tracks nothing, so callers need no nil checks.
func (*Tracker) CountsByModel ¶
CountsByModel tallies the in-flight requests per model.