Skip to content

Commit c7b9f37

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go

Lines changed: 15 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.filterBlackList(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,15 @@ func (s *filelogWatcher) watchLoop() {
129132
s.logCh <- log
130133
}
131134
}
135+
136+
func (s *filelogWatcher) filterBlackList(line string) bool {
137+
if s.cfg.BlackList == nil || len(s.cfg.BlackList) == 0 {
138+
return false
139+
}
140+
for _ , blackItem := range s.cfg.BlackList {
141+
if strings.Contains(line, blackItem) {
142+
return true
143+
}
144+
}
145+
return false
146+
}

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 black list by simple filter to avoid running more efforts in regex
40+
BlackList []string `json:"blackList,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)