Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions config/disk-log-message-filelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"plugin": "filelog",
"pluginConfig": {
"timestamp": "^.{15}",
"message": "(?i)Currently unreadable.*sectors|(?i)Offline uncorrectable sectors",
"timestampFormat": "Jan _2 15:04:05"
},
"logPath": "/var/log/messages",
"lookback": "10h",
"bufferSize": 1,
"source": "disk-monitor",
"skipList": [ " audit:", " audit[" ],
"conditions": [
{
"type": "DiskBadBlock",
"reason": "DiskBadBlock",
"message": "Disk no bad block"
},
],
"rules": [
{
"type": "permanent",
"condition": "DiskBadBlock",
"reason": "DiskBadBlock",
"pattern": ".*([1-9]\\d{2,}) (Currently unreadable.*sectors|Offline uncorrectable sectors).*"
},
]
}
12 changes: 12 additions & 0 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func (s *filelogWatcher) watchLoop() {
}
line = buffer.String()
buffer.Reset()
if s.filterSkipList(line) {
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
log, err := s.translator.translate(strings.TrimSuffix(line, "\n"))
if err != nil {
klog.Warningf("Unable to parse line: %q, %v", line, err)
Expand All @@ -129,3 +132,12 @@ func (s *filelogWatcher) watchLoop() {
s.logCh <- log
}
}

func (s *filelogWatcher) filterSkipList(line string) bool {
for _ , skipItem := range s.cfg.SkipList {
if strings.Contains(line, skipItem) {
return true
}
}
return false
}
33 changes: 33 additions & 0 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,36 @@ Jan 2 03:04:05 kernel: [2.000000] 3
}
}
}

func TestFilterSkipList(t *testing.T) {
s := &filelogWatcher{
cfg: types.WatcherConfig{
SkipList: []string{
" audit:", " kubelet:",
},
},
}
testcase := []struct{
log string
expect bool
}{
{
log: `Jan 2 03:04:03 kernel: [0.000000] 1`,
expect: false,
},
{
log: `Jan 2 03:04:04 audit: [1.000000] 2`,
expect: true,
},
{
log: `Jan 2 03:04:05 kubelet: [2.000000] 3`,
expect: true,

},
}
for i, test := range testcase {
if s.filterSkipList(test.log) != test.expect {
t.Errorf("test case %d: expect %v but got %v", i, test.expect, s.filterSkipList(test.log))
}
}
}
2 changes: 2 additions & 0 deletions pkg/systemlogmonitor/logwatchers/types/log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type WatcherConfig struct {
// PluginConfig is a key/value configuration of a plugin. Valid configurations
// are defined in different log watcher plugin.
PluginConfig map[string]string `json:"pluginConfig,omitempty"`
// Skip the log lines containing any of the strings in the list to avoid running unnecessary regex.
SkipList []string `json:"skipList,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a sample config file in https://github.com/kubernetes/node-problem-detector/tree/master/config to illustrate how to use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// LogPath is the path to the log
LogPath string `json:"logPath,omitempty"`
// Lookback is the time log watcher looks up
Expand Down