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

chore(cli): add svc status output for Static Site service type #4985

Merged
merged 11 commits into from
Jun 20, 2023

Conversation

huanjani
Copy link
Contributor

Very basic output:

% copilot svc status          
Service: static-site
Bucket Summary

  Bucket Name     bugbash-static-test-static-site-bucket-1qdzh62y4l3gj
  Total Objects   22
  Total Size      3.7 MB

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@huanjani huanjani requested a review from a team as a code owner June 13, 2023 22:23
@huanjani huanjani requested review from dannyrandall and removed request for a team June 13, 2023 22:23
@github-actions
Copy link

github-actions bot commented Jun 13, 2023

🍕 Here are the new binary sizes!

Name New size (kiB) size (kiB) Delta (%)
macOS (amd) 50928 50748 +0.35
macOS (arm) 51128 50956 +0.34
linux (amd) 44836 44680 +0.35
linux (arm) 43076 43012 +0.15
windows (amd) 41688 41548 +0.34

@@ -251,6 +251,40 @@ func (s *S3) GetBucketTree(bucket string) (string, error) {
return tree.String(), nil
}

// GetBucketSizeAndCount returns the total size and number of objects in an S3 bucket.
func (s *S3) GetBucketSizeAndCount(bucket string) (string, int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that this public function is specifically designed for status use case makes me think maybe we could rename this function. Otherwise it'll be too coupled with each other and not generic enough.

Also by looking at GetBucketTree I realized they share many very similar logics with each other (aka listing objects within the bucket). How about we just have

func (*S3) ListObjects(bucket string) (Objects, error)

type Objects []*s3.Object

func (Objects) TotalObjectCount() int

func (Objects) TotalSize() string

func (Objects) Tree() (string, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, yeah. I hadn't reused GetBucketTree because of the delimiter difference, but I could pass that in. Will refactor!

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 kept total count and total size together (for now) to avoid making another API call.
I have ListObjects returning the output because Objects are just one element of the response that we need (we also need prefixes for tree-making).

@codecov-commenter
Copy link

Codecov Report

Merging #4985 (bfc28c4) into mainline (8e41bea) will decrease coverage by 0.01%.
The diff coverage is 67.60%.

@@             Coverage Diff              @@
##           mainline    #4985      +/-   ##
============================================
- Coverage     70.16%   70.15%   -0.01%     
============================================
  Files           289      289              
  Lines         41797    41902     +105     
  Branches        285      285              
============================================
+ Hits          29326    29397      +71     
- Misses        11057    11089      +32     
- Partials       1414     1416       +2     
Impacted Files Coverage Δ
internal/pkg/cli/svc_status.go 24.80% <0.00%> (-2.32%) ⬇️
internal/pkg/describe/service.go 87.01% <ø> (ø)
internal/pkg/describe/static_site.go 61.53% <0.00%> (+0.75%) ⬆️
internal/pkg/describe/status_describe.go 70.37% <53.57%> (-5.33%) ⬇️
internal/pkg/describe/status.go 93.64% <81.25%> (-0.49%) ⬇️
internal/pkg/aws/s3/s3.go 92.33% <94.44%> (+1.01%) ⬆️
internal/pkg/aws/cloudwatch/cloudwatch.go 93.79% <100.00%> (ø)

... and 2 files with indirect coverage changes

Copy link
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

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

just a few small nits and a question!

internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
internal/pkg/aws/s3/s3.go Show resolved Hide resolved
internal/pkg/describe/status_describe.go Outdated Show resolved Hide resolved
internal/pkg/describe/status_describe.go Outdated Show resolved Hide resolved
return fmt.Errorf("create status describer for App Runner service %s in application %s: %w", o.svcName, o.appName, err)
}
o.statusDescriber = d
} else if wkld.Type == manifestinfo.StaticSiteType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe consider using a switch here?

Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

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

looks great!! just a few more nits!

internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
internal/pkg/aws/s3/s3.go Outdated Show resolved Hide resolved
@dannyrandall dannyrandall added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 20, 2023
@huanjani huanjani removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 20, 2023
@mergify mergify bot merged commit d6c5279 into aws:mainline Jun 20, 2023
@huanjani huanjani deleted the status-size-number branch July 17, 2023 21:13
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.

4 participants