feat: add deduplication ratio to 'ipfs dag stat'#9787
Conversation
|
@Jorropo this is just a draft, I'm still working on it, I'll add the tests and improve some things before starting with the bonus points. Can you take a look at this, just to see if I'm in the right direction? I don't know if that's what you wanted for the json and text encoders. |
|
@Jorropo can you review this draft? I'm kind of blocked on this feature, I just need to know if I'm on the right direction and if this satisfies the issue basic requirements so I can continue working on it and make the improvements you mentioned. |
|
Just wanted to say thanks @arthurgavazza for your contribution. The maintainers have been busy with https://2023.ipfs-thing.io/ but will be back into more normal flow next week. |
|
@BigLep thanks for letting me know! |
Jorropo
left a comment
There was a problem hiding this comment.
Thx a lot <3 this is good.
I have a few comments.
core/commands/dag/dag.go
Outdated
| if s.TotalSize > 0 { | ||
| s.Ratio = float32(s.redundantSize) / float32(s.TotalSize) | ||
| } |
There was a problem hiding this comment.
I would remove the if check and let s.Ratio being NaN and implement custom marshal which omits Ratio if it is NaN. But that fine, probably.
|
@Jorropo thx for the feedback! I'll work on this ASAP |
Co-authored-by: Jorropo <[email protected]>
Co-authored-by: Jorropo <[email protected]>
Co-authored-by: Jorropo <[email protected]>
Co-authored-by: Jorropo <[email protected]>
Co-authored-by: Jorropo <[email protected]>
|
For ci fix please run: find -type f -name "go.mod" | while read f; do cd $(dirname "${f}"); go mod tidy; cd -; done
go fmt ./... |
|
@arthurgavazza: are you to fix CI? It would be great to include in the next release. |
|
I think some fixes after the review havn't been pushed yet to. 🙂 |
|
@arthurgavazza you don't have any deadline, feel free to work on this when you have time. It will get in the release cycle whenever that happens. |
test/cli/dag_test.go
Outdated
| assert.Nil(t, err) | ||
| stat := node.RunIPFS("dag", "stat", "--progress=false", node1Cid, node2Cid) | ||
| str := stat.Stdout.String() | ||
| expected := "\nCID \tBlocks \tSize\nbafyreibmdfd7c5db4kls4ty57zljfhqv36gi43l6txl44pi423wwmeskwy\t2 \t53\nbafyreie3njilzdi4ixumru4nzgecsnjtu7fzfcwhg7e6s4s5i7cnbslvn4\t2 \t53\n\nSummary\nTotal Size: 145\nUnique Blocks: 3\nShared Size: 53\nRatio: 1.365517\n\n\n" |
There was a problem hiding this comment.
Please use the ` syntax, this is very hard to me.
There was a problem hiding this comment.
sorry for that, I'm gonna make this more readable
There was a problem hiding this comment.
@Jorropo I'm having a hard time comparing the text output with a string literal in this test, I added a test using the json encoded output so that I can validate the deduplication behaviour. Is there any other way that I could test the text output?
There was a problem hiding this comment.
@arthurgavazza json is good.
For the text one: the point of golden tests is that the code of the test is very dumb.
You create a dataset ahead of time that show all the behaviour you want (here it would be a .car fixture) and then you == or diff the output with some hardcoded values you create at the same time you make your fixture.
Co-authored-by: Jorropo <[email protected]>
|
@Jorropo sorry for taking too long to make the changes, I was very busy this last few weeks. I added a new test, comparing the text output with a fixture containing the expected results. Can you please take a look at the latest changes? |
hacdias
left a comment
There was a problem hiding this comment.
Very happy that you also moved the old relevant tests from .sh to .go 😃
Co-authored-by: Henrique Dias <[email protected]>
|
Thx ❤️🎉 |
|
@Jorropo thx for all the support! ❤️ I'm really glad I could help. About the improvements you mentioned on the issue. Can I open a new issue with them and start working on it? |
|
@arthurgavazza which improvements ? |
|
@Jorropo
|
|
@arthurgavazza I don't care that much about thoses, 1, 3 and 4 are just performance related (and what you have now is ok). 2 and 5 are very minor quality of life. Feel free to do it if that is fun for you, but if you want to make something that would change Kubo's usability I think there will be better use of your time than over optimizing an underused endpoint. 🙂 |
This adds deduplication information on a list of Cids for the
ipfs dag statcommand,as requested in #9762. ex:running
ipfs dag stat QmcQs9AFNh4mHKqFLJ2Zo7WPSottWi9YDdEoqdk3jv5RyE QmSg4hRo947Lkp9qKn3KJhjjCFGNmtw8VLoXhUCC9mLRgU QmSg4hRo947Lkp9qKn3KJhjjCFGNmtw8VLoXhUCC9mLRgUwrites the following output to stdout:and with the
--enc=jsonoption:Fixes #9762