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

up: handle various attach use cases better #10910

Merged
merged 1 commit into from
Aug 18, 2023
Merged

Conversation

milas
Copy link
Contributor

@milas milas commented Aug 17, 2023

What I did
By default, compose up attaches to all services (i.e. shows log output from every associated container). If a service is specified, e.g. compose up foo, then only foo's logs are tailed. The --attach-dependencies flag can also be used, so that if foo depended upon bar, then bar's logs would also be followed. It's also possible to use --no-attach to filter out one or more services explicitly, e.g. compose up --no-attach=noisy would launch all services, including noisy, and would show log output from every service except noisy. Lastly, it's possible to use up --attach to explicitly restrict to a subset of services (or their dependencies).

How these flags interact with each other is also worth thinking through.

There were a few different connected issues here, but the primary issue was that running compose up foo was always attaching dependencies regardless of --attach-dependencies.

The filtering logic here has been updated so that it behaves predictably both when launching all services (compose up) or a subset (compose up foo) as well as various flag combinations on top of those.

Notably, this required making some changes to how it watches containers. The logic here between attaching for logs and monitoring for lifecycle changes is
tightly coupled, so some changes were needed to ensure that the full set of services being up'd are watched and the subset that should have logs shown are attached. (This does mean faking the attach with an event but not actually doing it.)

While handling that, I adjusted the context lifetimes here, which improves error handling that gets shown to the user and should help avoid potential leaks by getting rid of a context.Background().

Related issue
Fixes:

(not mandatory) A picture of a cute animal, if possible in relation to what you did
spider monkey

By default, `compose up` attaches to all services (i.e.
shows log output from every associated container). If
a service is specified, e.g. `compose up foo`, then
only `foo`'s logs are tailed. The `--attach-dependencies`
flag can also be used, so that if `foo` depended upon
`bar`, then `bar`'s logs would also be followed. It's
also possible to use `--no-attach` to filter out one
or more services explicitly, e.g. `compose up --no-attach=noisy`
would launch all services, including `noisy`, and would
show log output from every service _except_ `noisy`.
Lastly, it's possible to use `up --attach` to explicitly
restrict to a subset of services (or their dependencies).

How these flags interact with each other is also worth
thinking through.

There were a few different connected issues here, but
the primary issue was that running `compose up foo` was
always attaching dependencies regardless of `--attach-dependencies`.

The filtering logic here has been updated so that it
behaves predictably both when launching all services
(`compose up`) or a subset (`compose up foo`) as well
as various flag combinations on top of those.

Notably, this required making some changes to how it
watches containers. The logic here between attaching
for logs and monitoring for lifecycle changes is
tightly coupled, so some changes were needed to ensure
that the full set of services being `up`'d are _watched_
and the subset that should have logs shown are _attached_.
(This does mean faking the attach with an event but not
actually doing it.)

While handling that, I adjusted the context lifetimes
here, which improves error handling that gets shown to
the user and should help avoid potential leaks by getting
rid of a `context.Background()`.

Signed-off-by: Milas Bowman <[email protected]>
@milas milas requested review from ndeloof and a team August 17, 2023 22:56
@milas milas self-assigned this Aug 17, 2023
@milas milas requested review from nicksieger, StefanScherer, ulyssessouza, glours and laurazard and removed request for a team August 17, 2023 22:56
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Patch coverage: 68.57% and project coverage change: +0.08% 🎉

Comparison is base (792afb8) 58.71% compared to head (6590b94) 58.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10910      +/-   ##
==========================================
+ Coverage   58.71%   58.80%   +0.08%     
==========================================
  Files         120      120              
  Lines       10477    10540      +63     
==========================================
+ Hits         6152     6198      +46     
- Misses       3722     3738      +16     
- Partials      603      604       +1     
Files Changed Coverage Δ
pkg/compose/start.go 62.34% <48.64%> (-3.09%) ⬇️
cmd/compose/up.go 67.06% <65.00%> (-1.46%) ⬇️
pkg/utils/set.go 68.51% <100.00%> (+33.90%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ndeloof ndeloof merged commit caad727 into docker:main Aug 18, 2023
25 checks passed
@milas milas deleted the fix-attach branch August 18, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants