Precompile log buffer regular expressions

Compile fixed patterns during monitor and log counter initialization, pass compiled expressions to the log buffer, and reject invalid log counter patterns before watching logs.
This commit is contained in:
Ciprian Hacman
2026-07-25 09:21:31 +03:00
parent 3b47d535b6
commit b02e2dcd09
6 changed files with 103 additions and 33 deletions
+7 -6
View File
@@ -59,13 +59,14 @@ func (mc *MonitorConfig) ApplyDefaultConfiguration() {
}
}
// ValidateRules verifies whether the regular expressions in the rules are valid.
func (mc MonitorConfig) ValidateRules() error {
for _, rule := range mc.Rules {
_, err := regexp.Compile(rule.Pattern)
func (mc MonitorConfig) compileRules() ([]*regexp.Regexp, error) {
patterns := make([]*regexp.Regexp, len(mc.Rules))
for i, rule := range mc.Rules {
pattern, err := CompilePattern(rule.Pattern)
if err != nil {
return err
return nil, err
}
patterns[i] = pattern
}
return nil
return patterns, nil
}