Documentation
¶
Overview ¶
Package stats stores derived request statistics in minute buckets.
Index ¶
- func StartFeed(ctx context.Context, s *Store, src bifrost.LogSource, tail *bifrost.Tail, ...) func()
- type CostSink
- type Cursor
- type Dimensions
- type Mix
- type ModelPair
- type Point
- type Result
- type Row
- type Store
- func (s *Store) Close() error
- func (s *Store) Cursor(ctx context.Context, name string) (Cursor, error)
- func (s *Store) Ingest(ctx context.Context, rows []Row) error
- func (s *Store) IngestPage(ctx context.Context, rows []Row, name string, pos Cursor) error
- func (s *Store) ModelPairs(ctx context.Context, from, to time.Time, filter func(Dimensions) bool) ([]ModelPair, error)
- func (s *Store) Prune(ctx context.Context, now time.Time, rawRetentionDays int) error
- func (s *Store) Query(ctx context.Context, from, to time.Time, bucketSec int64, ...) (Result, error)
- func (s *Store) TokenMix(ctx context.Context, from, to time.Time, filter func(Dimensions) bool) (Mix, error)
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CostSink ¶ added in v0.9.0
type CostSink interface {
Price(bifrost.Log) store.RequestCost
RequestCosts(ctx context.Context, ids []string) (map[string]store.RequestCost, error)
RecordCosts(ctx context.Context, rows []store.RequestCost) error
PruneRequestCost(ctx context.Context, before time.Time) error
}
CostSink prices terminal request log rows and persists them in the main store.
type Cursor ¶
Cursor is the last point committed by a log feed. The zero value means it has not started.
type Dimensions ¶
type Dimensions struct {
Provider, Model string
VirtualKeyID, RoutingRuleID, SelectedKeyID string
FallbackIndex int
}
Dimensions are the untranslated request-log dimensions. Unset IDs are empty.
type Mix ¶ added in v0.9.0
type Mix struct {
Requests, Input, Output, CacheRead int64
}
Mix holds request and token-class totals over a range. Input excludes cache tokens.
type ModelPair ¶
type ModelPair struct{ Provider, Model string }
ModelPair identifies an untranslated provider and model.
type Result ¶
Result contains the totals, the zero-filled series, and one summary per group predicate in input order.
type Row ¶ added in v0.9.0
type Row struct {
bifrost.Log
Cost store.RequestCost
}
Row is one engine log row paired with its computed request cost.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds the derived rollup, with a single SQLite connection serializing writes.
func Open ¶
Open opens the dedicated stats database at path. An existing database with a different schema version is discarded, so only one Store may own this path.
func (*Store) Cursor ¶
Cursor returns the named feed's persisted position, or the zero value if absent.
func (*Store) Ingest ¶
Ingest records terminal attempts once within the replay window. In-flight rows stay eligible when they are delivered again as terminal attempts.
func (*Store) IngestPage ¶
IngestPage records a page and advances the named cursor in one transaction. On restart, resume strictly after pos using timestamp and ID to break ties.
func (*Store) ModelPairs ¶
func (s *Store) ModelPairs(ctx context.Context, from, to time.Time, filter func(Dimensions) bool) ([]ModelPair, error)
ModelPairs returns distinct nonempty models that match the range and filter, busiest first, breaking ties by model and then provider as in the log rankings. The predicate has the same restrictions as in Query.
func (*Store) Prune ¶
Prune removes expired minute buckets and replay IDs. The feed calls it hourly with the raw log retention; stats keep at least eight days.
func (*Store) Query ¶
func (s *Store) Query(ctx context.Context, from, to time.Time, bucketSec int64, filter func(Dimensions) bool, groups ...func(Dimensions) bool) (Result, error)
Query includes both boundary minutes; a minute cannot be split. bucketSec must be a positive multiple of 60, or zero for no series. Predicates are evaluated while reading the store and must not call it; nil matches all dimensions.
type Summary ¶
type Summary struct {
Requests, Errors int64
PromptTokens, CompletionTokens, TotalTokens int64
CacheReadTokens, CacheWriteTokens int64
ActualUSD, EquivalentUSD, SavingUSD float64
UnpricedActual, UnpricedEquivalent int64
LatencyP50Ms, LatencyP95Ms *float64
}
Summary holds attempt totals and approximate percentiles of successful attempts.