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 sorted list of rules. Rules are indexed by tag and driver for O(1) lookup in the common case; ALL and complex-expression rules fall back to a linear scan.
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). A linear scan is used so that every evaluated rule updates its hit/miss statistics — tag/driver indexed lookup would skip non-matching rules, leaving their miss count at 0. Returns nil if no rule matches.
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 struct {
Rule core.Rule
Targets []string
Transform *core.TransformConfig
}
MatchResult contains the matched rule and resolved targets.