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 Cursor
- type Dimensions
- type ModelPair
- type Point
- type Result
- 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 []bifrost.Log) error
- func (s *Store) IngestPage(ctx context.Context, rows []bifrost.Log, 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)
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 ModelPair ¶
type ModelPair struct{ Provider, Model string }
ModelPair identifies an untranslated provider and model.
type Point ¶
Point is one UTC series bucket. Unlike Summary, its Errors exclude cancelled attempts and its CostUSD only includes positive charges, like the log histograms.
type Result ¶
Result contains the totals, the zero-filled series, and one summary per group predicate in input order.
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.