Help us shape the future of Go! Take the 2026 Go Developer Survey

analytics

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package analytics builds the AnalyticsStore: the zero-infrastructure stub (the default) or the Cassandra-protocol store (Apache Cassandra locally, Amazon Keyspaces in staging, chosen by the nested Cassandra config). Use New() or NewFromConfig(); decorate the result with the decorators subpackage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(kind Kind, opts ...options.Option[Config]) (interfaces.AnalyticsStore, error)

New creates an AnalyticsStore of the given kind with optional functional options.

func NewFromConfig

func NewFromConfig(cfg *Config) (interfaces.AnalyticsStore, error)

NewFromConfig creates an AnalyticsStore from cfg without I/O. The cassandra kind dials its session from cfg.Cassandra at Start (and, with EnsureSchema, creates its tables there, awaiting ACTIVE on Keyspaces); an unknown kind is CodeInvalidInput.

func WithCassandra

func WithCassandra(
	kind cassandra.Kind,
	opts ...options.Option[cassandra.Config],
) options.Option[Config]

WithCassandra sets the nested session kind and applies session options.

func WithCube

func WithCube(name string, grains ...types.Grain) options.Option[Config]

WithCube declares a cube and the grains it is rolled up at.

func WithEnsureSchema added in v0.3.6

func WithEnsureSchema() options.Option[Config]

WithEnsureSchema makes Start create the declared tables (see Config.EnsureSchema).

func WithMaxConcurrentBuckets

func WithMaxConcurrentBuckets(n int) options.Option[Config]

WithMaxConcurrentBuckets bounds a query's bucket fan-out.

func WithSessionFactory

func WithSessionFactory(f SessionFactory) options.Option[Config]

WithSessionFactory overrides how the Cassandra session is dialed.

func WithTTL

func WithTTL(grain types.Grain, d time.Duration) options.Option[Config]

WithTTL keeps rows of grain for d.

Types

type Config

type Config struct {
	// SessionFactory dials the session for KindCassandra (nil = cassandra.NewFromConfig).
	SessionFactory SessionFactory
	// BucketWidth is the partition bucket of each grain, as a coarser grain (a
	// grain's groups never span buckets): minute→hour, hour→day, day→month, month→month.
	BucketWidth map[types.Grain]types.Grain
	// Cubes declares each cube and the grains it is rolled up at (one table each).
	Cubes map[string][]types.Grain
	// TTL is how long a row of each grain is kept (0 or absent = forever).
	TTL map[types.Grain]time.Duration
	// Cassandra is the session config; its Kind picks Cassandra or Keyspaces.
	Cassandra cassandra.Config
	// Kind selects the backend.
	Kind Kind
	// MaxConcurrentBuckets bounds how many buckets a query reads at once.
	MaxConcurrentBuckets int
	// EnsureSchema makes the cassandra kind create every declared table at Start
	// and, on Amazon Keyspaces (Cassandra.Kind), wait until each one is ACTIVE.
	EnsureSchema bool
}

Config is the analytics store configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the stub kind with the default bucket widths, 8 concurrent buckets and the default Cassandra session config.

type Kind

type Kind int

Kind specifies which analytics store implementation to use.

const (
	// KindStub accepts writes and answers empty results (the default).
	KindStub Kind = iota
	// KindCassandra stores partial rows in Cassandra or Amazon Keyspaces.
	KindCassandra
)

func (Kind) String

func (k Kind) String() string

String returns the string representation of Kind.

type SessionFactory

type SessionFactory func(cfg *cassandra.Config) (cassandra.Session, error)

SessionFactory dials a Cassandra-protocol session from its config; the default is cassandra.NewFromConfig (injectable so the wiring is unit-testable).

Directories

Path Synopsis
Package cassandra is the Cassandra-protocol AnalyticsStore (Apache Cassandra or Amazon Keyspaces behind clients/cassandra.Session).
Package cassandra is the Cassandra-protocol AnalyticsStore (Apache Cassandra or Amazon Keyspaces behind clients/cassandra.Session).
Package decorators wraps an AnalyticsStore with resilience and observability, in the order recovery → metrics → tracing → circuit breaker → timeout (outermost first), and wraps a clients/cassandra.Session's writes in the client stack.
Package decorators wraps an AnalyticsStore with resilience and observability, in the order recovery → metrics → tracing → circuit breaker → timeout (outermost first), and wraps a clients/cassandra.Session's writes in the client stack.
Package stub is the default analytics store: it accepts every write and answers every query with an empty result, so the graph boots with no Cassandra.
Package stub is the default analytics store: it accepts every write and answers every query with an empty result, so the graph boots with no Cassandra.

Jump to

Keyboard shortcuts

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