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 ¶
This section is empty.
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 ¶
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 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 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.
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. |
|
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. |