threshold

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package threshold provides CEL-based evaluation of performance thresholds. Threshold expressions use a single `value` variable (float64) and must return a boolean. Example: "value >= 900".

Index

Constants

This section is empty.

Variables

View Source
var Registry = []Definition{
	{Key: "busBandwidthGBps", Unit: "GB/s", Description: "Bus bandwidth (from BandwidthMeasurement)"},
	{Key: "algBandwidthGBps", Unit: "GB/s", Description: "Algorithm bandwidth (from BandwidthMeasurement)"},
	{Key: "goodputRatio", Unit: "ratio (0-1)", Description: "Goodput ratio (from GoodputMeasurement)"},
	{Key: "avgTFLOPsPerGPU", Unit: "TFLOPS", Description: "Average TFLOPS per GPU (from GoodputMeasurement)"},
	{Key: "avgStepTimeSec", Unit: "seconds", Description: "Average step time (from GoodputMeasurement)"},
}

Registry lists all known threshold keys. Unknown keys are rejected by ValidateKeys.

Functions

func Evaluate

func Evaluate(measured float64, expression string) (bool, error)

Evaluate compiles and evaluates a CEL expression with the measured value. Returns true if the threshold is satisfied (expression returns true), false if violated (expression returns false). Returns an error if the expression fails to compile or evaluate.

func Keys

func Keys() []string

Keys returns all known threshold keys in Registry order.

func ValidateKeys

func ValidateKeys(thresholds map[string]string) []string

ValidateKeys returns any keys in thresholds that are not in the Registry, sorted for deterministic messages.

func ValidateKeysError

func ValidateKeysError(thresholds map[string]string) error

ValidateKeysError returns an error when thresholds contains keys that are not in the Registry. The error names each offending key and lists the valid keys, so a typo is diagnosed instead of silently disabling validation. Returns nil when every key is known.

Types

type Definition

type Definition struct {
	// Key is the camelCase metric name with unit suffix.
	Key string
	// Unit is the human-readable unit for display (e.g., "GB/s", "seconds").
	Unit string
	// Description is a short help text for the metric.
	Description string
}

Definition describes a known threshold key.

type Violation

type Violation struct {
	Key        string
	Expression string
	Measured   float64
	Reason     string // "ThresholdViolated", "InvalidThresholdExpression"
	Message    string
}

Violation describes a single threshold that was not met.

func EvaluateAll

func EvaluateAll(thresholds map[string]string, measured map[string]float64) ([]Violation, error)

EvaluateAll checks all thresholds against measured values. Returns a list of violations (empty if all thresholds pass), sorted by key. Returns an error when thresholds contains a key that is not in the Registry: an unknown key can never be measured, so evaluating around it would silently skip validation. The error names the offending keys and lists the valid ones.

Jump to

Keyboard shortcuts

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