Skip to content

Commit 2b5c836

Browse files
committed
add skip list to aviod take too much efforts to translate in file log watcher
1 parent 35ffe05 commit 2b5c836

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func (s *filelogWatcher) watchLoop() {
116116
}
117117
line = buffer.String()
118118
buffer.Reset()
119+
if s.filterSkipList(line) {
120+
continue
121+
}
119122
log, err := s.translator.translate(strings.TrimSuffix(line, "\n"))
120123
if err != nil {
121124
klog.Warningf("Unable to parse line: %q, %v", line, err)
@@ -129,3 +132,12 @@ func (s *filelogWatcher) watchLoop() {
129132
s.logCh <- log
130133
}
131134
}
135+
136+
func (s *filelogWatcher) filterSkipList(line string) bool {
137+
for _ , skipItem := range s.cfg.SkipList {
138+
if strings.Contains(line, skipItem) {
139+
return true
140+
}
141+
}
142+
return false
143+
}

pkg/systemlogmonitor/logwatchers/types/log_watcher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type WatcherConfig struct {
3636
// PluginConfig is a key/value configuration of a plugin. Valid configurations
3737
// are defined in different log watcher plugin.
3838
PluginConfig map[string]string `json:"pluginConfig,omitempty"`
39+
// Skip the log lines containing any of the strings in the list to avoid running unnecessary regex.
40+
SkipList []string `json:"skipList,omitempty"`
3941
// LogPath is the path to the log
4042
LogPath string `json:"logPath,omitempty"`
4143
// Lookback is the time log watcher looks up

0 commit comments

Comments
 (0)