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 ¶
- func Aggregate(rm metricdata.ResourceMetrics, at time.Time) *metricsv1.Snapshot
- type Option
- type Service
- func (s *Service) GetMetrics(ctx context.Context, _ *connect.Request[metricsv1.GetMetricsRequest]) (*connect.Response[metricsv1.Snapshot], error)
- func (s *Service) Start(ctx context.Context)
- func (s *Service) StreamMetrics(ctx context.Context, _ *connect.Request[metricsv1.StreamMetricsRequest], ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aggregate ¶
func Aggregate(rm metricdata.ResourceMetrics, at time.Time) *metricsv1.Snapshot
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 ¶
WithClock overrides the sample/snapshot timestamp source (tests use a fixed clock).
func WithRingCapacity ¶
WithRingCapacity overrides the backfill ring capacity.
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 ¶
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 ¶
func (s *Service) GetMetrics(ctx context.Context, _ *connect.Request[metricsv1.GetMetricsRequest]) (*connect.Response[metricsv1.Snapshot], error)
GetMetrics returns the current derived snapshot.
func (*Service) Start ¶
Start launches the utilization sampler goroutine; it stops when ctx is cancelled.
func (*Service) StreamMetrics ¶
func (s *Service) StreamMetrics(ctx context.Context, _ *connect.Request[metricsv1.StreamMetricsRequest], stream *connect.ServerStream[metricsv1.StreamMetricsResponse]) error
StreamMetrics sends exactly one Backfill (the ring history, oldest-first), then a fresh Snapshot on each tick until the client disconnects (ctx cancelled).