Documentation
¶
Overview ¶
Package metrics is the gofer Prometheus instrumentation (E16, design §6). It owns a PRIVATE registry (not the global default) so the collector set is explicit, test-isolated and free of any unrelated process-wide registrations.
The job package must NOT depend on prometheus (design §6, hard constraint): it records lifecycle counters through the narrow job.MetricsSink interface, which *Metrics implements here. Every record method is nil-safe — a nil *Metrics is a no-op — so non-serve callers (tests, mcp) need no wiring.
Index ¶
- type Metrics
- func (m *Metrics) Handler() http.Handler
- func (m *Metrics) JobSubmitted(caller, project, agent, runner string)
- func (m *Metrics) JobTerminal(status, caller, project, agent, runner string, durationSec float64)
- func (m *Metrics) ObserveHTTP(method, route, status string, sec float64)
- func (m *Metrics) RegisterRuntimeGauges(stats func() (inflight, queued, running int), ...)
- func (m *Metrics) WorkflowTerminal(status string, durationSec float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds the collectors and the private registry. A nil *Metrics makes every record method a no-op (so non-serve callers/tests need no wiring) and is the "metrics disabled" sentinel everywhere it is injected.
func New ¶
func New() *Metrics
New builds a Metrics with a fresh private registry pre-loaded with the Go runtime + process collectors (goroutines / GC / memory / fds) and the five gofer collector vecs. It panics on a duplicate registration (MustRegister), which only happens on a programming error since the registry is private.
func (*Metrics) Handler ¶
Handler returns an http.Handler serving the registry in the Prometheus text exposition format. It reads the private registry only (never the global default), so the scrape output is exactly the collectors registered here.
func (*Metrics) JobSubmitted ¶
JobSubmitted records one job submission (job.MetricsSink). nil-safe. An empty caller (allow_empty_token direct submit) is labelled "anon" so the label is never the empty string.
func (*Metrics) JobTerminal ¶
JobTerminal records one job reaching a terminal state plus its end-to-end duration (job.MetricsSink). nil-safe. durationSec is submit→terminal (incl. queue wait), per design §6.3.
func (*Metrics) ObserveHTTP ¶
ObserveHTTP records one HTTP request's count + duration. nil-safe. route must be a bounded route TEMPLATE (e.g. /v1/jobs/:id), never a raw path — the caller (httpapi.metricsMiddleware) is responsible for the cardinality guard.
func (*Metrics) RegisterRuntimeGauges ¶
func (m *Metrics) RegisterRuntimeGauges(stats func() (inflight, queued, running int), workers func() (connected, inFlight int))
RegisterRuntimeGauges registers the in-flight / queued / workers gauges as GaugeFuncs: each is evaluated at scrape time by reading live in-memory state (design §6.4), so there is NO periodic loop and no increment/decrement bookkeeping to keep consistent. nil-safe. stats returns (inflight, queued, running); workers returns (connected, inFlight).
func (*Metrics) WorkflowTerminal ¶
WorkflowTerminal records one workflow reaching a terminal state plus its whole-chain submit→terminal duration (job.MetricsSink, P4/T4.3). nil-safe. status is the workflow terminal status (done/failed/cancelled).