telemetry

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonGraceful    = "graceful"     // shutdown, app stop/disable, drain completed
	ReasonCrashed     = "crashed"      // health check failed or backend unreachable
	ReasonIdleTimeout = "idle_timeout" // autoscaler evicted an idle worker
)

Reason labels for blockyard_workers_stopped_total. Keep the set small and bounded — cardinality is #reasons, shared across all apps.

View Source
const (
	StateBusy     = "busy"     // has one or more active sessions
	StateIdle     = "idle"     // session count is zero, not draining
	StateDraining = "draining" // marked for drain; no new sessions routed
)

State labels for blockyard_workers gauge. Bounded and shared across all apps. States are derived from ActiveWorker fields on each reconciliation tick rather than tracked as explicit transitions, so "starting" and "crashed" (both transient) are not represented — workers only appear in the gauge once WorkersActive sees them, and disappear the moment they're evicted.

View Source
const AppUnknown = "unknown"

AppUnknown is the label value used for proxy requests that do not resolve to an app (e.g. 404 on an unknown name). Using a sentinel keeps cardinality bounded against arbitrary URL paths.

Variables

This section is empty.

Functions

func InitTracing

func InitTracing(ctx context.Context, endpoint string) (func(context.Context) error, error)

InitTracing sets up the OpenTelemetry trace provider. Returns a shutdown function that flushes pending spans. If endpoint is empty, tracing is not initialized (no-op provider is used).

func ProxyStatusClass added in v0.0.3

func ProxyStatusClass(code int) string

ProxyStatusClass returns the "Nxx" status class for an HTTP status code. Bucketing to classes (rather than raw codes) keeps label cardinality bounded — upstream apps and proxies emit long-tail codes (418, 499, 520, …) that would otherwise create a new series each.

func TracingMiddleware

func TracingMiddleware() func(http.Handler) http.Handler

TracingMiddleware returns a chi-compatible middleware that creates OpenTelemetry spans for each request.

Types

type Metrics added in v0.0.3

type Metrics struct {
	// Gauges — current state
	WorkersActive  prometheus.Gauge
	WorkersByState *prometheus.GaugeVec // labels: state
	SessionsActive prometheus.Gauge

	// Counters — cumulative totals
	WorkersSpawned          prometheus.Counter
	WorkersStopped          *prometheus.CounterVec // labels: reason
	BundlesUploaded         prometheus.Counter
	BundleRestoresSucceeded prometheus.Counter
	BundleRestoresFailed    prometheus.Counter
	ProxyRequests           *prometheus.CounterVec // labels: app, status
	HealthChecksFailed      *prometheus.CounterVec // labels: app
	AuditEntriesDropped     prometheus.Counter

	// Histograms — distributions
	ColdStartDuration    prometheus.Histogram
	ProxyRequestDuration prometheus.Histogram
	BuildDuration        prometheus.Histogram
}

Metrics holds every Prometheus collector used by the blockyard server. Create one instance per server (via NewMetrics) and thread it through the types that need to record observations. Tests should use a dedicated prometheus.Registry so parallel tests and before/after delta assertions stay isolated from each other.

func NewMetrics added in v0.0.3

func NewMetrics(reg prometheus.Registerer) *Metrics

NewMetrics constructs a Metrics registered with reg. Pass prometheus.DefaultRegisterer in production so the /metrics HTTP handler (which scrapes the default gatherer) can serve the values. Tests should pass prometheus.NewRegistry for isolation.

Jump to

Keyboard shortcuts

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