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

feat(cli): add more info to "snapshot create" json #3294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schra
Copy link
Contributor

@schra schra commented Sep 12, 2023

I'd like to expose how many bytes were uploaded to the json of kopia snapshot create --json. I tested my diff and it works as expected.

I think this diff is rather hacky. I am motivated to improve this diff, if you let me know what you would like me to change. I wasn't sure how to cleanly implement this and I am also new to Go.

@@ -286,6 +286,19 @@ func (c *commandSnapshotCreate) snapshotSingleSource(ctx context.Context, fsEntr
manifest.Tags = tags
manifest.UpdatePins(c.pins, nil)

progress := c.svc.getProgress()

manifest.Progress = map[string]int64{
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've listed all integer fields of cliProgress here, except inProgressHashing because it is "in progress" and thus not interesting to expose to the json

@@ -336,7 +349,7 @@ func (c *commandSnapshotCreate) snapshotSingleSource(ctx context.Context, fsEntr
}
}

c.svc.getProgress().Finish()
progress.Finish()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not totally sure if I should first Finish() before I access the values in progress. to me it seems like that the Finish function only changes what is displayed in the cli but doesn't affect the integer values, thus I think it doesn't matter when Finish is called

Description string `json:"description"`
StartTime fs.UTCTimestamp `json:"startTime"`
EndTime fs.UTCTimestamp `json:"endTime"`
Progress map[string]int64 `json:"progress"`
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 wasn't sure how exactly to expose progress here. Would it be better to introduce a new struct? Can I somehow directly use the cliProgress struct? Is using a map acceptable here?

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't Stats below have what you need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stats doesn't contain an uploadedBytes field. The only byte fields it has are TotalFileSize and ExcludedTotalFileSize. What would be the best option to continue? For example, I could try to add the new fields UploadedTotalFileSize and CachedTotalFileSize to Stats. Or I could keep the map that I introduced. Or I could create a new Stats struct that is only used to report the data in the json file. Thoughts :)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do Stats. I would prefer to be intentional and only add 1 or 2 field as needed, I know some folks manage millions of manifests and bloat can already be a problem.

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (164dcce) 75.74% compared to head (17b6a80) 75.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3294      +/-   ##
==========================================
+ Coverage   75.74%   75.75%   +0.01%     
==========================================
  Files         461      461              
  Lines       36960    36973      +13     
==========================================
+ Hits        27994    28010      +16     
- Misses       7036     7037       +1     
+ Partials     1930     1926       -4     
Files Changed Coverage Δ
snapshot/manifest.go 88.37% <ø> (ø)
cli/command_snapshot_create.go 80.22% <100.00%> (+0.75%) ⬆️

... and 5 files with indirect coverage changes

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

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.

None yet

2 participants