Documentation
¶
Overview ¶
Package aggregator provides persistent storage and periodic snapshotting of aggregated analytics stats to PostgreSQL.
Index ¶
- type Store
- func (s *Store) LatestSnapshot(ctx context.Context) (*analytics.AggregatedStats, error)
- func (s *Store) ListSnapshots(ctx context.Context, limit int) ([]analytics.AggregatedStats, error)
- func (s *Store) SaveSnapshot(ctx context.Context, stats analytics.AggregatedStats) error
- func (s *Store) StartPeriodicSave(ctx context.Context, agg *analytics.Aggregator, interval time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists aggregated analytics snapshots in PostgreSQL.
It requires an `analytics_snapshots` table:
CREATE TABLE analytics_snapshots (
id BIGSERIAL PRIMARY KEY,
data JSONB NOT NULL,
captured_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
func (*Store) LatestSnapshot ¶
LatestSnapshot loads the most recent snapshot from the database. Returns nil, nil if no snapshots exist yet.
func (*Store) ListSnapshots ¶
ListSnapshots returns the last N snapshots, newest first.
func (*Store) SaveSnapshot ¶
SaveSnapshot persists a stats snapshot to the database.
func (*Store) StartPeriodicSave ¶
func (s *Store) StartPeriodicSave(ctx context.Context, agg *analytics.Aggregator, interval time.Duration)
StartPeriodicSave launches a goroutine that periodically snapshots the aggregator's current stats to the database.
Click to show internal directories.
Click to hide internal directories.