-
Notifications
You must be signed in to change notification settings - Fork 54
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
Stop duplicate messages being sent by tedge-log-plugin
and tedge-configuration-plugin
on file reload
#2454
Stop duplicate messages being sent by tedge-log-plugin
and tedge-configuration-plugin
on file reload
#2454
Conversation
224ef70
to
0810bcd
Compare
Codecov Report
Additional details and impacted files
|
Robot Results
|
Are we also sure that this change does not affect replacing existing files using Also, shouldn't we also be doing the same handling for the configuration manager? |
Moving files and creating files both also emit
This is a good candidate for a Rust integration test, which I'll add for this PR.
We probably should. I'll update the configuration manager as well. |
let event = match notify_event.kind { | ||
EventKind::Access(access_kind) => match access_kind { | ||
AccessKind::Close(access_mode) => match access_mode { | ||
AccessMode::Any | AccessMode::Other | AccessMode::Write => { | ||
Some(FsEvent::Modified) | ||
} |
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.
This is the branch that allows us to only listen to FsEvent::Modified
. The actual sequence returned by lower-level notify-debouncer-full
is:
[crates/common/tedge_utils/src/notify.rs:77] ¬ify_event = DebouncedEvent {
event: Event {
kind: Create(
File,
),
paths: [
"/etc/tedge/plugins/tedge-log-plugin.toml",
],
attr:tracker: None,
attr:flag: None,
attr:info: None,
attr:source: None,
},
time: Instant {
tv_sec: 23846,
tv_nsec: 112231843,
},
}
[crates/common/tedge_utils/src/notify.rs:77] ¬ify_event = DebouncedEvent {
event: Event {
kind: Access(
Close(
Write,
),
),
paths: [
"/etc/tedge/plugins/tedge-log-plugin.toml",
],
attr:tracker: None,
attr:flag: None,
attr:info: None,
attr:source: None,
},
time: Instant {
tv_sec: 23846,
tv_nsec: 112263954,
},
}
[crates/common/tedge_utils/src/notify.rs:77] ¬ify_event = DebouncedEvent {
event: Event {
kind: Remove(
File,
),
paths: [
"/etc/tedge/plugins/tedge-log-plugin.toml~",
],
attr:tracker: None,
attr:flag: None,
attr:info: None,
attr:source: None,
},
time: Instant {
tv_sec: 23846,
tv_nsec: 112322524,
},
}
when saving the file with nvim, or:
[crates/common/tedge_utils/src/notify.rs:77] ¬ify_event = DebouncedEvent {
event: Event {
kind: Create(
File,
),
paths: [
"/etc/tedge/plugins/tedge-log-plugin.toml",
],
attr:tracker: None,
attr:flag: None,
attr:info: None,
attr:source: None,
},
time: Instant {
tv_sec: 23953,
tv_nsec: 87955441,
},
}
[crates/common/tedge_utils/src/notify.rs:77] ¬ify_event = DebouncedEvent {
event: Event {
kind: Access(
Close(
Write,
),
),
paths: [
"/etc/tedge/plugins/tedge-log-plugin.toml",
],
attr:tracker: None,
attr:flag: None,
attr:info: None,
attr:source: None,
},
time: Instant {
tv_sec: 23953,
tv_nsec: 87977201,
},
}
when file is copied. Picking up AccessKind::Close(AccessMode::Write)
allows us to reload appropriately.
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.
Approved. The code is clear and correct. Using notify-debouncer-full
was a great idea!
This is working as expected. |
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.
LGTM.
tedge-log-plugin
on file reloadtedge-log-plugin
and tedge-configuration-plugin
on file reload
4568fe4
to
e6c2dca
Compare
e6c2dca
to
7b8a913
Compare
Instead of doing integration tests for both To add relevant tests for both plugins, I'd need to rewrite the plugins themselves a little bit, and we're currently more pressed for other stuff, so that should be sufficient for now. |
7b8a913
to
406031b
Compare
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.
Some queries to better understand the test logic.
406031b
to
7e339d9
Compare
This commit adds debouncing of the `NotifyStream` events via the `notify-debouncer-full` crate. The debouncing window is configured as 50ms, leading to sending of `FsEvent` messages being delayed by that amount and duplicate events within that window being merged, which should reduce the number of duplicate messages. The tests had to be altered to delay deleting files, as if a file was created and deleted within the debounce window, the `FileCreated` and `FileRemoved` events would not fire. Other parts of the system which rely on fs events and also create and delete files quickly, not anticipating the delay, could also exhibit similar problems if we're not careful. FsEvents should not be relied on too much, as they can be unreliable[1]. A new test was added that checks if creating, modifying, deleting, or renaming a file causes `FsEvent::Modified` to be emitted. This event is emitted so that it can be used by consumers which need to respond to changes of the content of the type regardless if it was modified, deleted, moved, etc. Also, `notify` crate itself was upgraded to the latest version. [1]: https://docs.rs/notify/latest/notify/#known-problems
`tedge-log-plugin` and `tedge-configuration-plugin` no longer respond to `FsEvent::FileCreated` and only listen to `FsEvent::Modified` which is guaranteed to be emitted if the content of the file changed, regardless of the kind of the operation which led to this change. As described in the comment, different editors handle editing files differently, but only listening for modifications leads to only 1 reload taking place with following editors i tested: - nano - vim - neovim Listening for file changes could be made more simple by using `notify-debouncer-mini` instead, which doesn't emit precise types of events, but only `Any` events, which only describe that there was a change to the watched file/dir, and then it is up to the application to scan the filesystem and perform necessary steps in reaction to that change. For relevant plugins, that would be perfect, as the only thing we need to know is if the file was changed, and then we always read the file and publish the message. However, to keep our own `FsEvent` layer working, which is also used by other components, this was not done, but can be considered in the future, if we determine file events to be too unreliable.
7e339d9
to
351e8b8
Compare
Proposed changes
This fix consists of 2 parts:
NotifyStream
impl was changed to make use of anotify-debouncer-full
crate to delay and debounce fs events. This should also impact other consumers ofNotifyStream
.tedge-log-plugin
were changed to only listen toModified
events, no longer listening toFileCreated
events.This fix was confirmed to produce only 1 reload when using following editors:
More details regarding both parts can be found in their respective commit messages.
Types of changes
Paste Link to the issue
/etc/tedge/plugins/tedge-log-plugin.toml
results in multiplelog_upload
metadata messages being sent #2451Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments