Add lotus tracer transport calls
This commit is contained in:
parent
c367533a3c
commit
d5a4b0637a
@ -1,11 +1,16 @@
|
|||||||
package tracer
|
package tracer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
logging "github.com/ipfs/go-log/v2"
|
||||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("lotus-tracer")
|
||||||
|
|
||||||
func newLotusTracer(et pubsub.EventTracer, tt TracerTransport) LotusTracer {
|
func newLotusTracer(et pubsub.EventTracer, tt TracerTransport) LotusTracer {
|
||||||
return &lotusTracer{
|
return &lotusTracer{
|
||||||
et: et,
|
et: et,
|
||||||
@ -23,6 +28,28 @@ type LotusTracer interface {
|
|||||||
Trace(evt *pubsub_pb.TraceEvent)
|
Trace(evt *pubsub_pb.TraceEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lt *lotusTracer) TracePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {}
|
func (lt *lotusTracer) TracePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {
|
||||||
|
jsonEvent, err := json.Marshal(scores)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error while marshaling peer score: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (lt *lotusTracer) Trace(evt *pubsub_pb.TraceEvent) {}
|
err = lt.tt.Transport(jsonEvent)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error while transporting peer scores: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lt *lotusTracer) Trace(evt *pubsub_pb.TraceEvent) {
|
||||||
|
jsonEvent, err := json.Marshal(evt)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error while marshaling tracer event: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = lt.tt.Transport(jsonEvent)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error while transporting trace event: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package tracer
|
package tracer
|
||||||
|
|
||||||
type TracerTransport interface {
|
type TracerTransport interface {
|
||||||
Transport(jsonEvent []byte)
|
Transport(jsonEvent []byte) error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user