-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 Event Logging to Add Command #4465
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
My only worry would be performance but I'm pretty sure this won't be the bottleneck. However, would you mind running a small local before and after benchmark? E.g., add the go-ipfs
git repo to an empty repo before and after (and then maybe try adding a large file).
We really need benchmarks... |
@Stebalien
After Changes (d84e5a2):
|
Cool, doesnt appear to be any noticeable difference there. |
Could you post an image here of the tracing output that this generates? |
Sorry it got cut off a bit, this on is from the above benchmarks. This is one from my Also, its not shown in the screenshots, but you can view the tags (like filename) if you click the spans |
core/coreunix/add.go
Outdated
@@ -153,112 +153,148 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) { | |||
} | |||
|
|||
func (adder *Adder) RootNode() (node.Node, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense as well? It feels cleaner, it compiles and the tests pass.
diff --git a/core/coreunix/add.go b/core/coreunix/add.go
index 516b76d44..090ecee27 100644
--- a/core/coreunix/add.go
+++ b/core/coreunix/add.go
@@ -152,40 +152,42 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) {
return balanced.BalancedLayout(params.New(chnk))
}
-func (adder *Adder) RootNode() (node.Node, error) {
+func (adder *Adder) RootNode() (root node.Node, err error) {
eip := log.EventBegin(adder.ctx, "RootNode")
- defer eip.Done()
+ defer func() {
+ if root != nil {
+ eip.Append(root.Cid())
+ }
+ if err != nil {
+ eip.SetError(err)
+ }
+ eip.Done()
+ }()
// for memoizing
- if adder.root != nil {
- eip.Append(adder.root.Cid())
- return adder.root, nil
+ root = adder.root
+ if root != nil {
+ return root, nil
}
mr, err := adder.mfsRoot()
if err != nil {
- eip.SetError(err)
return nil, err
}
- root, err := mr.GetValue().GetNode()
+ root, err = mr.GetValue().GetNode()
if err != nil {
- eip.SetError(err)
return nil, err
}
// if not wrapping, AND one root file, use that hash as root.
if !adder.Wrap && len(root.Links()) == 1 {
- nd, err := root.Links()[0].GetNode(adder.ctx, adder.dagService)
+ root, err = root.Links()[0].GetNode(adder.ctx, adder.dagService)
if err != nil {
- eip.SetError(err)
return nil, err
}
-
- root = nd
}
adder.root = root
- eip.Append(root.Cid())
- return root, err
+ return
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with naming the return values for the purpose of accessing them from within the defer
statement. However, I wouldn't use the implicit return feature (IMO, it was a mistake). How about:
diff --git a/core/coreunix/add.go b/core/coreunix/add.go
index 516b76d44..090ecee27 100644
--- a/core/coreunix/add.go
+++ b/core/coreunix/add.go
@@ -152,37 +152,38 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) {
return balanced.BalancedLayout(params.New(chnk))
}
-func (adder *Adder) RootNode() (node.Node, error) {
+func (adder *Adder) RootNode() (root node.Node, err error) {
eip := log.EventBegin(adder.ctx, "RootNode")
- defer eip.Done()
+ defer func() {
+ if root != nil {
+ eip.Append(root.Cid())
+ }
+ if err != nil {
+ eip.SetError(err)
+ }
+ eip.Done()
+ }()
// for memoizing
- if adder.root != nil {
- eip.Append(adder.root.Cid())
- return adder.root, nil
+ if addr.root != nil {
+ return addr.root, nil
}
mr, err := adder.mfsRoot()
if err != nil {
- eip.SetError(err)
return nil, err
}
- root, err := mr.GetValue().GetNode()
+ root, err = mr.GetValue().GetNode()
if err != nil {
- eip.SetError(err)
return nil, err
}
// if not wrapping, AND one root file, use that hash as root.
if !adder.Wrap && len(root.Links()) == 1 {
- nd, err := root.Links()[0].GetNode(adder.ctx, adder.dagService)
+ root, err = root.Links()[0].GetNode(adder.ctx, adder.dagService)
if err != nil {
- eip.SetError(err)
return nil, err
}
-
- root = nd
}
adder.root = root
- eip.Append(root.Cid())
return root, err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, the implicit return thing was a terrible choice by the go team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I can make these changes on the rest of the methods here too then. I am not sure if I should make that a separate commit or rebase. What would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either way, i'm not picky. Though I do appreciate smaller numbers of commits
2483a55
to
2822474
Compare
return getBlocks(ctx, ks, s.blockstore, s.exchange) | ||
} | ||
|
||
func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block { | ||
out := make(chan blocks.Block) | ||
go func() { | ||
defer logging.MaybeFinishEvent(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs to go first for this functionality.
7ffb1d3
to
5ff4e7a
Compare
1f8003a
to
aef5ab7
Compare
bd44804
to
28aa9e2
Compare
9949fba
to
3134df7
Compare
Note: blocked until changes in go-log are bubbled up - CI will fail till then |
5cdbf8d
to
0215e8f
Compare
Now that everything else has been unblocked, what exact changes do you still need (if any)? |
@Stebalien we will need to gx publish the changes in go-log and update the version that go-ipfs uses (currently using 1.2.0). The changes in go-log include instrumenting it with opentracing, as well as adding the DoneWithErr method and MaybeFinishEvent method (basically all the changes made to go-log in prs 8 - 16). I can start that process now. CI fails because the aforementioned methods are missing from go-log and this branch uses them. Changes Needed: |
0215e8f
to
ddc37ae
Compare
License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
ddc37ae
to
0426dd1
Compare
Named return params and defer func to complete event License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
Contextual logging for async methods License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
0426dd1
to
00d0582
Compare
Closing, will reopen when this becomes a priority -- I currently lack the bandwidth to push this forward. |
License: MIT
Signed-off-by: ForrestWeston forrest@protocol.ai