Add in some more notifications to help profile queries
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Nov 4, 2015 at 21:49 UTC
80c73f26b851853acfd8f75780852bf5992cf4bc
2 files changed
+18
-2
notifications/query.go
+2
@@ -18,6 +18,8 @@ const (
18
QueryError
19
Provider
20
Value
21
+ AddingPeer
22
+ DialingPeer
23
)
24
25
type QueryEvent struct {
routing/dht/query.go
+16
-2
@@ -79,6 +79,8 @@ type dhtQueryRunner struct {
79
rateLimit chan struct{} // processing semaphore
80
log logging.EventLogger
81
82
+ runCtx context.Context
83
+
84
proc process.Process
85
sync.RWMutex
86
}
@@ -98,6 +100,7 @@ func newQueryRunner(q *dhtQuery) *dhtQueryRunner {
100
101
func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryResult, error) {
102
r.log = log
103
+ r.runCtx = ctx
104
105
if len(peers) == 0 {
106
log.Warning("Running query with no peers!")
@@ -167,6 +170,11 @@ func (r *dhtQueryRunner) addPeerToQuery(next peer.ID) {
170
return
171
}
172
173
+ notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{
174
+ Type: notif.AddingPeer,
175
+ ID: next,
176
+ })
177
+
178
r.peersRemaining.Increment(1)
179
select {
180
case r.peersToQuery.EnqChan <- next:
@@ -221,7 +229,12 @@ func (r *dhtQueryRunner) queryPeer(proc process.Process, p peer.ID) {
229
// make sure we're connected to the peer.
230
// FIXME abstract away into the network layer
231
if conns := r.query.dht.host.Network().ConnsToPeer(p); len(conns) == 0 {
224
- log.Infof("not connected. dialing.")
232
+ log.Error("not connected. dialing.")
233
+
234
+ notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{
235
+ Type: notif.DialingPeer,
236
+ ID: p,
237
+ })
238
// while we dial, we do not take up a rate limit. this is to allow
239
// forward progress during potentially very high latency dials.
240
r.rateLimit <- struct{}{}
@@ -231,9 +244,10 @@ func (r *dhtQueryRunner) queryPeer(proc process.Process, p peer.ID) {
244
if err := r.query.dht.host.Connect(ctx, pi); err != nil {
245
log.Debugf("Error connecting: %s", err)
246
234
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
247
+ notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{
248
Type: notif.QueryError,
249
Extra: err.Error(),
250
+ ID: p,
251
})
252
253
r.Lock()