metrics

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package metrics is the daemon's derived-dashboard presentation layer for magus's OTel metrics. It rolls raw in-process metricdata (histogram buckets and counters, read via otlp.Collector) into the magus.metrics.v1alpha1 wire types the /dashboard consumes, maintains a rolling sample ring for backfill, and implements the Connect MetricsService. It is the only place the generated metrics proto meets the OTel SDK; observability itself stays proto-free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

Aggregate rolls one metricdata.ResourceMetrics collection into a derived Snapshot: each latency histogram family becomes a Latency (count/sum plus interpolated p50/p95/p99/max), and the remote-cache instruments become a Remote. Missing instruments yield zero-valued (never nil) sub-messages, so the wire shape is stable from the first tick. at stamps capture_time.

Types

type Option

type Option func(*Service)

Option customizes a Service; production callers pass none. Test seams inject a clock, the tick interval, and the ring capacity.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the sample/snapshot timestamp source (tests use a fixed clock).

func WithRingCapacity

func WithRingCapacity(n int) Option

WithRingCapacity overrides the backfill ring capacity.

func WithTick

func WithTick(d time.Duration) Option

WithTick overrides the sampler and stream cadence.

type Service

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

Service implements metricsv1alpha1connect.MetricsServiceHandler for the /dashboard: it serves the current derived Snapshot (GetMetrics) and a backfilled live stream (StreamMetrics), reading raw metricdata through a collector and keeping a rolling Sample ring. Construct it with NewService and launch its sampler with Start.

func NewService

func NewService(coll collector, stat statusSource, opts ...Option) *Service

NewService builds a Service reading derived metrics from coll and live pool occupancy from stat. Call Start to begin filling the backfill ring.

func (*Service) GetMetrics

GetMetrics returns the current derived snapshot.

func (*Service) Start

func (s *Service) Start(ctx context.Context)

Start launches the utilization sampler goroutine; it stops when ctx is cancelled.

func (*Service) StreamMetrics

StreamMetrics sends exactly one Backfill (the ring history, oldest-first), then a fresh Snapshot on each tick until the client disconnects (ctx cancelled).

Jump to

Keyboard shortcuts

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