Documentation
¶
Index ¶
- Constants
- Variables
- func CompareFloat(a, b float64, c string) bool
- func ComparerTypeName(condition *Condition) string
- func ConnectCondition(res bool, eval bool, connector string) bool
- func GetDynamicParamValue(ctx *Context, value string) string
- func RunAction(funcs ValueFuncs, ctx *Context, action *Action, dryRun bool) error
- type Action
- type ActionTrigger
- type Condition
- type Context
- type Criteria
- type DataSource
- type DefaultEvaluator
- type EvalResult
- type Evaluator
- type Event
- type Facts
- type FuncMap
- type Parameter
- type Rule
- type Span
- type Spans
- type ValueFuncs
Constants ¶
View Source
const ( CONNECTOR_AND string = "&&" CONNECTOR_OR string = "||" COMPARER_EQUAL string = "==" COMPARER_NOT_EQUAL string = "!=" COMPARER_GREATER string = ">" COMPARER_GREATER_OR_EQUAL string = ">=" COMPARER_LESS string = "<" COMPARER_LESS_OR_EQUAL string = "<=" COMPARER_BETWEEN string = "<>" COMPARER_EXISTS string = "!!" COMPARER_NOT_SET string = "null" COMPARER_IN string = "in" COMPARER_NOT_IN string = "nin" COMPARER_MATCH string = "match" COMPARER_MATCH_NOT string = "dontmatch" COMPARER_ANY string = "any" COMPARER_ALL string = "all" COMPARER_NONE string = "none" PARAMTYPE_STRING string = "string" PARAMTYPE_NUMBER string = "number" PARAMTYPE_FLOAT string = "float" PARAMTYPE_FRACTION string = "fraction" PARAMTYPE_BOOL string = "bool" PARAMTYPE_DATE string = "date" PARAMTYPE_DATETIME string = "datetime" PARAMTYPE_EVENT string = "eventType" PARAMTYPE_DURATION string = "duration" PARAMTYPE_FIELDS string = "eventFields" RETURNTYPE_ARRAY string = "array" AGGREGATE_AVARAGE string = "avg" AGGREGATE_TOTAL string = "sum" AGGREGATE_MINIMUM string = "min" AGGREGATE_MAXIMUM string = "max" )
View Source
const ( EventPrefix = "rules." Status = EventPrefix + "status" CmdReload = EventPrefix + "reload" CmdStop = EventPrefix + "stop" CmdResume = EventPrefix + "resume" )
View Source
const ( DRY_RUN_KEY = "dryRun" ON_FAIL_DEACTIVATE = 0 ON_FAIL_KEEPACTIVE = 1 ON_UNMET_NOOP = 0 ON_UNMET_LOG = 1 ON_MET_NOOP = 0 ON_MET_LOG = 1 )
Variables ¶
View Source
var ( // using an empty struct{} here has the advantage that it doesn't require any additional space // and go's internal map type is optimized for that kind of values // therefore map[string]struct{} is a popular choice for sets in the go world CommandTopics = map[string]struct{}{ CmdReload: {}, CmdStop: {}, CmdResume: {}, } )
Functions ¶
func CompareFloat ¶
func ComparerTypeName ¶
func GetDynamicParamValue ¶
Types ¶
type ActionTrigger ¶
type Condition ¶
type Condition struct {
Field string `json:"field"`
Comparer string `json:"comparer"`
Connector string `json:"connector"`
Value string `json:"value"`
Type string `json:"type"`
Items []*Condition `json:"items"`
Method string `json:"method"`
Alias string `json:"alias"`
IsDynamic bool `json:"isDynamic"`
}
type Context ¶
type Context struct {
Facts Facts `json:"facts"`
Spans Spans `json:"spans,omitempty"`
RuleID string `json:"ruleId"`
RuleTitle string `json:"ruleTitle"`
}
func NewContext ¶
func NewContext(eventData interface{}) *Context
type Criteria ¶
type Criteria struct {
DataSource *DataSource `json:"datasource"`
Parameters []*Parameter `json:"parameters"`
Returns string `json:"returns"`
Connector string `json:"connector"`
Items []*Criteria `json:"items"`
Conditions []*Condition `json:"conditions"`
Filters []*Condition `json:"filters"`
Aggregations []*Condition `json:"aggregations"`
}
type DataSource ¶
type DefaultEvaluator ¶
type DefaultEvaluator struct{}
wrapper to fulfill evaluator interface
func (*DefaultEvaluator) EvaluateRule ¶
func (e *DefaultEvaluator) EvaluateRule(funcs ValueFuncs, ctx *Context, rule *Rule, event *Event) *EvalResult
type EvalResult ¶
type EvalResult struct {
Rule *Rule `json:"rule"`
Event *Event `json:"event"`
Context *Context `json:"context"`
Met bool `json:"met"`
Unmet bool `json:"unmet"`
MetReason string `json:"-"`
UnmetReason string `json:"-"`
Error error `json:"-"`
Duration time.Duration `json:"-"`
}
func (*EvalResult) MarshalJSON ¶
func (e *EvalResult) MarshalJSON() ([]byte, error)
type Evaluator ¶
type Evaluator interface {
EvaluateRule(funcs ValueFuncs, ctx *Context, rule *Rule, event *Event) *EvalResult
}
evaluator interface to support swappable implementations
type Rule ¶
type Rule struct {
ID string `json:"id"`
Archive bool `json:"archive"`
Active bool `json:"active"`
OnUnmet int `json:"onUnmet"`
OnMet int `json:"onMet"`
OnFail int `json:"onFail"`
Title string `json:"title"`
Desc string `json:"desc"`
Tags string `json:"tags"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Event string `json:"event"`
Criterias []*Criteria `json:"criterias"`
NoCriterias bool `json:"noCriterias"`
Chainable bool `json:"chainable"`
Actions []*Action `json:"actions"`
UnmetActions []*Action `json:"unmetActions"`
Scheduled bool `json:"scheduled"`
RunAt string `json:"runat"`
Cron string `json:"cron"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
ValidFrom time.Time `json:"validFrom"`
ValidTo time.Time `json:"validTo"`
Changes string `json:"changes"`
Metadata map[string]interface{} `json:"metadata"`
}
type Span ¶
type ValueFuncs ¶
func MakeValueFuncs ¶
func MakeValueFuncs(funcs FuncMap) ValueFuncs
Source Files
¶
Click to show internal directories.
Click to hide internal directories.