Documentation
¶
Overview ¶
Package metrics exposes the gateway's Prometheus instrumentation on /metrics.
All collectors are registered on a dedicated *prometheus.Registry created per Metrics rather than on the global default registry. Using a private registry avoids duplicate-registration panics, keeps test runs isolated, and gives callers explicit control over what is exposed.
It reports tool-call counts keyed by (client, downstream, decision), call latency histograms by downstream, downstream health and circuit-breaker state, stdio pool gauges and exhaustion fast-fails, and a fail-closed counter for security records that could not be audited.
The exported update methods take plain string labels so the package depends on no other internal package; callers are responsible for label discipline (bounded, low-cardinality label values).
Index ¶
- Constants
- type Metrics
- func (m *Metrics) AuditUnrecordable()
- func (m *Metrics) Handler() http.Handler
- func (m *Metrics) PoolExhausted(downstream string)
- func (m *Metrics) RecordCall(client, downstream, decision string, latency time.Duration)
- func (m *Metrics) Registry() *prometheus.Registry
- func (m *Metrics) SetBreakerState(downstream string, state int)
- func (m *Metrics) SetDownstreamUp(downstream string, up bool)
- func (m *Metrics) SetPoolInUse(downstream string, n int)
Constants ¶
const ( // BreakerClosed indicates the breaker is closed: calls flow normally. BreakerClosed = 0 // BreakerHalfOpen indicates the breaker is half-open: a single probe is // permitted to test recovery. BreakerHalfOpen = 1 // BreakerOpen indicates the breaker is open: calls fast-fail. BreakerOpen = 2 )
Breaker state encoding for the portcullis_breaker_state gauge. The numeric encoding is part of the exposed contract; dashboards and alerts depend on it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is the gateway's Prometheus metrics surface. It owns a private registry and the collectors registered on it, and provides typed update methods so callers maintain label discipline. A Metrics is safe for concurrent use: every method delegates to a concurrency-safe collector.
func New ¶
func New() *Metrics
New builds a Metrics with a fresh registry and all collectors constructed and registered. Each call returns an independent instance with its own registry, so repeated construction never panics on duplicate registration.
func (*Metrics) AuditUnrecordable ¶
func (m *Metrics) AuditUnrecordable()
AuditUnrecordable increments the counter of security records that could not be audited. The gateway fails closed when this happens, so a rising value is a security-relevant signal.
func (*Metrics) Handler ¶
Handler returns an http.Handler that serves the registered metrics in the Prometheus exposition format. Mount it at /metrics.
func (*Metrics) PoolExhausted ¶
PoolExhausted increments the counter of stdio pool exhaustion fast-fails for a downstream.
func (*Metrics) RecordCall ¶
RecordCall records one completed tool call: it increments the call counter for (client, downstream, decision) and observes latency against the per-downstream histogram. decision is the policy decision or reason code.
func (*Metrics) Registry ¶
func (m *Metrics) Registry() *prometheus.Registry
Registry returns the private registry the collectors are registered on. It is the source for the Metrics.Handler and is exposed so callers can gather or extend the metric set (for example, registering process or build-info collectors) without reaching for the global default.
func (*Metrics) SetBreakerState ¶
SetBreakerState sets the circuit-breaker state gauge for a downstream using the BreakerClosed, BreakerHalfOpen, and BreakerOpen encoding.
func (*Metrics) SetDownstreamUp ¶
SetDownstreamUp sets the health gauge for a downstream: 1 when up, 0 when down.
func (*Metrics) SetPoolInUse ¶
SetPoolInUse sets the gauge of stdio subprocesses currently checked out of the pool for a downstream.