Skip to content

Commit 3a386a6

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

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

config/disk-log-message-filelog.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"plugin": "filelog",
3+
"pluginConfig": {
4+
"timestamp": "^.{15}",
5+
"message": "(?i)Currently unreadable.*sectors|(?i)Offline uncorrectable sectors",
6+
"timestampFormat": "Jan _2 15:04:05"
7+
},
8+
"logPath": "/var/log/messages",
9+
"lookback": "10h",
10+
"bufferSize": 1,
11+
"source": "disk-monitor",
12+
"skipList": [ " audit:", " audit[" ],
13+
"conditions": [
14+
{
15+
"type": "DiskBadBlock",
16+
"reason": "DiskBadBlock",
17+
"message": "Disk no bad block"
18+
},
19+
],
20+
"rules": [
21+
{
22+
"type": "permanent",
23+
"condition": "DiskBadBlock",
24+
"reason": "DiskBadBlock",
25+
"pattern": ".*([1-9]\\d{2,}) (Currently unreadable.*sectors|Offline uncorrectable sectors).*"
26+
},
27+
]
28+
}

pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go

+12
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/filelog/log_watcher_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,36 @@ Jan 2 03:04:05 kernel: [2.000000] 3
176176
}
177177
}
178178
}
179+
180+
func TestFilterSkipList(t *testing.T) {
181+
s := &filelogWatcher{
182+
cfg: types.WatcherConfig{
183+
SkipList: []string{
184+
" audit:", " kubelet:",
185+
},
186+
},
187+
}
188+
testcase := []struct{
189+
log string
190+
expect bool
191+
}{
192+
{
193+
log: `Jan 2 03:04:03 kernel: [0.000000] 1`,
194+
expect: false,
195+
},
196+
{
197+
log: `Jan 2 03:04:04 audit: [1.000000] 2`,
198+
expect: true,
199+
},
200+
{
201+
log: `Jan 2 03:04:05 kubelet: [2.000000] 3`,
202+
expect: true,
203+
204+
},
205+
}
206+
for i, test := range testcase {
207+
if s.filterSkipList(test.log) != test.expect {
208+
t.Errorf("test case %d: expect %v but got %v", i, test.expect, s.filterSkipList(test.log))
209+
}
210+
}
211+
}

pkg/systemlogmonitor/logwatchers/types/log_watcher.go

+2
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)