swarm: integrate OpenTracing; propagate ctx to internal APIs (#17169)
* swarm: propagate ctx, enable opentracing * swarm/tracing: log error when tracing is misconfigured
This commit is contained in:
committed by
Balint Gabor
parent
f7d3678c28
commit
7c9314f231
@@ -19,6 +19,7 @@
|
||||
package pss
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
@@ -40,7 +41,7 @@ type Ping struct {
|
||||
InC chan bool // optional, report back to calling code
|
||||
}
|
||||
|
||||
func (p *Ping) pingHandler(msg interface{}) error {
|
||||
func (p *Ping) pingHandler(ctx context.Context, msg interface{}) error {
|
||||
var pingmsg *PingMsg
|
||||
var ok bool
|
||||
if pingmsg, ok = msg.(*PingMsg); !ok {
|
||||
@@ -80,7 +81,7 @@ func NewPingProtocol(ping *Ping) *p2p.Protocol {
|
||||
for {
|
||||
select {
|
||||
case ispong := <-ping.OutC:
|
||||
pp.Send(&PingMsg{
|
||||
pp.Send(context.TODO(), &PingMsg{
|
||||
Created: time.Now(),
|
||||
Pong: ispong,
|
||||
})
|
||||
|
@@ -18,6 +18,7 @@ package pss
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
@@ -71,7 +72,7 @@ type senderPeer interface {
|
||||
Info() *p2p.PeerInfo
|
||||
ID() discover.NodeID
|
||||
Address() []byte
|
||||
Send(interface{}) error
|
||||
Send(context.Context, interface{}) error
|
||||
}
|
||||
|
||||
// per-key peer related information
|
||||
@@ -344,7 +345,7 @@ func (p *Pss) getHandlers(topic Topic) map[*Handler]bool {
|
||||
// Check if address partially matches
|
||||
// If yes, it CAN be for us, and we process it
|
||||
// Only passes error to pss protocol handler if payload is not valid pssmsg
|
||||
func (p *Pss) handlePssMsg(msg interface{}) error {
|
||||
func (p *Pss) handlePssMsg(ctx context.Context, msg interface{}) error {
|
||||
metrics.GetOrRegisterCounter("pss.handlepssmsg", nil).Inc(1)
|
||||
|
||||
pssmsg, ok := msg.(*PssMsg)
|
||||
@@ -844,7 +845,7 @@ func (p *Pss) forward(msg *PssMsg) error {
|
||||
p.fwdPoolMu.RUnlock()
|
||||
|
||||
// attempt to send the message
|
||||
err := pp.Send(msg)
|
||||
err := pp.Send(context.TODO(), msg)
|
||||
if err != nil {
|
||||
metrics.GetOrRegisterCounter("pss.pp.send.error", nil).Inc(1)
|
||||
log.Error(err.Error())
|
||||
|
@@ -334,7 +334,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
Data: []byte{0x66, 0x6f, 0x6f},
|
||||
},
|
||||
}
|
||||
if err := ps.handlePssMsg(msg); err != nil {
|
||||
if err := ps.handlePssMsg(context.TODO(), msg); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
tmr := time.NewTimer(time.Millisecond * 100)
|
||||
@@ -351,7 +351,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
// message should pass and queue due to partial length
|
||||
msg.To = addr[0:1]
|
||||
msg.Payload.Data = []byte{0x78, 0x79, 0x80, 0x80, 0x79}
|
||||
if err := ps.handlePssMsg(msg); err != nil {
|
||||
if err := ps.handlePssMsg(context.TODO(), msg); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
tmr.Reset(time.Millisecond * 100)
|
||||
@@ -374,7 +374,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
|
||||
// full address mismatch should put message in queue
|
||||
msg.To[0] = 0xff
|
||||
if err := ps.handlePssMsg(msg); err != nil {
|
||||
if err := ps.handlePssMsg(context.TODO(), msg); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
tmr.Reset(time.Millisecond * 10)
|
||||
@@ -397,7 +397,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
|
||||
// expired message should be dropped
|
||||
msg.Expire = uint32(time.Now().Add(-time.Second).Unix())
|
||||
if err := ps.handlePssMsg(msg); err != nil {
|
||||
if err := ps.handlePssMsg(context.TODO(), msg); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
tmr.Reset(time.Millisecond * 10)
|
||||
@@ -417,7 +417,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
}{
|
||||
pssMsg: &PssMsg{},
|
||||
}
|
||||
if err := ps.handlePssMsg(fckedupmsg); err == nil {
|
||||
if err := ps.handlePssMsg(context.TODO(), fckedupmsg); err == nil {
|
||||
t.Fatalf("expected error from processMsg but error nil")
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ func TestHandlerConditions(t *testing.T) {
|
||||
ps.outbox <- msg
|
||||
}
|
||||
msg.Payload.Data = []byte{0x62, 0x61, 0x72}
|
||||
err = ps.handlePssMsg(msg)
|
||||
err = ps.handlePssMsg(context.TODO(), msg)
|
||||
if err == nil {
|
||||
t.Fatal("expected error when mailbox full, but was nil")
|
||||
}
|
||||
|
Reference in New Issue
Block a user