Documentation
¶
Overview ¶
Package rule provides the rule matching and routing engine for CoreC data points.
Index ¶
- func EvalArith(exprStr string, value float64) (float64, error)
- type Engine
- func (e *Engine) AddProvider(p core.RuleProvider)
- func (e *Engine) CloseProviders()
- func (e *Engine) Match(point core.DataPoint) *MatchResult
- func (e *Engine) ProviderCount() int
- func (e *Engine) RuleStats() []core.RuleStat
- func (e *Engine) Rules() []core.Rule
- func (e *Engine) SetRuleDisabled(index int, disabled bool) error
- func (e *Engine) SetRules(configs []core.RuleConfig) error
- func (e *Engine) SetSubRules(groups map[string][]core.RuleConfig) error
- type FileProvider
- type MatchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the rule matching engine. It evaluates DataPoints against a priority-sorted list of rules using a linear scan, so that every evaluated rule records its hit/miss statistics and the priority order is preserved (see the Match doc comment for the full rationale).
func (*Engine) AddProvider ¶
func (e *Engine) AddProvider(p core.RuleProvider)
AddProvider registers a rule provider for RULE-SET references.
func (*Engine) CloseProviders ¶ added in v0.0.2
func (e *Engine) CloseProviders()
CloseProviders closes and removes all registered rule providers, stopping any background goroutines they started (e.g. reload loops). This should be called during engine Stop/Reload to prevent goroutine leaks (problem 4).
func (*Engine) Match ¶
func (e *Engine) Match(point core.DataPoint) *MatchResult
Match finds the first matching rule for a DataPoint. Rules are evaluated in priority order (lower priority = higher precedence). Returns nil if no rule matches.
Match intentionally uses a linear scan over e.rules rather than tag/driver indexes. Using indexes would break two invariants that existing tests rely on:
- Priority order — candidates gathered from separate index buckets are each sorted by priority but are NOT globally sorted across buckets, so the first bucket hit could be a lower-priority rule than one in another bucket (see TestEngineMatch).
- Statistics — ruleWrapper.Match updates hit/miss counters on every evaluation. Indexed lookup skips rules whose indexed tag/driver differs from the point, so those rules would never record their misses even though they sit before the first match in priority order (see TestRuleStats / TestWrapperStats). Because matchInRules returns on the first match, only rules up to and including that match are evaluated — exactly the set the linear scan covers.
Correctness is preserved over performance.
func (*Engine) ProviderCount ¶ added in v0.0.2
ProviderCount returns the number of registered rule providers.
func (*Engine) SetRuleDisabled ¶
SetRuleDisabled enables or disables a rule by index.
func (*Engine) SetRules ¶
func (e *Engine) SetRules(configs []core.RuleConfig) error
SetRules parses rule configs and sets the active rule set.
func (*Engine) SetSubRules ¶
func (e *Engine) SetSubRules(groups map[string][]core.RuleConfig) error
SetSubRules parses named sub-rule groups for SUB-RULE references.
type FileProvider ¶
type FileProvider struct {
// contains filtered or unexported fields
}
FileProvider loads match-only rules from a YAML file and supports hot-reload at a configurable interval.
func NewFileProvider ¶
func NewFileProvider(name, path, intervalStr string) (*FileProvider, error)
NewFileProvider creates a file-based rule provider. interval is the hot-reload interval; 0 means no auto-reload.
func (*FileProvider) Count ¶
func (p *FileProvider) Count() int
func (*FileProvider) Initial ¶
func (p *FileProvider) Initial() error
Initial loads the provider data (already done in constructor, kept for interface compat).
func (*FileProvider) Match ¶
func (p *FileProvider) Match(point core.DataPoint) bool
Match returns true if any rule in the provider matches the DataPoint.
func (*FileProvider) Name ¶
func (p *FileProvider) Name() string
func (*FileProvider) Update ¶
func (p *FileProvider) Update() error
Update forces a reload of the provider file.
type MatchResult ¶
type MatchResult = core.RuleMatchResult
MatchResult contains the matched rule and resolved targets. It is an alias for core.RuleMatchResult so the concrete rule.Engine satisfies the core.RuleEngine port (whose Match returns *core.RuleMatchResult) without any conversion at the call site.