From d5a4b0637abf50b418756d02c796c15230febc0c Mon Sep 17 00:00:00 2001 From: Matija Petrunic Date: Fri, 10 Sep 2021 15:37:38 +0200 Subject: [PATCH] Add lotus tracer transport calls --- node/modules/tracer/tracer.go | 31 +++++++++++++++++++++++++++++-- node/modules/tracer/transport.go | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/node/modules/tracer/tracer.go b/node/modules/tracer/tracer.go index a19ae065d..6d60352e7 100644 --- a/node/modules/tracer/tracer.go +++ b/node/modules/tracer/tracer.go @@ -1,11 +1,16 @@ package tracer import ( + "encoding/json" + + logging "github.com/ipfs/go-log/v2" peer "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" ) +var log = logging.Logger("lotus-tracer") + func newLotusTracer(et pubsub.EventTracer, tt TracerTransport) LotusTracer { return &lotusTracer{ et: et, @@ -23,6 +28,28 @@ type LotusTracer interface { 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) + } +} diff --git a/node/modules/tracer/transport.go b/node/modules/tracer/transport.go index 73ef80690..c8495821e 100644 --- a/node/modules/tracer/transport.go +++ b/node/modules/tracer/transport.go @@ -1,5 +1,5 @@ package tracer type TracerTransport interface { - Transport(jsonEvent []byte) + Transport(jsonEvent []byte) error }