usage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package usage builds cohort reports from retained counts and verified links.

Index

Constants

View Source
const ReadinessMaxAge = 10 * time.Minute

Variables

View Source
var ErrTotalsOutOfRange = errors.New("usage totals exceed the supported exact integer range")

Functions

func NamespaceUID

func NamespaceUID(ctx context.Context, reader client.Reader, namespace string) (string, error)

func NamespaceUIDForObject

func NamespaceUIDForObject(ctx context.Context, reader client.Reader, object client.Object) (string, error)

Read the namespace first, then fence the source object's UID. A stale cached Task or monitor cannot be relabeled with a recreated namespace's identity.

Types

type Measurement

type Measurement struct {
	ID                    string    `json:"id"`
	AttemptID             string    `json:"attemptID,omitempty"`
	Scope                 string    `json:"scope"`
	Source                string    `json:"source"`
	Provider              string    `json:"provider,omitempty"`
	Model                 string    `json:"model,omitempty"`
	InputTokens           *int64    `json:"inputTokens"`
	OutputTokens          *int64    `json:"outputTokens"`
	CachedInputTokens     *int64    `json:"cachedInputTokens"`
	CacheWriteInputTokens *int64    `json:"cacheWriteInputTokens"`
	Status                string    `json:"status"`
	Completeness          string    `json:"completeness"`
	Gap                   string    `json:"gap,omitempty"`
	ObservedAt            time.Time `json:"observedAt"`
	// contains filtered or unexported fields
}

type OtherWork

type OtherWork struct {
	Category    string `json:"category"`
	Explanation string `json:"explanation"`
	Totals      Totals `json:"usage"`
	TaskCount   int    `json:"taskCount"`
	Tasks       []Task `json:"tasks,omitempty"`
	Page        *Page  `json:"page,omitempty"`
}

type Page

type Page struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
	Total  int `json:"total"`
}

type PullRequest

type PullRequest struct {
	store.UsagePullRequest
	Origin     string `json:"origin"`
	EvidenceID string `json:"evidenceID"`
}

type Report

type Report struct {
	Selection     store.UsageFilter `json:"selection"`
	RetainedSince *time.Time        `json:"retainedSince,omitempty"`
	Summary       Summary           `json:"summary"`
	Teams         []Team            `json:"teams"`
	Works         []Work            `json:"works"`
	OtherWork     []OtherWork       `json:"otherWork"`
	Page          *Page             `json:"page,omitempty"`
}

func Build

func Build(data store.UsageData, filter store.UsageFilter) (Report, error)

Build selects requests by start date. Model filtering selects whole requests that used a model; it never removes their other models from the numerator.

func BuildPage

func BuildPage(data store.UsageData, filter store.UsageFilter, page Page, otherCategory string) (Report, error)

BuildPage computes totals across the entire selection, then pages compact work rows. Only a requested other-usage category includes Task details.

type Retention

type Retention struct {
	Store  store.UsageStore
	Period time.Duration
}

Retention expires inactive reporting cohorts independently of Task TTLs.

func (*Retention) NeedLeaderElection

func (r *Retention) NeedLeaderElection() bool

func (*Retention) Start

func (r *Retention) Start(ctx context.Context) error

type Summary

type Summary struct {
	Totals
	WorkRequests      int      `json:"workRequests"`
	UnfinishedWork    int      `json:"unfinishedWork"`
	PRsOpened         int      `json:"prsOpened"`
	PRsReady          int      `json:"prsReady"`
	PRsMerged         int      `json:"prsMerged"`
	PRsClosed         int      `json:"prsClosed"`
	PRsAssisted       int      `json:"prsAssisted"`
	TokensPerPROpened *float64 `json:"tokensPerPROpened"`
	TokensPerPRMerged *float64 `json:"tokensPerPRMerged"`
}

type Task

type Task struct {
	store.UsageTask
	Totals       Totals        `json:"usage"`
	Measurements []Measurement `json:"measurements"`
	Shared       bool          `json:"shared"`
}

type Team

type Team struct {
	Namespace string  `json:"namespace"`
	Summary   Summary `json:"summary"`
}

type Totals

type Totals struct {
	InputTokens             int64  `json:"inputTokens"`
	OutputTokens            int64  `json:"outputTokens"`
	CachedInputTokens       int64  `json:"cachedInputTokens"`
	CacheWriteInputTokens   int64  `json:"cacheWriteInputTokens"`
	TotalTokens             int64  `json:"totalTokens"`
	EstimatedTokens         int64  `json:"estimatedTokens"`
	CachedUsageReported     bool   `json:"cachedUsageReported"`
	CacheWriteUsageReported bool   `json:"cacheWriteUsageReported"`
	Measurements            int    `json:"measurements"`
	ReportedMeasurements    int    `json:"reportedMeasurements"`
	MissingMeasurements     int    `json:"missingMeasurements"`
	PartialMeasurements     int    `json:"partialMeasurements"`
	Calls                   int    `json:"calls"`
	Attempts                int    `json:"attempts"`
	Completeness            string `json:"completeness"`
	ModelCost               string `json:"modelCost"`
}

type Work

type Work struct {
	store.UsageWorkRequest
	Summary      Summary       `json:"summary"`
	Tasks        []Task        `json:"tasks,omitempty"`
	PullRequests []PullRequest `json:"pullRequests,omitempty"`
	Models       []string      `json:"models,omitempty"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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