Documentation
¶
Overview ¶
Package state owns everything Inobi persists.
Index ¶
- Constants
- Variables
- func AppendGroupKey(dst []byte, data map[string]any, fields [][]string) ([]byte, bool)
- func EscapePart(s string) string
- func GroupKey(data map[string]any, fields [][]string) (string, bool)
- type CompositeItem
- type CompositeUpdate
- type Composites
- type DB
- func (db *DB) Close() error
- func (db *DB) Composites() Composites
- func (db *DB) DeleteEntries(filter Filter) (int, error)
- func (db *DB) Entries(filter Filter) ([]Entry, error)
- func (db *DB) Flush() error
- func (db *DB) KV(rid ruleset.RuleID) KV
- func (db *DB) Risk() Risk
- func (db *DB) RunGC(ctx context.Context)
- func (db *DB) Sources() Sources
- func (db *DB) Timeouts() Timeouts
- func (db *DB) Usage(filter Filter) ([]Usage, error)
- type ETCompositeState
- type Entry
- type Filter
- type KV
- func (kv KV) Add(k string, val any, ttl time.Duration) (float64, error)
- func (kv KV) Delete(k string) error
- func (kv KV) Exists(k string) (bool, error)
- func (kv KV) Get(k string) (any, error)
- func (kv KV) Set(k string, value any, ttl time.Duration) error
- func (kv KV) Swap(k string, value any, ttl time.Duration) (any, error)
- type Kind
- type Options
- type Risk
- func (r Risk) AlertedLevel(entityType, entityValue string) (int, bool, error)
- func (r Risk) Contributions(entityType, entityValue string) ([]RiskContribution, error)
- func (r Risk) Delete(entityType, entityValue string) (bool, error)
- func (r Risk) DeleteAlertedLevel(entityType, entityValue string) error
- func (r Risk) Entities() ([]RiskEntity, error)
- func (r Risk) SetAlertedLevel(entityType, entityValue string, rank int, ttl time.Duration) error
- func (r Risk) UpdateContributions(entityType, entityValue string, ...) error
- type RiskContribution
- type RiskEntity
- type SourcePosition
- type Sources
- type Timeouts
- type Usage
Constants ¶
const ( LargeValueSize = 1 << 20 DefaultFlushInterval = time.Second )
const ( NSKV = "h" NSComposite = "c" NSTimeout = "t" NSRisk = "r" NSRiskAlertedLevel = "rl" NSSource = "s" NSMeta = "m" )
Key layout: - h:<rule id>:<kv key> - c:<rule id>:<group> - t:<rule id>:<group> - r:<entity type>:<entity value> - rl:<entity type>:<entity value> - s:<source id> - m:<name>
Every part except the last is escaped.
const FormatVersion = 1
FormatVersion must be bumped whenever the key layout or a value encoding changes incompatibly.
Variables ¶
var ( ErrFormatVersion = errors.New("unsupported state format version") ErrNotExist = errors.New("no state database") ErrInUse = errors.New("state directory in use, ensure inobi is not running") )
var ErrBadType = errors.New("bad type")
var Kinds = []Kind{KindKV, KindComposite, KindTimeout, KindRisk, KindSource}
Functions ¶
func AppendGroupKey ¶
Types ¶
type CompositeItem ¶
type CompositeUpdate ¶
type CompositeUpdate int
const ( CompositeKeep CompositeUpdate = iota CompositeWrite CompositeClear )
type Composites ¶
type Composites struct {
// contains filtered or unexported fields
}
func (Composites) Update ¶
func (c Composites) Update(rid ruleset.RuleID, group string, ttl time.Duration, fn func(items *[]CompositeItem) CompositeUpdate) error
func (Composites) UpdateET ¶
func (c Composites) UpdateET(rid ruleset.RuleID, group string, ttl time.Duration, fn func(st *ETCompositeState) CompositeUpdate) error
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Composites ¶
func (db *DB) Composites() Composites
type ETCompositeState ¶
type ETCompositeState struct {
MaxEventTS time.Time `json:"ts"`
Parts [][]CompositeItem `json:"p"`
Chains [][]CompositeItem `json:"c,omitempty"`
}
ETCompositeState holds each part's events sorted by time. Events older than MaxEventTS minus the allowed lateness are settled: no new event can precede them, so they are compacted (see engine.compactETComposite) into at most one item per part, or for ordered rules into Chains, where Chains[i] is the settled sequence of parts 0..i with the latest start.
type Options ¶
type Options struct {
Dir string
MustExist bool
InMemory bool
SyncWrites bool
FlushInterval time.Duration
Logger *slog.Logger
Operations *prometheus.CounterVec // Has "operation" and "status" labels.
LargeValues *prometheus.CounterVec // Has a "rule_id" label.
}
type Risk ¶
type Risk struct {
// contains filtered or unexported fields
}
func (Risk) AlertedLevel ¶
func (Risk) Contributions ¶
func (r Risk) Contributions(entityType, entityValue string) ([]RiskContribution, error)
func (Risk) DeleteAlertedLevel ¶
func (Risk) Entities ¶
func (r Risk) Entities() ([]RiskEntity, error)
func (Risk) SetAlertedLevel ¶
func (Risk) UpdateContributions ¶
type RiskContribution ¶
type RiskEntity ¶
type RiskEntity struct {
Type string
Value string
Contributions []RiskContribution
AlertedLevel int
Alerted bool
}
type SourcePosition ¶
type Sources ¶
type Sources struct {
// contains filtered or unexported fields
}
func (Sources) List ¶
func (s Sources) List() ([]SourcePosition, error)