Repository navigation
fix(fluent-watcher): reload fluent-bit after the config volume is switched - #2140
Open
CharlieR-o-o-t wants to merge 1 commit into
Open
CharlieR-o-o-t wants to merge 1 commit into
CharlieR-o-o-t wants to merge 1 commit into
Conversation
…tched
The watcher sent SIGHUP on the first file event in the watch path. One
update of a mounted Secret is a burst of events: the kubelet creates a
new timestamped directory, writes the files and only then switches the
"..data" symlink. The first event comes from the new directory, so
fluent-bit started the hot reload before the switch and read the
previous config. The events of the switch itself arrived while that
reload was running and were dropped ("reloading in progress,
aborting"), so the pod stayed one config version behind until the next
change, while reporting a successful reload.
Wait until the watch path has been unchanged for -reload-delay
(default 1s) and send one SIGHUP per update.
Signed-off-by: Siarei Rasiukevich <s.rasiukevich@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it
After a config change, fluent-bit pods often keep running the previous config while logging a successful reload. They stay one version behind until the config changes again. With namespaced
FluentBitConfigthis means a newly created route is missing on part of the nodes and the logs of that namespace are not delivered from them.Cause.
fluent-bit-watchersendsSIGHUPon the firstCreate/Writeevent in/fluent-bit/config. A single update of the mounted Secret is a burst of events, because the kubelet updates the volume atomically:..<timestamp>directory - first event..data_tmpand rename it to..data- more eventsThe first event arrives before
..datapoints to the new directory. fluent-bit starts the hot reload right away and reads the old content. The events of step 3 come a fraction of a millisecond later and are dropped, because a reload is already running:Nothing triggers another reload afterwards. When the old main config is read together with files that are already switched (a Lua script of a removed filter, for example), the same race shows up as
[filter_lua] filter cannot be loaded/reloaded config is invalid. Reloading is halted.Seen on a 120-node cluster with fluent-operator v3.10.0 and the
fluent-bit:5.1.0image: after one route was re-created, about 70% of the pods that reloaded were running the config from before the change.Fix. The watcher now waits until the watch path has been unchanged for
-reload-delay(default1s) and then sends oneSIGHUPper update. This also removes thereloading in progress, abortingerrors that every config change produced.Which issue(s) this PR fixes
Fixes #2141
Testing
New tests in
cmd/fluent-watcher/fluentbit/main_test.goupdate a directory the way the kubelet does and check which content is visible through..dataat the moment of the reload. Without the delay all three fail withreloaded config "v1", want "v2".Not covered: a change that lands while fluent-bit is still reloading (the reload takes up to the grace period) is still dropped by fluent-bit itself. That needs feedback from fluent-bit, for example the hot-reload counter of the HTTP API, and is left for a follow-up.
Does this PR introduce a user-facing change?