metrics

package
v0.167.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func (m *Metrics) Handler() http.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

func (m *Metrics) JobSubmitted(caller, project, agent, runner string)

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

func (m *Metrics) JobTerminal(status, caller, project, agent, runner string, durationSec float64)

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

func (m *Metrics) ObserveHTTP(method, route, status string, sec float64)

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

func (m *Metrics) WorkflowTerminal(status string, durationSec float64)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL