-
Notifications
You must be signed in to change notification settings - Fork 649
feat(kernelLogWatcher): enable revive kmsg parser if channel closed #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,19 @@ import ( | |
"k8s.io/node-problem-detector/pkg/util/tomb" | ||
) | ||
|
||
const ( | ||
reviveRetries = 10 | ||
reviveDuration = 5 * time.Second | ||
) | ||
|
||
type kernelLogWatcher struct { | ||
cfg types.WatcherConfig | ||
startTime time.Time | ||
logCh chan *logtypes.Log | ||
tomb *tomb.Tomb | ||
|
||
kmsgParser kmsgparser.Parser | ||
kmsgParser kmsgparser.Parser | ||
reviveCount int | ||
} | ||
|
||
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg | ||
|
@@ -55,22 +61,17 @@ func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher { | |
startTime: startTime, | ||
tomb: tomb.NewTomb(), | ||
// Arbitrary capacity | ||
logCh: make(chan *logtypes.Log, 100), | ||
logCh: make(chan *logtypes.Log, 100), | ||
reviveCount: 0, | ||
} | ||
} | ||
|
||
var _ types.WatcherCreateFunc = NewKmsgWatcher | ||
|
||
func (k *kernelLogWatcher) Watch() (<-chan *logtypes.Log, error) { | ||
if k.kmsgParser == nil { | ||
// nil-check to make mocking easier | ||
parser, err := kmsgparser.NewParser() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create kmsg parser: %v", err) | ||
} | ||
k.kmsgParser = parser | ||
if err := k.SetKmsgParser(); err != nil { | ||
return nil, err | ||
} | ||
|
||
go k.watchLoop() | ||
return k.logCh, nil | ||
} | ||
|
@@ -99,6 +100,9 @@ func (k *kernelLogWatcher) watchLoop() { | |
return | ||
case msg, ok := <-kmsgs: | ||
if !ok { | ||
if val, ok := k.cfg.PluginConfig["revive"]; ok && val == "true" { | ||
k.reviveMyself() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before revive, add a log line about we are starting to revive. |
||
} | ||
klog.Error("Kmsg channel closed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log line should be before the revive. |
||
return | ||
} | ||
|
@@ -120,3 +124,35 @@ func (k *kernelLogWatcher) watchLoop() { | |
} | ||
} | ||
} | ||
|
||
// create a new kmsg parser and sets it to the watcher. | ||
func (k *kernelLogWatcher) SetKmsgParser() error { | ||
parser, err := kmsgparser.NewParser() | ||
if err != nil { | ||
return fmt.Errorf("failed to create kmsg parser: %v", err) | ||
} | ||
k.kmsgParser = parser | ||
return nil | ||
} | ||
|
||
// revive ourselves if the kmsg channel is closed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious about the error you observe when the channel is closed. Do you see the "Kmsg channel closed" log? Is it always associated with high load of the node? |
||
// close the old kmsg parser and create a new one | ||
// enter the watch loop again | ||
func (k *kernelLogWatcher) reviveMyself() { | ||
// if k.reviveCount >= reviveRetries { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncomment? |
||
// klog.Errorf("Failed to revive kmsg parser after %d retries", reviveRetries) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the retries, is there any time boundary needed? For example, if the revive happens 10 times over a year, it may be fine. But if revive happens 10 times over a minute, something is wrong. |
||
// return | ||
// } | ||
// klog.Infof("Reviving kmsg parser, attempt %d of %d", k.reviveCount, reviveRetries) | ||
klog.Infof("Reviving kmsg parser, attempt %d", k.reviveCount) | ||
if err := k.kmsgParser.Close(); err != nil { | ||
klog.Errorf("Failed to close kmsg parser: %v", err) | ||
} | ||
time.Sleep(reviveDuration) | ||
if err := k.SetKmsgParser(); err != nil { | ||
klog.Errorf("Failed to revive kmsg parser: %v", err) | ||
return | ||
} | ||
k.reviveCount++ | ||
k.watchLoop() | ||
} |
There was a problem hiding this comment.
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 for using revive?