Skip to content

Commit 3d1ac8b

Browse files
committed
add future time filter for log watchers when time across the year
1 parent d4163ca commit 3d1ac8b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (s *filelogWatcher) watchLoop() {
131131
klog.V(5).Infof("Throwing away msg %q before start time: %v < %v", log.Message, log.Timestamp, s.startTime)
132132
continue
133133
}
134+
135+
// Discard messages after now, lots of log files are not record year. 1 min cover log write latency
136+
if log.Timestamp.After(time.Now().Add(time.Minute)) {
137+
klog.V(5).Infof("Throwing away msg %q after current time: %v < %v", log.Message, log.Timestamp, time.Now())
138+
continue
139+
}
140+
134141
s.logCh <- log
135142
}
136143
}

pkg/systemlogmonitor/logwatchers/journald/log_watcher.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ func (j *journaldWatcher) watchLoop() {
130130
continue
131131
}
132132

133+
// Discard messages after now, the journal log is not record year. 1 min cover log write latency
134+
if entry.RealtimeTimestamp > timeToJournalTimestamp(time.Now().Add(time.Minute)) {
135+
klog.V(5).Infof("Throwing away msg %q after current time: %v < %v", entry.Fields[sdjournal.SD_JOURNAL_FIELD_MESSAGE], entry.RealtimeTimestamp, time.Now())
136+
continue
137+
}
138+
133139
j.logCh <- translate(entry)
134140
}
135141
}

pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func (k *kernelLogWatcher) watchLoop() {
115115
continue
116116
}
117117

118+
// Discard messages after now, lots of log files are not record year. 1 min cover log write latency
119+
if msg.Timestamp.After(time.Now().Add(time.Minute)) {
120+
klog.V(5).Infof("Throwing away msg %q after current time: %v < %v", msg.Message, msg.Timestamp, time.Now())
121+
continue
122+
}
123+
118124
k.logCh <- &logtypes.Log{
119125
Message: strings.TrimSpace(msg.Message),
120126
Timestamp: msg.Timestamp,

0 commit comments

Comments
 (0)