observability

package
v0.1.0-rc.39 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package observability provides process and service metrics without depending on one metrics provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationBucketsSeconds

func DurationBucketsSeconds() []float64

DurationBucketsSeconds returns independent boundaries shared by operation, HTTP, SQL, and driver-observed guard histograms. the final implicit +Inf bucket also counts operations longer than two minutes.

func ParseMetrics

func ParseMetrics(reader io.Reader) ([]*dto.MetricFamily, error)

ParseMetrics decodes Prometheus text exposition, retaining types and labels.

func ProcessHandler

func ProcessHandler(metrics http.Handler, ready func() bool) http.Handler

ProcessHandler serves private process health, readiness, and metrics.

Types

type DatabaseConnectionSnapshot

type DatabaseConnectionSnapshot struct {
	Open       int64
	Connecting int64
	Opened     int64
	Closed     int64
	Failed     int64
}

type DatabaseOperationSnapshot

type DatabaseOperationSnapshot struct {
	Operation      string
	ElapsedSeconds float64
}

type DatabaseSnapshot

type DatabaseSnapshot struct {
	Pool              *pgxpool.Stat
	Connections       map[string]DatabaseConnectionSnapshot
	ActiveOperations  []DatabaseOperationSnapshot
	OperationsOmitted int
}

DatabaseSnapshot is process-local database state collected without I/O.

type DurationSummary

type DurationSummary struct {
	Name        string            `json:"name"`
	Labels      map[string]string `json:"labels"`
	Count       uint64            `json:"count"`
	SumSeconds  float64           `json:"sum_seconds"`
	MeanSeconds float64           `json:"mean_seconds"`
	P50Seconds  *float64          `json:"p50_seconds"`
	P95Seconds  *float64          `json:"p95_seconds"`
	P99Seconds  *float64          `json:"p99_seconds"`
}

DurationSummary describes observations between two process-local snapshots. quantiles are linear estimates within classic histogram buckets, not exact samples or maxima. they are nil for an empty interval or the unbounded bucket.

func DurationSummaries

func DurationSummaries(before, after []*dto.MetricFamily) ([]DurationSummary, error)

DurationSummaries differences classic histogram counts, sums, and cumulative buckets before estimating quantiles. inputs must describe the same process; process_start_time_seconds and histogram creation timestamps, when present, also detect restarts. new lazy series start at zero. missing end series, changed layouts, invalid samples, and detectable resets invalidate the interval. all histogram families are included; callers should supply durations in seconds.

type IngressRoutingSnapshot

type IngressRoutingSnapshot struct {
	Initialized          bool
	CaughtUp             bool
	LastSuccessfulCheck  time.Time
	LastCaughtUp         time.Time
	LastAcknowledged     time.Time
	LatestRevision       int64
	AppliedRevision      int64
	AcknowledgedRevision int64
	UpdateFailures       uint64
	Resnapshots          uint64
}

IngressRoutingSnapshot is bounded, process-local controller state. revisions describe successful routing responses, not control's current revision while a request is pending. CaughtUp requires an event response confirming catch-up; applying the initial snapshot alone only establishes Initialized.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics owns a process-local Prometheus registry.

func New

func New(role string) *Metrics

New constructs an isolated registry for one tnld role.

func (*Metrics) APIRequests

func (m *Metrics) APIRequests(surface string, next http.Handler) http.Handler

APIRequests records matched route patterns, never URLs or resource IDs. wrap the router so authentication and parameter-binding failures are counted too.

func (*Metrics) AddAssignmentReplacements

func (m *Metrics) AddAssignmentReplacements(reason string, count int)

func (*Metrics) AddForwardedBytes

func (m *Metrics) AddForwardedBytes(direction string, count int64)

func (*Metrics) AddReadyPublisherConnections

func (m *Metrics) AddReadyPublisherConnections(delta int)

func (*Metrics) AddRecoveryPending

func (m *Metrics) AddRecoveryPending(delta int)

func (*Metrics) AddRegisteredPublisherConnections

func (m *Metrics) AddRegisteredPublisherConnections(delta int)

func (*Metrics) AddRelayLeases

func (m *Metrics) AddRelayLeases(state string, delta int)

func (*Metrics) AddRelayStreams

func (m *Metrics) AddRelayStreams(delta int)

func (*Metrics) AddUsageItems

func (m *Metrics) AddUsageItems(result string, count int)

func (*Metrics) Gather

func (m *Metrics) Gather() ([]*dto.MetricFamily, error)

Gather captures this process's registry using only passive collectors.

func (*Metrics) Handler

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

func (*Metrics) IncCapacityRejection

func (m *Metrics) IncCapacityRejection(resource string)

func (*Metrics) IncChallengeRejection

func (m *Metrics) IncChallengeRejection(reason string)

func (*Metrics) IncDrainingRejection

func (m *Metrics) IncDrainingRejection()

func (*Metrics) IncInspectionFailure

func (m *Metrics) IncInspectionFailure(stage string)

func (*Metrics) ObserveAPIRequest

func (m *Metrics) ObserveAPIRequest(surface, operation, outcome string, duration time.Duration)

func (*Metrics) ObserveCertificateClaim

func (m *Metrics) ObserveCertificateClaim(kind, outcome string)

func (*Metrics) ObserveCertificateIteration

func (m *Metrics) ObserveCertificateIteration(kind, stage, outcome string, duration time.Duration)

func (*Metrics) ObserveCertificateMilestone

func (m *Metrics) ObserveCertificateMilestone(milestone string, age time.Duration)

func (*Metrics) ObserveCertificateTransition

func (m *Metrics) ObserveCertificateTransition(kind, state string)

func (*Metrics) ObserveCertificateWork

func (m *Metrics) ObserveCertificateWork(stage, outcome string, duration time.Duration)

func (*Metrics) ObserveCleanup

func (m *Metrics) ObserveCleanup(kind string, count int, busy bool, err error)

func (*Metrics) ObserveDNSTransition

func (m *Metrics) ObserveDNSTransition(kind, state string)

func (*Metrics) ObserveDNSWork

func (m *Metrics) ObserveDNSWork(kind, phase, outcome string, elapsed time.Duration)

func (*Metrics) ObserveDatabaseAcquire

func (m *Metrics) ObserveDatabaseAcquire(err error, elapsed time.Duration)

func (*Metrics) ObserveDatabaseGuard

func (m *Metrics) ObserveDatabaseGuard(operation string, err error, elapsed time.Duration)

ObserveDatabaseGuard records a driver-observed guard interval. outcome is the transaction-ending command's outcome, not the application operation's outcome.

func (*Metrics) ObserveDatabaseQuery

func (m *Metrics) ObserveDatabaseQuery(operation string, err error, elapsed time.Duration)

ObserveDatabaseQuery accepts only names sanitized by the controlstate tracer: compiled sqlc operations, transaction commands, or the fixed "unknown" label.

func (*Metrics) ObserveOperation

func (m *Metrics) ObserveOperation(operation string, err error, elapsed time.Duration)

ObserveOperation records only the fixed application operations below. nil metrics are useful for callers that do not run a process metrics listener.

func (*Metrics) ObservePlacement

func (m *Metrics) ObservePlacement(action, outcome string)

func (*Metrics) ObservePublishRunReadiness

func (m *Metrics) ObservePublishRunReadiness(outcome string, duration, age time.Duration)

outcomes and stages are closed sets, independent of public URL and order identity.

func (*Metrics) ObservePublisherExit

func (m *Metrics) ObservePublisherExit(unexpected bool)

func (*Metrics) ObserveRecoveryAttempt

func (m *Metrics) ObserveRecoveryAttempt(outcome string)

func (*Metrics) ObserveRecoveryDuration

func (m *Metrics) ObserveRecoveryDuration(duration time.Duration)

func (*Metrics) ObserveRelayAttempt

func (m *Metrics) ObserveRelayAttempt(slot, outcome string)

func (*Metrics) ObserveRelayStreamRejection

func (m *Metrics) ObserveRelayStreamRejection(reason string)

func (*Metrics) ObserveRoutingHistoryBatch

func (m *Metrics) ObserveRoutingHistoryBatch(scanned, deleted int64, busy bool)

func (*Metrics) ObserveRoutingHistoryFloor

func (m *Metrics) ObserveRoutingHistoryFloor(revision uint64)

func (*Metrics) ObserveUsageReceiver

func (m *Metrics) ObserveUsageReceiver(outcome string, elapsed time.Duration)

func (*Metrics) ObserveUsageWork

func (m *Metrics) ObserveUsageWork(phase, outcome string)

func (*Metrics) ObserveVisitor

func (m *Metrics) ObserveVisitor(outcome string)

visitor outcomes describe the last ingress boundary reached, not a completed TLS handshake or a successful HTTP request at the local service.

func (*Metrics) ObserveVisitorOpen

func (m *Metrics) ObserveVisitorOpen(success bool, elapsed time.Duration)

func (*Metrics) RegisterControlCertificate

func (m *Metrics) RegisterControlCertificate(source func() time.Time)

RegisterControlCertificate reads certificate material already in this process.

func (*Metrics) RegisterDatabase

func (m *Metrics) RegisterDatabase(source func(time.Time) DatabaseSnapshot)

RegisterDatabase exposes in-memory database state. its source must never acquire a connection because collection must remain available under database contention and pool exhaustion.

func (*Metrics) RegisterIngressLease

func (m *Metrics) RegisterIngressLease(source func() time.Time)

RegisterIngressLease reads a local controller snapshot without external I/O.

func (*Metrics) RegisterIngressRouting

func (m *Metrics) RegisterIngressRouting(source func() IngressRoutingSnapshot)

RegisterIngressRouting exposes one ingress controller's in-memory state. the source must perform no network or database I/O, including during a stalled poll.

func (*Metrics) SetCapacityLimit

func (m *Metrics) SetCapacityLimit(resource string, limit int64)

func (*Metrics) SetIngressConnections

func (m *Metrics) SetIngressConnections(class string, count int)

func (*Metrics) SetIngressStreams

func (m *Metrics) SetIngressStreams(count int)

func (*Metrics) SetReadyPublisherConnections

func (m *Metrics) SetReadyPublisherConnections(count int)

func (*Metrics) SetRelayCertificateExpiry

func (m *Metrics) SetRelayCertificateExpiry(identity string, expires time.Time)

func (*Metrics) SetRelayLeaseExpiry

func (m *Metrics) SetRelayLeaseExpiry(identity string, expires time.Time)

func (*Metrics) SetRelayLeases

func (m *Metrics) SetRelayLeases(state string, count int)

func (*Metrics) SetUsageRetained

func (m *Metrics) SetUsageRetained(count int)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a running metrics listener.

func Listen

func Listen(address string, handler http.Handler) (*Server, error)

Listen starts serving metrics at address.

func Serve

func Serve(listener net.Listener, handler http.Handler) *Server

Serve starts serving metrics on a listener reserved during process startup.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the bound listener address.

func (*Server) Done

func (s *Server) Done() <-chan error

Done reports when the listener exits.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the listener.

Jump to

Keyboard shortcuts

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