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

Add extraction progress output to GetFSFromImage/GetFSFromLayers #11

Merged
merged 3 commits into from
May 24, 2024

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented May 22, 2024

This PR allows printing extraction progress during unpack. Since we can't access the underlying reader for the compressed data, we can only print accurate progress at every layer change. Instead we print ... every 1 second (triggered via read) to indicate that the extraction is still in progress.

Fixes coder/envbuilder#124

#2: Building stage 'mcr.microsoft.com/devcontainers/typescript-node:18-bookworm' [idx: '1', base-idx: '-1']
#2: Unpacking rootfs as cmd ADD install-vscode.sh /root/ requires it.
#2: Extracting image layers to /
#2: Extracting layer 1/22 (0.0%)
#2: Extracting layer 1/22 (0.0%) .
#2: Extracting layer 1/22 (0.0%) ..
#2: Extracting layer 2/22 (7.6%)
#2: Extracting layer 3/22 (11.3%)
#2: Extracting layer 3/22 (11.3%) .
#2: Extracting layer 3/22 (11.3%) ..
#2: Extracting layer 4/22 (21.1%)
#2: Extracting layer 4/22 (21.1%) .
#2: Extracting layer 4/22 (21.1%) ..
#2: Extracting layer 4/22 (21.1%) ...
#2: Extracting layer 4/22 (21.1%) ....
#2: Extracting layer 4/22 (21.1%) .....
#2: Extracting layer 4/22 (21.1%) ......
#2: Extracting layer 5/22 (53.4%)
#2: Extracting layer 6/22 (53.4%)
#2: Extracting layer 6/22 (53.4%) .
#2: Extracting layer 7/22 (60.4%)
#2: Extracting layer 8/22 (60.6%)
#2: Extracting layer 9/22 (60.6%)
#2: Extracting layer 10/22 (61.5%)
#2: Extracting layer 11/22 (61.5%)
#2: Extracting layer 12/22 (61.5%)
#2: Extracting layer 13/22 (61.5%)
#2: Extracting layer 14/22 (61.5%)
#2: Extracting layer 14/22 (61.5%) .
#2: Extracting layer 14/22 (61.5%) ..
#2: Extracting layer 15/22 (72.1%)
#2: Extracting layer 15/22 (72.1%) .
#2: Extracting layer 16/22 (82.0%)
#2: Extracting layer 17/22 (83.6%)
#2: Extracting layer 17/22 (83.6%) .
#2: Extracting layer 18/22 (90.5%)
#2: Extracting layer 19/22 (90.5%)
#2: Extracting layer 20/22 (90.5%)
#2: Extracting layer 21/22 (90.5%)
#2: Extracting layer 22/22 (90.5%)
#2: Extracting layer 22/22 (90.5%) .
#2: Extraction complete
#2: Using files from context: [/workspaces/vscode/.devcontainer/install-vscode.sh]

@mafredri mafredri self-assigned this May 22, 2024
@mafredri
Copy link
Member Author

Whoops, just noticed this:

#2: Extracting image layers to / (0 bytes)
#2: Extraction complete 0/0 (-9223372036854775808%)

I'll push a fix later.

pkg/util/fs_util.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but LGTM otherwise. I don't need to review again 👍

Copy link

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

Left a couple nits & suggestions

Q: did you consider passing a io.TeeReader to the extraction function? That might give you insight into the progress when io.Copy occurs here (I haven't validated this).

pkg/util/fs_util.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
ReadCloser: r,
after: time.Second,
print: func(int64) {
logrus.Infof("Extracting layer %d...", i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside: I think it'd be even more useful to have a timestamp at the start of every log line so we could see how long things took after the fact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider enabling that on the logger lever, but I don't think we should diverge for these log lines. Usually timestamps would be available e.g. via container logs or similar. Not against showing an elapsed human readable time, but then again I want to keep this simple 😄.

pkg/util/fs_util.go Outdated Show resolved Hide resolved
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mafredri
Copy link
Member Author

Q: did you consider passing a io.TeeReader to the extraction function? That might give you insight into the progress when io.Copy occurs here (I haven't validated this).

I'm not following what this would achieve? We're already monitoring reads via the printing reader and writes we can't know anything about.

@dannykopping
Copy link

Q: did you consider passing a io.TeeReader to the extraction function? That might give you insight into the progress when io.Copy occurs here (I haven't validated this).

I'm not following what this would achieve? We're already monitoring reads via the printing reader and writes we can't know anything about.

In func (r *printAfterReader) Read(p []byte) (n int, err error) { you're printing . while the extracting is in progress, but I'm saying you could monitoring the extraction of each layer itself (I think). In any case, this is great as it is - just an idea for later if we have some big layers which take ages to extract and we need more fine-grained insight into that process.

@mafredri
Copy link
Member Author

In func (r *printAfterReader) Read(p []byte) (n int, err error) { you're printing . while the extracting is in progress, but I'm saying you could monitoring the extraction of each layer itself (I think). In any case, this is great as it is - just an idea for later if we have some big layers which take ages to extract and we need more fine-grained insight into that process.

@dannykopping Ah, I see. This is something I wanted to do, but as I mentioned in the PR description, it's not possible. We only know the compressed size and the number of uncompressed bytes read. 😔 Correlating these will always be inaccurate.

@mafredri mafredri merged commit 9d0d559 into main May 24, 2024
9 checks passed
@mafredri mafredri deleted the mafredri/feat-add-extraction-progress branch May 24, 2024 08:22
mafredri added a commit that referenced this pull request May 30, 2024
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.

Add an extracting progress bar
4 participants