-
Notifications
You must be signed in to change notification settings - Fork 1k
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
P2P Message Execution Tracing #517
Conversation
shared/p2p/adapter/tracer/tracer.go
Outdated
return nil, errors.New("tracing service name cannot be empty") | ||
} | ||
|
||
// TODO: make sampling fraction configurable? |
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.
Thoughts on this? Currently hard-coded to sampling 25% of requests.
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.
That'd be awesome. Feel free to open an issue and change it to TODO(#Issue number)
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.
Done, made this configurable.
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.
Please format as TODO(#issue number)
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.
Thanks for the PR. Can't wait to try it later!
shared/cmd/flags.go
Outdated
Name: "disable-tracing", | ||
Usage: "Disable request tracing", | ||
} | ||
// TracingEndpointFlag flag defines the http enpoint for serving traces to Jaeger |
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.
period
shared/p2p/adapter/tracer/tracer.go
Outdated
|
||
var log = logrus.WithField("prefix", "tracer") | ||
|
||
// New creates and initializes a new tracing adapter |
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.
period
shared/p2p/adapter/tracer/tracer.go
Outdated
return nil, errors.New("tracing service name cannot be empty") | ||
} | ||
|
||
// TODO: make sampling fraction configurable? |
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.
That'd be awesome. Feel free to open an issue and change it to TODO(#Issue number)
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.
Looking good! I can't wait to try it
shared/p2p/adapter/tracer/tracer.go
Outdated
) | ||
|
||
const ( | ||
defaultSamplingFraction = 0.25 |
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.
Should this be a flag?
shared/p2p/message.go
Outdated
"reflect" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
// Message represents a message received from an external peer. | ||
type Message struct { | ||
// Ctx message context |
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.
You can omit this. It doesn't add any additional information
shared/p2p/service.go
Outdated
@@ -119,7 +119,7 @@ func (s *Server) RegisterTopic(topic string, message proto.Message, adapters ... | |||
} | |||
|
|||
var h Handler = func(ctx context.Context, pMsg Message) { | |||
s.emit(feed, msg, msgType) | |||
s.emit(pMsg.Ctx, feed, msg, msgType) | |||
} | |||
|
|||
pMsg := Message{} |
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.
Let's assign a context here and remove the context parameter from the adapter functions, as you suggested.
shared/p2p/service.go
Outdated
@@ -119,7 +119,7 @@ func (s *Server) RegisterTopic(topic string, message proto.Message, adapters ... | |||
} | |||
|
|||
var h Handler = func(ctx context.Context, pMsg Message) { | |||
s.emit(feed, msg, msgType) | |||
s.emit(pMsg.Ctx, feed, msg, msgType) |
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.
Can you pass the whole message?
var messageSpan *trace.Span | ||
msg.Ctx, messageSpan = trace.StartSpan(msg.Ctx, "handleP2pMessage") | ||
next(msg) | ||
messageSpan.End() |
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.
Will this work properly when the message is handled in a go routine? The typical lifecycle for a message is:
- Receive message
- Apply adapters
- Emit message to feed subscribers that are running in other go routines
- End routine for handling message <- I think your span will end here, no?
- Message received via feed to subscriber 1
- Message received via feed to subscriber 2
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 span only traces the handling of a message in the p2p layer and will end after the emit step as you mentioned. However, since the message context is passed to subscribers 1 and 2, any spans created there will be children of this root and linked to the message trace.
I expect the subscribing routines to define these child spans. (See receiveBlockHash in beacon chain sync service for an example)
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.
Ah, I see. That makes sense.
One last request, can you add an example of how to instrument code in your readme?
It would be helpful to point someone to a canonical example in documentation.
After that, I think this is good to go!
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.
Updated doc
Codecov Report
@@ Coverage Diff @@
## master #517 +/- ##
==========================================
+ Coverage 76.18% 76.62% +0.43%
==========================================
Files 41 42 +1
Lines 2818 2879 +61
==========================================
+ Hits 2147 2206 +59
- Misses 472 473 +1
- Partials 199 200 +1
Continue to review full report at Codecov.
|
@d1vyank please resolve conflicts then we can merge. Thanks! |
* Request execution tracing initial commit * Resolve linter issues * Run gazelle * Make trace sampling configurable, clean up, update doc * Document trace span creation * Fix linter issue
--enable-tracing
,trace-sample-fraction
, and--tracing-endpoint
CLI options addedtowards #438