Skip to content

Commit 81d34d2

Browse files
committed
add skiplist filter example in filelog config and add test case
1 parent 2b5c836 commit 81d34d2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

config/docker-monitor-filelog.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lookback": "5m",
1010
"bufferSize": 10,
1111
"source": "docker-monitor",
12+
"skipList": [],
1213
"conditions": [],
1314
"rules": [
1415
{

config/kernel-monitor-filelog.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lookback": "5m",
1010
"bufferSize": 10,
1111
"source": "kernel-monitor",
12+
"skipList": [ " audit:", " audit[" ],
1213
"conditions": [
1314
{
1415
"type": "KernelDeadlock",

pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go

Lines changed: 33 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)