Documentation
¶
Overview ¶
Package chronos defines the public extension surface of the Chronos engine.
Chronos is a data-source-agnostic pattern detection engine for time-series data. The engine is generic — it knows nothing about the domain it serves. All domain knowledge enters through adapters that implement Source and produce [EntityState]s. Insights are derived from those states and surfaced through the HTTP API.
This package is the contract between the engine and adapter authors. It is deliberately small: an EntityState data type, a Source interface, and a process-wide registry. Internal domain logic, persistence, similarity, and insight generation live under internal/ and are not part of the public API.
Adapters self-register via init():
package myadapter
import "github.com/felixgeelhaar/chronos"
func init() { chronos.Register(&Source{}) }
Index ¶
Constants ¶
const ( PatternTypeRecurrence = domain.PatternTypeRecurrence PatternTypeTrend = domain.PatternTypeTrend PatternTypeSpike = domain.PatternTypeSpike PatternTypeDrop = domain.PatternTypeDrop PatternTypeStall = domain.PatternTypeStall PatternTypeAnomaly = domain.PatternTypeAnomaly PatternTypeSeasonality = domain.PatternTypeSeasonality PatternTypeCorrelation = domain.PatternTypeCorrelation PatternTypeChangePoint = domain.PatternTypeChangePoint PatternTypeOutlierCluster = domain.PatternTypeOutlierCluster PatternTypeCrossScopeCorrelation = domain.PatternTypeCrossScopeCorrelation )
PatternType constants re-exported for callers that want to filter queries by pattern without importing internal/domain.
const ( ConfidenceClassTentative = domain.ConfidenceClassTentative ConfidenceClassEstablished = domain.ConfidenceClassEstablished ConfidenceClassStrong = domain.ConfidenceClassStrong )
ConfidenceClass constants re-exported.
Variables ¶
var ( ErrMissingEntityID = errors.New("chronos: entity state missing entity ID") ErrMissingScopeID = errors.New("chronos: entity state missing scope ID") ErrMissingFeatures = errors.New("chronos: entity state has no features") ErrLabelsMismatch = errors.New("chronos: labels length does not match features length") )
Errors returned by validation on public types.
Functions ¶
func Adapters ¶
func Adapters() []string
Adapters returns the names of all registered adapters in unspecified order. Useful for "chronos compute --help" output and registry diagnostics.
func Register ¶
func Register(src Source)
Register adds src to the global adapter registry, keyed on src.Name(). It panics if src or src.Name() is empty so registration mistakes surface at program start.
Re-registering an adapter under the same name overwrites the previous entry (last-write-wins). This is intentional so a program that imports both the library surface and the cmd/chronos binary doesn't panic on duplicate init() registration; see ADR 0001.
Types ¶
type Closer ¶
type Closer interface {
Close() error
}
Closer is implemented by sources that own external resources (for example a database connection). The engine will call Close on any source that implements it during shutdown.
type ConfidenceClass ¶ added in v0.6.0
type ConfidenceClass = domain.ConfidenceClass
ConfidenceClass classifies a Signal's confidence into tentative / established / strong tiers for downstream filters.
type EntityState ¶
type EntityState struct {
ID uuid.UUID // unique observation ID
EntityID uuid.UUID // the entity (athlete, server, sensor, …)
ScopeID uuid.UUID // the scope (coach, team, tenant, …)
Timestamp time.Time // when this state was observed
Features []float64 // numeric feature vector; last element is the outcome
Labels []string // optional human-readable feature names; len(Labels)==len(Features) when set
Meta map[string]string // adapter-specific metadata; not used for similarity
}
EntityState is a single observation of an entity at a point in time, encoded as a vector of numeric features. Adapters map their domain-specific data into this generic shape.
Conventions the engine relies on:
- The last element of Features is treated as the outcome metric. Higher values are interpreted as "better outcomes" for the purposes of OutcomeDirection in generated insights.
- ScopeID is the grouping primitive: insights are generated by comparing entities only against other entities sharing the same ScopeID.
- Meta is opaque adapter metadata. It is not used for similarity computation; it is preserved for downstream presentation.
func (EntityState) Outcome ¶
func (s EntityState) Outcome() float64
Outcome returns the conventional outcome metric (the last feature). It returns zero when Features is empty; callers should validate first.
func (EntityState) Validate ¶
func (s EntityState) Validate() error
Validate enforces the EntityState invariants. Adapters and stores must call it before returning or persisting an entity state.
type Explanation ¶ added in v0.6.0
type Explanation = domain.Explanation
Explanation carries the detector's per-Signal reasoning artefacts (feature evolution, baseline references, contributing factors).
type FeatureSample ¶ added in v0.6.0
type FeatureSample = domain.FeatureSample
FeatureSample is one numeric observation within a TimeWindow, carried inside Evidence for explainability.
type PatternType ¶ added in v0.6.0
type PatternType = domain.PatternType
PatternType names the kind of pattern a Signal represents.
type Signal ¶ added in v0.6.0
Signal is an inference the detection engine emits when it sees a pattern in a series of entity states (spike, drop, trend, etc.).
type Source ¶
type Source interface {
// Name returns the stable adapter identifier (e.g. "ascend", "prometheus").
// The name is used to register and look up the adapter and is persisted
// alongside each EntityState.
Name() string
// Fetch retrieves entity states from the external source. Implementations
// must respect ctx cancellation and should return wrapped errors.
Fetch(ctx context.Context, cfg map[string]string) ([]EntityState, error)
}
Source is the inbound contract for adapters. Implementations map external data into a slice of [EntityState]s. The cfg map carries adapter-specific parameters (for example "tenant_id" for a SaaS adapter); the engine passes through whatever was supplied at the CLI or API boundary.
type TimeWindow ¶ added in v0.6.0
type TimeWindow = domain.TimeWindow
TimeWindow bounds the period of observation a Signal references.
Directories
¶
| Path | Synopsis |
|---|---|
|
api
|
|
|
Package client is the public Go SDK for the Chronos HTTP API.
|
Package client is the public Go SDK for the Chronos HTTP API. |
|
cmd
|
|
|
chronos
command
Package main is the chronos command-line entrypoint.
|
Package main is the chronos command-line entrypoint. |
|
Package embed exposes Chronos as an in-process Go library.
|
Package embed exposes Chronos as an in-process Go library. |
|
internal
|
|
|
api
Package api provides Chronos's HTTP REST API.
|
Package api provides Chronos's HTTP REST API. |
|
api/grpc
Package grpc provides Chronos's gRPC transport layer.
|
Package grpc provides Chronos's gRPC transport layer. |
|
config
Package config provides Chronos configuration.
|
Package config provides Chronos configuration. |
|
detect
Package detect contains Chronos's pattern detectors and the engine that fans observations out across them.
|
Package detect contains Chronos's pattern detectors and the engine that fans observations out across them. |
|
domain
Package domain holds the engine's private domain model.
|
Package domain holds the engine's private domain model. |
|
notify
Package notify implements outbound transports for newly-detected signals.
|
Package notify implements outbound transports for newly-detected signals. |
|
observability
Package observability exposes Chronos's runtime metrics in Prometheus exposition format.
|
Package observability exposes Chronos's runtime metrics in Prometheus exposition format. |
|
pipeline
Package pipeline orchestrates Chronos's compute job.
|
Package pipeline orchestrates Chronos's compute job. |
|
ports
Package ports declares the outbound interfaces ("ports") the engine drives.
|
Package ports declares the outbound interfaces ("ports") the engine drives. |
|
similarity
Package similarity provides generic similarity computation for feature vectors.
|
Package similarity provides generic similarity computation for feature vectors. |
|
store
Package store wires Chronos's persistence backends behind a single scheme-dispatched factory.
|
Package store wires Chronos's persistence backends behind a single scheme-dispatched factory. |
|
store/batching
Package batching provides a write-coalescing decorator for the EntityStateRepository port.
|
Package batching provides a write-coalescing decorator for the EntityStateRepository port. |
|
store/libsql
Package libsql implements a store provider backed by libSQL — the SQLite-compatible engine behind Turso.
|
Package libsql implements a store provider backed by libSQL — the SQLite-compatible engine behind Turso. |
|
store/memory
Package memory provides in-memory implementations of the persistence ports defined in internal/ports.
|
Package memory provides in-memory implementations of the persistence ports defined in internal/ports. |
|
store/mysql
Package mysql implements a store provider backed by MySQL or MariaDB.
|
Package mysql implements a store provider backed by MySQL or MariaDB. |
|
store/postgres
Package postgres provides a PostgreSQL-backed implementation of the persistence ports.
|
Package postgres provides a PostgreSQL-backed implementation of the persistence ports. |
|
store/sqlite
Package sqlite provides a SQLite-backed implementation of the persistence ports.
|
Package sqlite provides a SQLite-backed implementation of the persistence ports. |
|
storage
|
|
|
all
Package all registers every Chronos SQL storage backend at once (Postgres, SQLite, MySQL/MariaDB, libSQL) for consumers that don't want to pick individual drivers.
|
Package all registers every Chronos SQL storage backend at once (Postgres, SQLite, MySQL/MariaDB, libSQL) for consumers that don't want to pick individual drivers. |
|
libsql
Package libsql registers Chronos's libSQL storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("libsql://…")).
|
Package libsql registers Chronos's libSQL storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("libsql://…")). |
|
mysql
Package mysql registers Chronos's MySQL/MariaDB storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("mysql://HOST/DB")).
|
Package mysql registers Chronos's MySQL/MariaDB storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("mysql://HOST/DB")). |
|
postgres
Package postgres registers Chronos's Postgres storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("postgres://…")).
|
Package postgres registers Chronos's Postgres storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("postgres://…")). |
|
sqlite
Package sqlite registers Chronos's SQLite storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("sqlite:///path/chronos.db")).
|
Package sqlite registers Chronos's SQLite storage backend so an external consumer can build a durable engine with embed.New(embed.WithStorage("sqlite:///path/chronos.db")). |