MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Compile

Method Compile

pkg/rules/engine.go:161–210  ·  view source on GitHub ↗

Compile loads macros/rules and builds an indexable filter set. For every rule in the ruleset the condition is compiled and converted into a filter. The filter is indexed by either the event name or event category.

()

Source from the content-addressed store, hash-verified

159// converted into a filter. The filter is indexed by either the
160// event name or event category.
161func (e *Engine) Compile() (*config.RulesCompileResult, error) {
162 filters, rs, err := e.compiler.compile()
163 if err != nil {
164 return nil, err
165 }
166
167 for c, f := range filters {
168 var ss *sequenceState
169 if f.IsSequence() {
170 ss = newSequenceState(f, c, e.psnap)
171 }
172 fltr := newCompiledFilter(f, c, ss)
173 if ss != nil {
174 // store the sequences in engine
175 // for more convenient tracking
176 e.sequences = append(e.sequences, ss)
177 }
178
179 if !fltr.isScoped() {
180 log.Warnf("%q rule doesn't have "+
181 "event type or event category condition! "+
182 "This rule is being discarded by "+
183 "the engine. Please consider narrowing the "+
184 "scope of the rule by including the `evt.name` "+
185 "or `evt.category` condition",
186 c.Name)
187 continue
188 }
189
190 // traverse all event name or category fields and determine
191 // the event type from the filter field name expression.
192 // We end up with a map of rules indexed by event type
193 // or event category
194 for name, values := range f.GetStringFields() {
195 for _, v := range values {
196 switch name {
197 case fields.EvtName:
198 for _, typ := range event.NameToTypes(v) {
199 e.filters.types[typ] = append(e.filters.types[typ], fltr)
200 }
201 case fields.EvtCategory:
202 category := event.Category(v)
203 e.filters.categories[category.Index()] = append(e.filters.categories[category.Index()], fltr)
204 }
205 }
206 }
207 }
208
209 return rs, nil
210}
211
212func (e *Engine) RegisterMatchFunc(fn RuleMatchFunc) {
213 e.matchFunc = fn

Callers 2

BenchmarkRunRulesFunction · 0.95
NewAppFunction · 0.95

Calls 9

NameToTypesFunction · 0.92
CategoryTypeAlias · 0.92
newSequenceStateFunction · 0.85
newCompiledFilterFunction · 0.85
compileMethod · 0.80
isScopedMethod · 0.80
IndexMethod · 0.80
IsSequenceMethod · 0.65
GetStringFieldsMethod · 0.65

Tested by 1

BenchmarkRunRulesFunction · 0.76