Documentation
¶
Overview ¶
Package runtimebudget reads runtime/metrics snapshots and compares them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownMetric means the metric name is not in runtime/metrics.All. ErrUnknownMetric = errors.New("runtimebudget: unknown metric") // ErrMetricMissing means a snapshot does not contain the requested metric. ErrMetricMissing = errors.New("runtimebudget: metric missing from snapshot") ErrMetricUnavailable = errors.New("runtimebudget: metric unavailable") // ErrKindMismatch means a value's kind differs from its runtime description. ErrKindMismatch = errors.New("runtimebudget: metric kind mismatch") // ErrUnsupportedKind means a newer or otherwise unsupported metric kind was seen. ErrUnsupportedKind = errors.New("runtimebudget: unsupported metric kind") // ErrNotCumulative means an operation requiring a cumulative metric was requested. ErrNotCumulative = errors.New("runtimebudget: metric is not cumulative") // ErrCumulativeMetric means Check received a cumulative metric. ErrCumulativeMetric = errors.New("runtimebudget: metric is cumulative; use CheckDelta or CheckRate for scalars, HistogramDelta for histograms") // ErrHistogramScalarDelta means a histogram was passed to scalar Delta or Rate. ErrHistogramScalarDelta = errors.New("runtimebudget: histogram needs bucket handling") // ErrHistogramRequired means HistogramDelta was passed a non-histogram metric. ErrHistogramRequired = errors.New("runtimebudget: metric is not a histogram") // ErrHistogramLayout means two histogram snapshots have different bucket boundaries. ErrHistogramLayout = errors.New("runtimebudget: histogram bucket layout mismatch") // ErrCounterReset means a cumulative value decreased between snapshots. ErrCounterReset = errors.New("runtimebudget: cumulative metric decreased") // ErrInvalidInterval means the current snapshot is not after the previous one. ErrInvalidInterval = errors.New("runtimebudget: snapshot interval must be positive") // ErrInvalidBudget means a budget limit is NaN or infinite. ErrInvalidBudget = errors.New("runtimebudget: budget limit must be finite") // ErrHistogramBudget means a histogram cannot be checked as one scalar value. ErrHistogramBudget = errors.New("runtimebudget: histogram budget needs bucket handling") // ErrBudgetExceeded means at least one budget was exceeded. ErrBudgetExceeded = errors.New("runtimebudget: budget exceeded") // ErrNilContext means WatchRate received a nil context. ErrNilContext = errors.New("runtimebudget: nil context") // ErrNilCallback means WatchRate received a nil report callback. ErrNilCallback = errors.New("runtimebudget: nil callback") // ErrInvalidWatchInterval means WatchRate received a non-positive interval. ErrInvalidWatchInterval = errors.New("runtimebudget: watch interval must be positive") )
Functions ¶
func Rate ¶
Rate returns the scalar cumulative increase per second, using the timestamps captured in the two snapshots. Histograms are intentionally rejected.
func WatchRate ¶ added in v0.3.0
func WatchRate(ctx context.Context, interval time.Duration, budgets map[string]float64, onReport func(Report)) error
WatchRate samples selected cumulative metrics immediately and then at each interval, reporting the rate between consecutive samples. It blocks until ctx is canceled and then returns ctx.Err(). Reports are delivered synchronously in the caller's goroutine. Slow callbacks delay sampling and may cause ticker events to be dropped. Rates use actual snapshot timestamps, not the requested interval. Cancellation does not interrupt a callback; it must return before WatchRate can exit.
Types ¶
type Histogram ¶
Histogram is an explicit bucketed metric value. Counts[i] covers [Buckets[i], Buckets[i+1]).
type Report ¶
Report contains budget violations and metrics that could not be checked.
func Check ¶
Check evaluates maximum numeric budgets for non-cumulative scalar metrics. The returned report is deterministic by metric name. Use report.Err() when the caller wants violations and evaluation issues as an error. Cumulative metrics produce ErrCumulativeMetric; use CheckDelta or CheckRate for scalars and HistogramDelta for histograms.
func CheckDelta ¶ added in v0.2.0
CheckDelta evaluates maximum budgets against cumulative metric increases. The returned report is deterministic by metric name.
func CheckRate ¶ added in v0.2.0
CheckRate evaluates maximum budgets against cumulative metric increases per second. The returned report is deterministic by metric name.
type ReportError ¶
type ReportError struct {
Report Report
}
ReportError is returned by Report.Err when a check has violations or issues.
func (*ReportError) Error ¶
func (e *ReportError) Error() string
func (*ReportError) Unwrap ¶
func (e *ReportError) Unwrap() []error
Unwrap makes errors.Is useful for both violations and evaluation issues.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is an immutable copy of selected runtime metrics at one point in time. The snapshot's histogram slices are copied, so a later runtime/metrics.Read does not change this snapshot.
func Read ¶
Read reads the named metrics. With no names, it reads every metric currently returned by runtime/metrics.All. Unknown names are retained with KindBad.
func ReadAll ¶
func ReadAll() Snapshot
ReadAll reads every metric currently returned by runtime/metrics.All.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a kind-tagged runtime metric value.
func Delta ¶
Delta returns the scalar increase of a cumulative metric. Histograms are intentionally rejected; use HistogramDelta for their bucket counts.