mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 09:59:56 +00:00
Add --revert-pattern for logcounter
This commit is contained in:
@@ -34,6 +34,7 @@ type LogCounterOptions struct {
|
||||
Lookback string
|
||||
Delay string
|
||||
Pattern string
|
||||
RevertPattern string
|
||||
Count int
|
||||
}
|
||||
|
||||
@@ -46,6 +47,8 @@ func (fedo *LogCounterOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
"The time duration log watcher delays after node boot time. This is useful when log watcher needs to wait for some time until the node is stable.")
|
||||
fs.StringVar(&fedo.Pattern, "pattern", "",
|
||||
"The regular expression to match the problem in log. The pattern must match to the end of the line.")
|
||||
fs.StringVar(&fedo.RevertPattern, "revert-pattern", "",
|
||||
"Similar to --pattern but conversely it decreases count value for every match. This is useful to discount a log when another log occurs.")
|
||||
fs.IntVar(&fedo.Count, "count", 1,
|
||||
"The number of times the pattern must be found to trigger the condition")
|
||||
}
|
||||
|
||||
@@ -40,10 +40,11 @@ const (
|
||||
)
|
||||
|
||||
type logCounter struct {
|
||||
logCh <-chan *systemtypes.Log
|
||||
buffer systemlogmonitor.LogBuffer
|
||||
pattern string
|
||||
clock clock.Clock
|
||||
logCh <-chan *systemtypes.Log
|
||||
buffer systemlogmonitor.LogBuffer
|
||||
pattern string
|
||||
revertPattern string
|
||||
clock clock.Clock
|
||||
}
|
||||
|
||||
func NewJournaldLogCounter(options *options.LogCounterOptions) (types.LogCounter, error) {
|
||||
@@ -59,10 +60,11 @@ func NewJournaldLogCounter(options *options.LogCounterOptions) (types.LogCounter
|
||||
return nil, fmt.Errorf("error watching journald: %v", err)
|
||||
}
|
||||
return &logCounter{
|
||||
logCh: logCh,
|
||||
buffer: systemlogmonitor.NewLogBuffer(bufferSize),
|
||||
pattern: options.Pattern,
|
||||
clock: clock.RealClock{},
|
||||
logCh: logCh,
|
||||
buffer: systemlogmonitor.NewLogBuffer(bufferSize),
|
||||
pattern: options.Pattern,
|
||||
revertPattern: options.RevertPattern,
|
||||
clock: clock.RealClock{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -84,6 +86,9 @@ func (e *logCounter) Count() (count int, err error) {
|
||||
if len(e.buffer.Match(e.pattern)) != 0 {
|
||||
count++
|
||||
}
|
||||
if len(e.buffer.Match(e.revertPattern)) != 0 {
|
||||
count--
|
||||
}
|
||||
case <-e.clock.After(timeout):
|
||||
// Don't block forever if we do not get any new messages
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user