metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

View Source
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

func (m *Metrics) Handler() http.Handler

Handler returns an http.Handler that serves the registered metrics in the Prometheus exposition format. Mount it at /metrics.

func (*Metrics) PoolExhausted

func (m *Metrics) PoolExhausted(downstream string)

PoolExhausted increments the counter of stdio pool exhaustion fast-fails for a downstream.

func (*Metrics) RecordCall

func (m *Metrics) RecordCall(client, downstream, decision string, latency time.Duration)

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

func (m *Metrics) SetBreakerState(downstream string, state int)

SetBreakerState sets the circuit-breaker state gauge for a downstream using the BreakerClosed, BreakerHalfOpen, and BreakerOpen encoding.

func (*Metrics) SetDownstreamUp

func (m *Metrics) SetDownstreamUp(downstream string, up bool)

SetDownstreamUp sets the health gauge for a downstream: 1 when up, 0 when down.

func (*Metrics) SetPoolInUse

func (m *Metrics) SetPoolInUse(downstream string, n int)

SetPoolInUse sets the gauge of stdio subprocesses currently checked out of the pool for a downstream.

Jump to

Keyboard shortcuts

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