Skip to content
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

Merged
merged 56 commits into from
Feb 2, 2023
Merged

Tilt watcher #10218

merged 56 commits into from
Feb 2, 2023

Conversation

ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Jan 30, 2023

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
image

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 72.79% // Head: 73.89% // Increases project coverage by +1.10% 🎉

Coverage data is based on head (a9e8351) compared to base (f24d345).
Patch has no changes to coverable lines.

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     
Impacted Files Coverage Δ
pkg/e2e/framework.go 72.15% <0.00%> (+1.17%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ndeloof ndeloof force-pushed the tilt-watcher branch 11 times, most recently from 83523c1 to 68ab928 Compare January 30, 2023 15:52
@@ -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
Copy link
Member

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)

Copy link
Contributor

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.

Copy link
Member

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).

Copy link
Contributor

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".

Copy link
Contributor Author

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

@ndeloof ndeloof force-pushed the tilt-watcher branch 3 times, most recently from cc237ff to 809d6b1 Compare January 31, 2023 09:59
@ndeloof ndeloof marked this pull request as ready for review January 31, 2023 10:23
@ndeloof ndeloof force-pushed the tilt-watcher branch 2 times, most recently from 731b70d to e0d877c Compare January 31, 2023 12:35
@ndeloof ndeloof requested review from a team, nicksieger, StefanScherer, ulyssessouza, glours, milas and laurazard and removed request for a team January 31, 2023 13:07

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
nicks and others added 19 commits February 1, 2023 09:19

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
`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.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* 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>
@ndeloof ndeloof force-pushed the tilt-watcher branch 2 times, most recently from 47015e9 to fea472e Compare February 1, 2023 09:14
fmt.Fprintf(s.stderr(), "change detected on %s\n", event.Path())

for src, dest := range config.Sync {
if strings.HasPrefix(event.Path(), src) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

@nicks nicks Feb 1, 2023

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

Comment on lines 94 to 95
Source: event.Path(),
Destination: fmt.Sprintf("%s:%s/%s", service.Name, dest, event.Path()[len(src):]),
Copy link
Contributor

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 @

compose/pkg/compose/cp.go

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]
}

Copy link
Contributor Author

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"))
Copy link
Contributor

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?) 😬

Copy link
Contributor Author

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 :)

Comment on lines 104 to 108
func IsWindowsShortReadError(err error) bool {
return runtime.GOOS == "windows" && err != nil && strings.Contains(err.Error(), "short read")
}
Copy link
Contributor

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

return newWatcher(paths, ignore)
}

const WindowsBufferSizeEnvVar = "TILT_WATCH_WINDOWS_BUFFER_SIZE"
Copy link
Contributor

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/ 😛

Copy link
Contributor

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!! 😅

@ndeloof ndeloof force-pushed the tilt-watcher branch 3 times, most recently from 554ba97 to 18930bb Compare February 2, 2023 10:37
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof ndeloof merged commit 1640f15 into docker:v2 Feb 2, 2023
@ndeloof ndeloof deleted the tilt-watcher branch February 2, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants