Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Add size analyzer #256

Merged
merged 3 commits into from
Oct 1, 2018
Merged

Conversation

peter-evans
Copy link
Contributor

This feature is a size analyzer for images and layers.
It aims to satisfy the request made in issue #236.

Adds two new types:

  • --type=size
  • --type=sizelayer

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

@peter-evans thanks for the contribution! this is super cool. overall the structure looks good, I left a few comments and one change request.

func (a SizeAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
diff := []util.EntryDiff{
{
Name: "*",
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason you used * here? should this just be the empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason there is an * here is because it indicates "all layers" of the image. I was trying to use templates efficiently and just created two for the four different cases.

The four cases are:

  1. analyze <image> --type=size
  2. analyze <image> --type=sizelayer
  3. diff <image1> <image2> --type=size
  4. diff <image1> <image2> --type=sizelayer

Rather than create four separate templates I found a way to create two, one for analysis and one for diff. Both templates have LAYER as the first column and I reuse them for the image size comparison by displaying an *. Here is an example:

$ out/container-diff analyze gcr.io/gcp-runtimes/diff-layer-base --type=size

-----Size-----

Analysis for gcr.io/gcp-runtimes/diff-layer-base:
LAYER        SIZE
*            19B

When analyzing/diffing the image layers the layer number is shown as in this example:

$ out/container-diff analyze gcr.io/gcp-runtimes/diff-layer-base --type=sizelayer

-----SizeLayer-----

Analysis for gcr.io/gcp-runtimes/diff-layer-base:
LAYER        SIZE
0            6B
1            7B
2            6B

If you would prefer to have the column read IMAGE for the image size comparison cases I can create two further templates. Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see what you did. Being totally honest, I'm not a huge fan of reusing LAYER for the image diff, I think it's a little confusing. If you could create another template for this case that would be great.

-----{{.DiffType}}-----

Size differences between {{.Image1}} and {{.Image2}}:{{if not .Diff}} None{{else}}
LAYER SIZE1 SIZE2{{range .Diff}}{{"\n"}}{{.Name}} {{.Size1}} {{.Size2}}{{end}}
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be IMAGE instead of LAYER?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see this comment: #256 (comment)

{
"Name": "0",
"Size1": 6,
"Size2": 6
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm. any idea why this is showing up when the two sizes are the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I've implemented this is technically not a "diff." In both cases, image and layer size diff, it just shows a comparison between the two even if they match. Now that you've pointed it out I've realised that the diff output probably needs a rethink. It probably should only display layers where the size differs between the two images. If there are no differences and it's an exact match I'm not sure what the expected output should be. Let me know if you have some ideas.

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 for this case, it would be fine to just not display the result at all if the two sizes are identical. Since we're looking for diffs, this is the exact opposite of a diff, so we can just omit it from the results. Then the output will just have a list of the layers that have actual size differences. Does that make sense?

}

diff := util.EntryDiff{
Name: strconv.Itoa(index),
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be cool to use the layer digest here instead of just a number so we can print that to the user. do you think you might be able to add that?

I don't think it would be much more than just adding a Digest field to the image_utils.Layer struct, then calling layer.Digest() here when we're creating the layers. then you could add that into the diff struct and in the template that gets printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I'll have a go at adding this.

@peter-evans
Copy link
Contributor Author

@nkubala Thanks for your review! I'll wait for guidance on a few points that I've outlined in the comments before making further changes.

@nkubala
Copy link
Contributor

nkubala commented Sep 24, 2018

@peter-evans sorry for the delay on this one! I added a few comments, just a few changes need to be made here and this should be good to go 👍

@peter-evans
Copy link
Contributor Author

@nkubala Thanks for the feedback! I've modified the code accordingly.

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

@peter-evans thanks for the contribution!

@nkubala nkubala merged commit 8904693 into GoogleContainerTools:master Oct 1, 2018
@peter-evans peter-evans deleted the size-analyzer branch October 9, 2018 00:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants