libp2p / go-libp2p-pubsub

The PubSub implementation for go-libp2p
https://github.com/libp2p/specs/tree/master/pubsub
Other
319 stars 185 forks source link

Tracing is uneasy with only the public interface #399

Closed MichaelMure closed 3 years ago

MichaelMure commented 3 years ago

I wanted to monitor the messages dropped due to #398 but the tracing API make that difficult. I ended up writing the following (obviously not great) code:

type tracer struct {
    ingressDropped *stats.Int64Measure
    egressDropped  *stats.Int64Measure
}

func (t tracer) Trace(evt *pubsub_pb.TraceEvent) {
    switch evt.GetType() {
    case pubsub_pb.TraceEvent_REJECT_MESSAGE:
        if evt.RejectMessage == nil {
            return
        }
        switch evt.RejectMessage.GetReason() {
        case "validation queue full", "validation throttled":
            stats.Record(context.Background(), t.ingressDropped.M(1))
        }
    case pubsub_pb.TraceEvent_DROP_RPC:
        stats.Record(context.Background(), t.egressDropped.M(1))
    }
}

This code:

The internalTracer interface looks better in my opinion but it's also not publicly accessible.

vyzo commented 3 years ago

So the right solution for this is to simply expose the lower level interface from internalTracer and export the reason strings. This should give you a more powerful hook that avoids the protobuf round trip.

vyzo commented 3 years ago

See #403.