Documentation
¶
Overview ¶
Package metrics owns every Prometheus metric Jō-ei exposes.
Hook rule: no other package imports client_golang. They expose optional observer hooks (funcs or small interfaces) and cmd/jo-ei wires them to the methods here.
To add a metric:
- Add its collector as an unexported field on a sub-struct of Metrics and register it in New (or a helper New calls) on m.Registry.
- Expose a nil-safe Wrap*/Register*/Observe* method that updates it.
- Constrain every label value to a closed set via oneOf; use newDurationHistogramOpts for latency histograms.
- Touch it in newFullyWired (metrics_test.go) so lint and drift tests see it.
Index ¶
- func UpstreamHosts(upstreamLists ...[]string) []string
- type BuildInfo
- type CacheStatter
- type Metrics
- func (m *Metrics) Handler() http.Handler
- func (m *Metrics) RegisterAsyncWriter(component string, snapshot func() storage.WriterStats)
- func (m *Metrics) RegisterCache(s CacheStatter, maxBytes int64)
- func (m *Metrics) RegisterCircuitBreaker(cb OpenHostsReporter, hosts []string)
- func (m *Metrics) RegisterScannerHealth(snapshot func() []health.ScannerHealth, types map[string]string)
- func (m *Metrics) ScanWaitObserver() func(time.Duration)
- func (m *Metrics) SetScanConcurrencyLimit(n int)
- func (m *Metrics) WrapAVScanner(name, engine string, s gate.AVScanner) gate.AVScanner
- func (m *Metrics) WrapCVEScanner(engine string, s gate.CVEScanner) gate.CVEScanner
- func (m *Metrics) WrapHandler(next http.Handler, route RouteFunc) http.Handler
- func (m *Metrics) WrapImageScanner(engine string, s dockerproxy.ImageScanner) dockerproxy.ImageScanner
- func (m *Metrics) WrapRecorder(r gate.Recorder) gate.Recorder
- func (m *Metrics) WrapTransport(rt http.RoundTripper, hosts []string) http.RoundTripper
- type OpenHostsReporter
- type RouteFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UpstreamHosts ¶
UpstreamHosts returns the deduplicated URL hosts (host[:port]) of every URL in upstreamLists, in first-seen order. Unparseable or host-less URLs are skipped. The result is the closed host-label set for upstream metrics.
Types ¶
type BuildInfo ¶
type BuildInfo struct{ Version, Commit string }
BuildInfo identifies the running binary.
type CacheStatter ¶
type CacheStatter interface {
Stats() (cache.CacheStats, error)
}
CacheStatter is the slice of the cache the size collector needs.
type Metrics ¶
type Metrics struct {
Registry *prometheus.Registry
// contains filtered or unexported fields
}
Metrics holds the registry and all Jō-ei collectors.
A nil *Metrics is valid and means "metrics disabled": every Wrap*/Register* method added to this type is nil-safe and becomes a no-op or pass-through.
func New ¶
New builds a private registry with Go runtime, process and build-info collectors. It never touches prometheus.DefaultRegisterer.
func (*Metrics) RegisterAsyncWriter ¶ added in v1.1.0
func (m *Metrics) RegisterAsyncWriter(component string, snapshot func() storage.WriterStats)
RegisterAsyncWriter exposes in-memory snapshots for the two bounded component names. Snapshot callbacks must never query storage or request a flush.
func (*Metrics) RegisterCache ¶
func (m *Metrics) RegisterCache(s CacheStatter, maxBytes int64)
RegisterCache exposes jo_ei_cache_size_bytes (read at scrape time) and, when maxBytes > 0, the constant jo_ei_cache_max_bytes. Call it once per process: a repeated call is ignored. A nil *Metrics or nil s is a no-op.
func (*Metrics) RegisterCircuitBreaker ¶
func (m *Metrics) RegisterCircuitBreaker(cb OpenHostsReporter, hosts []string)
RegisterCircuitBreaker exposes jo_ei_upstream_circuit_open, read from cb at scrape time, for each of hosts. Call it once per process: a repeated call is ignored (the first registration stays). A nil *Metrics is a no-op.
func (*Metrics) RegisterScannerHealth ¶
func (m *Metrics) RegisterScannerHealth(snapshot func() []health.ScannerHealth, types map[string]string)
RegisterScannerHealth exposes jo_ei_scanner_up, derived from snapshot at scrape time. types maps an AV scanner's display name to its engine type (e.g. "kaspersky" → "icap"): those names are the scanner label verbatim, with the type as the engine label; any other name goes through the closed set. Call it once per process: a repeated call is ignored. A nil *Metrics is a no-op.
func (*Metrics) ScanWaitObserver ¶
ScanWaitObserver returns a func recording an AV scan's concurrency-slot wait into jo_ei_scan_queue_wait_seconds, or nil when m is nil (so callers skip timing entirely).
func (*Metrics) SetScanConcurrencyLimit ¶
SetScanConcurrencyLimit records the configured AV scan concurrency limit. A nil *Metrics is a no-op.
func (*Metrics) WrapAVScanner ¶
WrapAVScanner instruments s under its configured display name (the scanner label; config keeps names unique) and engine type (clamav, icap; anything else is "other"). A nil *Metrics returns s unchanged.
func (*Metrics) WrapCVEScanner ¶
func (m *Metrics) WrapCVEScanner(engine string, s gate.CVEScanner) gate.CVEScanner
WrapCVEScanner instruments s as the given engine. A nil *Metrics returns s unchanged.
func (*Metrics) WrapHandler ¶
WrapHandler instruments next with request count, duration, in-flight and client-abort metrics. A nil *Metrics returns next unchanged.
func (*Metrics) WrapImageScanner ¶
func (m *Metrics) WrapImageScanner(engine string, s dockerproxy.ImageScanner) dockerproxy.ImageScanner
WrapImageScanner instruments s as the given engine and forwards Health. A nil *Metrics returns s unchanged.
func (*Metrics) WrapRecorder ¶
WrapRecorder counts every event in jo_ei_verdicts_total, then delegates to r. A nil *Metrics returns r unchanged.
func (*Metrics) WrapTransport ¶
func (m *Metrics) WrapTransport(rt http.RoundTripper, hosts []string) http.RoundTripper
WrapTransport instruments rt with upstream request count, duration, in-flight and error-reason metrics. hosts is the closed host-label set (see UpstreamHosts); any other request host is labelled "other". Install it as the outermost layer of the upstream transport chain so rate-limit waits and circuit-open fast-fails are visible. It never registers collectors. A nil *Metrics returns rt unchanged.
type OpenHostsReporter ¶
type OpenHostsReporter interface{ OpenHosts() []string }
OpenHostsReporter reports which upstream hosts currently have an open circuit. *httpx.CircuitBreaker implements it.
type RouteFunc ¶
RouteFunc maps a request path to a bounded route label.
func NewRouteFunc ¶
NewRouteFunc returns a RouteFunc that labels paths by first segment when it is one of proxyPrefixes ("v2" is reported as "docker"), and by fixed names for the console, API, health (/health and /ready) and favicon paths. Anything else is "other".