metrics

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package metrics provides interfaces for defining self-contained, reusable metrics.

Each metric is a computation unit that:

  • Declares its input requirements
  • Computes a typed output
  • Provides metadata for documentation and serialization

This design allows metrics to be reused across analyzers and output formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register[In, Out any](r *Registry, m Metric[In, Out])

Register adds a metric to the registry.

func RiskPriority

func RiskPriority(level RiskLevel) int

RiskPriority returns a sortable integer for a risk level. Lower values indicate higher priority: CRITICAL < HIGH < MEDIUM < LOW/unknown.

Types

type Metric

type Metric[In, Out any] interface {
	// Name returns the machine-readable identifier (snake_case, unique).
	Name() string

	// DisplayName returns a human-readable name for UI/reports.
	DisplayName() string

	// Description returns detailed documentation including:
	// - What the metric measures.
	// - How to interpret the value.
	// - Units (if applicable).
	// - Any caveats or limitations.
	Description() string

	// Type returns the metric category (e.g., "aggregate", "time_series", "risk").
	Type() string

	// Compute calculates the metric value from input data.
	Compute(input In) Out
}

Metric is the core interface that all metrics must implement. Each metric is a self-contained computation with metadata.

type MetricMeta

type MetricMeta struct {
	MetricName        string
	MetricDisplayName string
	MetricDescription string
	MetricType        string
}

MetricMeta holds the common metadata for a metric. Embed this in metric implementations to satisfy metadata methods.

func (MetricMeta) Description

func (m MetricMeta) Description() string

Description returns detailed documentation.

func (MetricMeta) DisplayName

func (m MetricMeta) DisplayName() string

DisplayName returns a human-readable name for UI/reports.

func (MetricMeta) Name

func (m MetricMeta) Name() string

Name returns the machine-readable identifier.

func (MetricMeta) Type

func (m MetricMeta) Type() string

Type returns the metric category.

type Registry

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

Registry holds a collection of metrics that can be computed together.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty metric registry.

func (*Registry) Get

func (r *Registry) Get(name string) (any, bool)

Get retrieves a metric by name.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all registered metric names.

type RiskLevel

type RiskLevel string

RiskLevel represents severity levels.

const (
	RiskCritical RiskLevel = "CRITICAL"
	RiskHigh     RiskLevel = "HIGH"
	RiskMedium   RiskLevel = "MEDIUM"
	RiskLow      RiskLevel = "LOW"
)

Risk level constants.

type RiskResult

type RiskResult struct {
	Value     any       `json:"value"`
	Level     RiskLevel `json:"risk_level"`
	Threshold float64   `json:"threshold,omitempty"`
	Message   string    `json:"message,omitempty"`
}

RiskResult is the output of a risk metric.

type TimeSeriesPoint

type TimeSeriesPoint struct {
	Tick  int     `json:"tick"`
	Value float64 `json:"value"`
}

TimeSeriesPoint is a single data point in a time series.

Jump to

Keyboard shortcuts

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