-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Tilt watcher #10218
Tilt watcher #10218
Conversation
Codecov ReportBase: 72.79% // Head: 73.89% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## v2 #10218 +/- ##
==========================================
+ Coverage 72.79% 73.89% +1.10%
==========================================
Files 2 2
Lines 272 272
==========================================
+ Hits 198 201 +3
+ Misses 62 60 -2
+ Partials 12 11 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
83523c1
to
68ab928
Compare
@@ -33,6 +33,8 @@ require ( | |||
github.com/spf13/pflag v1.0.5 | |||
github.com/stretchr/testify v1.8.1 | |||
github.com/theupdateframework/notary v0.7.0 | |||
github.com/tilt-dev/fsevents v0.0.0-20200515134857-2efe37af20de | |||
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 |
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.
Do we know what patches are in this fork, and if they were rejected upstream? I know fsnotify
has had some time where maintenance was slow, but I think it improved in that respect (and I think we have some maintainers on it that are also maintainers for moby/moby)
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.
https://github.com/tilt-dev/fsnotify#notable-changes
That's not quite accurate anymore, since, as you noted, fsnotify/fsnotify
has had more activity recently.
In fact, I believe all the important changes have been upstreamed:
- Ignore file attribute change events on Windows:
fsnotify#520
- Configurable Windows buffer size:
fsnotify#521
- Recursive Windows watcher support:
fsnotify#540
However, they're all on main
still - no release of fsnotify/fsnotify
contains them yet. Also, not a huge deal, but there's some API differences in the upstreamed implementations, most notably in the format for Windows recursive paths.
All that said, I feel good about using upstream and pinning to a Git hash for now; that'll certainly make any future improvements more straightforward.
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.
Ah, thanks! Yes, saw the comment later on, and saw that (github indicated "10" commits in the fork);
fsnotify/fsnotify@main...tilt-dev:fsnotify:main
Pinning to a commit from upstream SGTM (short term). I'm mostly trying to avoid having 2 forks of the same dependency (as I know we have fsnotify as dependency in our tree already).
If someone has some cycles to spare to look what patches are not (yet) in upstream, we could contribute them there.
@cpuguy83 were you a maintainer on that repo? Or do I misremember that? (Otherwise I think there's some familiar people on it, that we may try to reach out to to ask for a (pre-)release).
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.
I think I have commit access in order to get some important changes in, but I wouldn't call myself a "maintainer".
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.
watcher_naive relies on SetRecursive
which doesn't exist in upstream
cc237ff
to
809d6b1
Compare
731b70d
to
e0d877c
Compare
…ker#3743) In most places in Tilt, we try to use absolute paths everywhere. So this makes things more consistent with the rest of Tilt, and lets us be a bit more flexible in how we handle subdirs and parent dirs in ignores. Fixes tilt-dev/tilt#3740
Unused code linter isn't particularly smart about platform build tags, so since this func is only used by the "naive" (non-macOS) file watcher, it needs to live with that or it gets flagged as dead code when linting on macOS.
`WalkDir` is new in Go 1.16 and avoids calling `os.Lstat` on every visited file and directory. In most cases, we don't need that info, so this will help reduce I/O when listing files, which can be helpful for particularly big monorepos.
* lint: add make lintfix and run it Fixes all errors like: ``` File is not `goimports`-ed with -local github.com/tilt-dev/tilt (goimports) ``` * git: change to use TrimSuffix * build: remove unnecessary cast
I've been running the test suite (`./internal/engine` in particular) with `-count X` a lot recently to catch timing-related test failures. After running enough times, the tests start failing due to too many open files, so I did an audit and found a few places where files or readers weren't always being closed.
…cker#5281) `exportloopref` - detects captures of loop variable without re-assignment NOTE: There can be false negatives with this linter to avoid being overly strict and annoying! Also upgraded `golangci-lint` to latest (v1.43.0 published 2021-11-03).
Fix local-prefixes on linters imports then resolved imports to be as expected Signed-off-by: Ken Sipe <kensipe@gmail.com>
Signed-off-by: Nick Santos <nick.santos@docker.com> Signed-off-by: Nick Santos <nick.santos@docker.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
47015e9
to
fea472e
Compare
pkg/compose/watch.go
Outdated
fmt.Fprintf(s.stderr(), "change detected on %s\n", event.Path()) | ||
|
||
for src, dest := range config.Sync { | ||
if strings.HasPrefix(event.Path(), src) { |
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.
For portability, I'd look at using filepath.Rel
to determine this:
- It'll call
Clean()
on both paths so separators match (e.g. if you're on Windows but defined your ignores/a/b/c
) - It has some (probably imperfect but better than nothing?) case-insensitivity logic for Windows
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.
Or perhaps IsChild
from pkg/watch/paths.go
which is used to filter out watches on descendants of recursively watched paths
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.
ya +1 for using IsChild for this kind of comparison.
the things to watch out for are:
- case insensitive file systems (e.g., /path/to/myrepo vs /path/to/MyRepo)
- symlinks, like the /tmp -> /private/tmp symlink
so we tried to avoid string-based functions for doing this kind of check, because the path string we used as input doesn't always use the same casing as the path string that the OS attaches to the event.
Lizz and I spent some time trying to pull out a "canonical" version of paths for string comparison
https://github.com/tilt-dev/tilt/pull/5309/files
but got distracted
pkg/compose/watch.go
Outdated
Source: event.Path(), | ||
Destination: fmt.Sprintf("%s:%s/%s", service.Name, dest, event.Path()[len(src):]), |
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.
Ugh, definitely not in-scope for this PR, but we should change api.CopyOptions
to use full fields for this and do the parsing in the CLI, right now we're doing that all in the backend @
Lines 274 to 289 in f24d345
func splitCpArg(arg string) (container, path string) { | |
if system.IsAbs(arg) { | |
// Explicit local absolute path, e.g., `C:\foo` or `/foo`. | |
return "", arg | |
} | |
parts := strings.SplitN(arg, ":", 2) | |
if len(parts) == 1 || strings.HasPrefix(parts[0], ".") { | |
// Either there's no `:` in the arg | |
// OR it's an explicit local relative path like `./file:name.txt`. | |
return "", arg | |
} | |
return parts[0], parts[1] | |
} |
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 indeed is something I had in mind for a while ...
func readDockerignorePatterns(repoRoot string) ([]string, error) { | ||
var excludes []string | ||
|
||
f, err := os.Open(filepath.Join(repoRoot, ".dockerignore")) |
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.
Aren't the .dockerignore
loading rules more complex than this? (For example, if you have foo.dockerfile
, won't it auto-use foo.dockerignore
?) 😬
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.
I don't think so. But I might be wrong. I expect users to reming me with new issues if this is the case :)
pkg/watch/notify.go
Outdated
func IsWindowsShortReadError(err error) bool { | ||
return runtime.GOOS == "windows" && err != nil && strings.Contains(err.Error(), "short read") | ||
} |
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.
FYI for once we switch off the Tilt fork...this has been superseded by ErrEventOverflow
in HEAD @ fsnotify/fsnotify
pkg/watch/notify.go
Outdated
return newWatcher(paths, ignore) | ||
} | ||
|
||
const WindowsBufferSizeEnvVar = "TILT_WATCH_WINDOWS_BUFFER_SIZE" |
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 sorta ties into below re: short reads, but Tilt would detect these errors and then provide a message back to the user letting them know they should try and raise this limit.
In practice, I'm not sure how often it actually got hit (maybe @nicks knows), so it might be safe to drop configurability entirely here
Otherwise...s/TILT/COMPOSE/
😛
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.
people stopped filing issues about it once we put instructions on how to embiggen the buffer in the error message!! 😅
554ba97
to
18930bb
Compare
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
What I did
imported watcher code from tilt to support new
compose watch
command(not mandatory) A picture of a cute animal, if possible in relation to what you did
