Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type DataType
- type PathStatsSnapshot
- type PathUpdate
- type Sampler
- func (s *Sampler) Close() error
- func (s *Sampler) DeleteSchema(ctx context.Context, schemaID string) error
- func (s *Sampler) Flush() error
- func (s *Sampler) GetSchema(ctx context.Context, schemaID string) (*SchemaNode, error)
- func (s *Sampler) Sample(ctx context.Context, schemaID string, payload any) error
- func (s *Sampler) Stats() SamplerStats
- type SamplerStats
- type SchemaNode
- type StatsBackend
Constants ¶
const Version = "1.0.0"
Version is the current version of the assay library.
Variables ¶
var ErrClosed = errors.New("assay: sampler is closed")
ErrClosed is returned when an operation is performed on a closed sampler.
var ErrMaxDepthExceeded = errors.New("maximum JSON nesting depth exceeded")
ErrMaxDepthExceeded is returned when the payload exceeds the maximum depth limit.
var ErrMaxSchemasExceeded = errors.New("maximum schema count exceeded")
ErrMaxSchemasExceeded is returned when the maximum number of active schemas is reached.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
MaxDepth int // Prevents Stack Overflow (Default: 32)
MaxPaths int // Prevents Cardinality Explosion (Default: 1000)
MaxSchemas int // Prevents unbounded schema creation (Default: 1000)
MaxArrayElements int // Max array/slice elements profiled (Default: 10)
FlushInterval time.Duration // Interval for buffering writes to stats backend (Default: 100ms. Set to -1 to disable periodic background flushing)
FlushTimeout time.Duration // Timeout for individual backend writes (Default: 3s)
OnError func(error) // Optional callback to handle flush or background errors
}
Config defines execution and limits for safety.
type PathStatsSnapshot ¶
PathStatsSnapshot represents the snapshot of a path's counters.
type PathUpdate ¶
PathUpdate represents an aggregated increment update for a path and type.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler is the entrypoint coordinator. Sampler must not be copied after creation.
func NewSampler ¶
func NewSampler(backend StatsBackend, cfg Config) (*Sampler, error)
NewSampler initializes a new Sampler with a backend and configuration.
func (*Sampler) Close ¶
Close flushes any pending stats and shuts down the background flushing worker. It returns an error if the shutdown or final flush timed out or failed.
func (*Sampler) DeleteSchema ¶ added in v0.2.0
DeleteSchema removes a schema ID and all its accumulated stats from local memory and deletes the schema's metrics from the persistent stats backend.
func (*Sampler) Flush ¶ added in v0.4.0
Flush forces an immediate synchronous flush of all locally accumulated statistics to the backend. It returns an error if any flush operation failed.
func (*Sampler) GetSchema ¶
GetSchema reconstructs and returns the computed schema tree from the backend metrics.
func (*Sampler) Sample ¶
Sample parses the incoming payload and updates stats in the local buffer. payload can be: []byte (JSON), map[string]any, or a Struct pointer.
func (*Sampler) Stats ¶ added in v0.6.0
func (s *Sampler) Stats() SamplerStats
Stats returns a snapshot of the Sampler's metrics.
type SamplerStats ¶ added in v0.6.0
type SamplerStats struct {
ActiveSchemas int64
IngestedSamples uint64
DroppedSamples uint64
RejectedSamples uint64
FlushSuccesses uint64
FlushFailures uint64
}
SamplerStats contains metrics and observability data for the Sampler.
type SchemaNode ¶
type SchemaNode struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "string", "number", "mixed", "null", "object", etc.
Required bool `json:"required"` // Evaluated against parent observation frequency
Probability map[string]float64 `json:"probability"` // E.g., {"string": 0.95, "number": 0.05}
Children map[string]*SchemaNode `json:"children,omitempty"`
}
SchemaNode represents a reconstructed node in the schema tree. Note: This structure is not safe for concurrent mutation. If multiple goroutines write to the returned tree, external synchronization is required.
type StatsBackend ¶
type StatsBackend interface {
MapIncrementBy(ctx context.Context, key, field string, delta float64) (float64, error)
MapGetAll(ctx context.Context, key string) (map[string]string, error)
Delete(ctx context.Context, key string) error
}
StatsBackend represents the abstraction layer for stats storage. It matches Capacitor's MapIncrementBy, MapGetAll, and Delete methods, enabling implicit integration.