Documentation
¶
Overview ¶
Package stats is the pure arithmetic behind the all-time FindingRollup objects: micro-USD cost parsing, per-scope delta computation, and exactly-once ledger application. Everything here is table-testable — the rollup reconciler supplies objects and writes results, this package never touches the cluster.
Index ¶
- func Apply(st *v1alpha1.FindingRollupStatus, ledgerKey string, stage *StageDelta, ...) bool
- func ParseCostMicroUSD(s string) (int64, error)
- func PhaseKey(p v1alpha1.Phase) string
- func RecordCompletion(ctx context.Context, phase, recommendation, repo string)
- func RecordDeleted(ctx context.Context, reason string)
- func RecordStage(ctx context.Context, d StageDelta, repo string)
- func ScopeObjectName(scope v1alpha1.RollupScope) string
- type FindingDelta
- type StageDelta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply( st *v1alpha1.FindingRollupStatus, ledgerKey string, stage *StageDelta, finding *FindingDelta, now time.Time, month string, ) bool
Apply folds one delta into a rollup status under the exactly-once ledger: it returns false (and mutates nothing) when ledgerKey was already applied. Exactly one of stage/finding may be non-nil. The monthly trend line is maintained only when month is non-empty (the total scope).
func ParseCostMicroUSD ¶
ParseCostMicroUSD converts a CRD decimal cost string into integer micro-USD without float arithmetic. Empty means zero.
func RecordCompletion ¶
RecordCompletion emits a finding's terminal-entry metrics (first rollup only).
func RecordDeleted ¶
RecordDeleted emits a finding deletion (reason: ttl or manual).
func RecordStage ¶
func RecordStage(ctx context.Context, d StageDelta, repo string)
RecordStage emits one run's metrics (called at total-scope aggregation so it fires exactly once per run).
func ScopeObjectName ¶
func ScopeObjectName(scope v1alpha1.RollupScope) string
ScopeObjectName is the deterministic FindingRollup object name for a scope value: total, repo-<hash>, harness-<sanitized>, model-<sanitized>.
Types ¶
type FindingDelta ¶
type FindingDelta struct {
// Phase bucket to increment (kebab-free lowercase: remediated, failed,
// dismissed, handedoff, deleted).
Phase string
// PrevPhase, when non-empty, is decremented first — the revival
// correction (the finding was counted under PrevPhase, then revived and
// completed again).
PrevPhase string
// Recommendation histogram key (remediate/ignore/manual); empty skips.
Recommendation string
// Attempts summed (investigation + remediation), counted only on the
// first terminal entry (corrections pass zero to avoid double counts).
Attempts int64
// FirstCount marks the finding's first terminal entry (findings++).
FirstCount bool
}
FindingDelta is one finding's terminal contribution (total and repository scopes only — a finding has no single harness/model owner).
type StageDelta ¶
type StageDelta struct {
// Stage is "investigation" or "remediation".
Stage string
// Outcome from the envelope vocabulary (+ "aborted").
Outcome string
// Succeeded marks an ok run (for remediation: ok and successful).
Succeeded bool
// Harness/Model executed the run; empty when the run died without one.
Harness string
Model string
// Token sums.
InputTokens, OutputTokens, CacheReadTokens, CacheCreationTokens int64
// CostMicroUSD spent.
CostMicroUSD int64
// ElapsedMilliseconds of wall clock.
ElapsedMilliseconds int64
}
StageDelta is one agent run's contribution to a StageAggregate.
func StageDeltaFrom ¶
func StageDeltaFrom(stage string, st *v1alpha1.StageResult, succeeded bool) (StageDelta, error)
StageDeltaFrom derives the delta from a child's stage result.