rule

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rule provides the rule matching and routing engine for CoreC data points.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalArith

func EvalArith(exprStr string, value float64) (float64, error)

EvalArith parses and evaluates an arithmetic expression against the given value. The expression must reference the variable as `value`. Compiled programs are cached for reuse across calls with the same expression.

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 NewEngine

func NewEngine() *Engine

NewEngine creates a new rule engine.

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

func (e *Engine) ProviderCount() int

ProviderCount returns the number of registered rule providers.

func (*Engine) RuleStats

func (e *Engine) RuleStats() []core.RuleStat

RuleStats returns runtime statistics for all rules.

func (*Engine) Rules

func (e *Engine) Rules() []core.Rule

Rules returns the active rules.

func (*Engine) SetRuleDisabled

func (e *Engine) SetRuleDisabled(index int, disabled bool) error

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) Close

func (p *FileProvider) Close()

Close stops the reload goroutine.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL