watcher: notify when watched files are modified#6215
watcher: notify when watched files are modified#6215mattklein123 merged 3 commits intoenvoyproxy:masterfrom
Conversation
The file system watcher previously only reported file movement events, but it's also useful to track changes to watched files (to trigger a reload, for example). This change adds support for tracking file modification events reports them using a new Watcher::Events::Modified. Both inotify (IN_MODIFY) and kqueue (NOTE_WRITE) are supported. This also reduces the set of watched inotify events to just the ones we need: IN_MODIFY | IN_MOVED_TO. Signed-off-by: Jon Parise <jon@pinterest.com>
|
Two further considerations:
|
|
One other note regarding the motivation behind this change: External systems that write watched files should do so using an atomic rename operation to avoid races. We've found a few systems that aren't doing that, and we intend to fix them. Once that's done, Envoy's existing This change has been useful in the meantime, but I would understand if it isn't something that we'd want to maintain in Envoy proper. |
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
/wait |
jmarantz
left a comment
There was a problem hiding this comment.
Many apologies for the delay. Code looks great. A few comments about tests.
| std::ofstream file(TestEnvironment::temporaryPath("envoy_test/watcher_target")); | ||
|
|
||
| WatchCallback callback; | ||
| EXPECT_CALL(callback, called(Watcher::Events::Modified)); |
There was a problem hiding this comment.
Move this EXPECT_CALL to right before where you append to the file?
Also I think you also want to declare testing::InSequence as the first line of this test.
There was a problem hiding this comment.
I followed the pattern used in the other tests in this suite, which all appear to declare their EXPECT_CALLs right after before watcher->addWatch() is called. Given that, would you like me to leave this as-is, change it for just this new test, or revise all of the existing tests?
As for testing::InSequence, I don't think that would make much of a difference here because this test only makes a single assertion/expectation. I'm happy to add it for correctness, though. Would you like me to add that to the existing tests that would benefit from it, too?
There was a problem hiding this comment.
I'm not sure about InSequence but I think if you move the EXPECT_CALL to right before line 109, then the test would fail if the Modified event were called in the first call to dispatcher_->run().
It would be nice to also make similar improvements in precision to the other tests but if that winds up taking you down a rathole I'd be happy with this one.
There was a problem hiding this comment.
Makes sense to me. 👍
Signed-off-by: Jon Parise <jon@pinterest.com>
jparise
left a comment
There was a problem hiding this comment.
Thanks for the review! I added a few questions that will help inform how I address your feedback.
| std::ofstream file(TestEnvironment::temporaryPath("envoy_test/watcher_target")); | ||
|
|
||
| WatchCallback callback; | ||
| EXPECT_CALL(callback, called(Watcher::Events::Modified)); |
There was a problem hiding this comment.
I followed the pattern used in the other tests in this suite, which all appear to declare their EXPECT_CALLs right after before watcher->addWatch() is called. Given that, would you like me to leave this as-is, change it for just this new test, or revise all of the existing tests?
As for testing::InSequence, I don't think that would make much of a difference here because this test only makes a single assertion/expectation. I'm happy to add it for correctness, though. Would you like me to add that to the existing tests that would benefit from it, too?
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
Signed-off-by: Jon Parise <jon@pinterest.com>
* master: (137 commits) test: router upstream log to v2 config stubs (envoyproxy#6499) remove idle timeout validation (envoyproxy#6500) build: Change namespace of chromium_url. (envoyproxy#6506) coverage: exclude chromium_url (envoyproxy#6498) fix(tracing): allow 256 chars in path tag (envoyproxy#6492) Common: Introduce StopAllIteration filter status for decoding and encoding filters (envoyproxy#5954) build: update PGV url (envoyproxy#6495) subset lb: avoid partitioning host lists on worker threads (envoyproxy#6302) ci: Make envoy_select_quiche no-op. (envoyproxy#6393) watcher: notify when watched files are modified (envoyproxy#6215) stat: Add counterFromStatName(), gaugeFromStatName(), and histogramFromStatName() (envoyproxy#6475) bump to 1.11.0-dev (envoyproxy#6490) release: bump to 1.10.0 (envoyproxy#6489) hcm: path normalization. (#1) build: import manually minified Chrome URL lib. (envoyproxy#3) codec: reject embedded NUL in headers. (envoyproxy#2) Added veryfication if path contains query params and add them to path header (envoyproxy#6466) redis: basic integration test for redis_proxy (envoyproxy#6450) stats: report sample count as an integer to prevent loss of precision (envoyproxy#6274) Added VHDS protobuf message and updated RouteConfig to include it. (envoyproxy#6418) ... Signed-off-by: Michael Puncel <mpuncel@squareup.com>
The file system watcher previously only reported file movement events,
but it's also useful to track changes to watched files (to trigger a
reload, for example).
This change adds support for tracking file modification events reports
them using a new Watcher::Events::Modified. Both inotify (IN_MODIFY) and
kqueue (NOTE_WRITE) are supported.
This also reduces the set of watched inotify events to just the ones we
need: IN_MODIFY | IN_MOVED_TO.
Risk Level: Low (nothing is using this new event type yet)
Testing: New unit test (tested on macOS and Linux)
Signed-off-by: Jon Parise jon@pinterest.com