Send peerID peer score as separate events to enable usage of kibana runtime fields

This commit is contained in:
Matija Petrunic 2021-09-21 12:30:50 +02:00
parent 082f70757c
commit d65d9aa6e0

View File

@ -28,10 +28,10 @@ const (
) )
type LotusTraceEvent struct { type LotusTraceEvent struct {
Type pubsub_pb.TraceEvent_Type `json:"type,omitempty"` Type pubsub_pb.TraceEvent_Type `json:"type,omitempty"`
PeerID string `json:"peerID,omitempty"` PeerID string `json:"peerID,omitempty"`
Timestamp *int64 `json:"timestamp,omitempty"` Timestamp *int64 `json:"timestamp,omitempty"`
PeerScores []TraceEvent_PeerScore `json:"peerScores,omitempty"` PeerScore TraceEvent_PeerScore `json:"peerScore,omitempty"`
} }
type TraceEvent_PeerScore struct { type TraceEvent_PeerScore struct {
@ -47,20 +47,17 @@ type LotusTracer interface {
} }
func (lt *lotusTracer) PeerScores(scores map[peer.ID]*pubsub.PeerScoreSnapshot) { func (lt *lotusTracer) PeerScores(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {
var peerScores []TraceEvent_PeerScore
for pid, score := range scores {
peerScores = append(peerScores, TraceEvent_PeerScore{PeerID: pid.Pretty(), Score: float32(score.Score)})
}
now := time.Now().UnixNano() now := time.Now().UnixNano()
evt := &LotusTraceEvent{ for pid, score := range scores {
Type: *TraceEvent_PEER_SCORES.Enum(), evt := &LotusTraceEvent{
PeerID: string(lt.pid), Type: *TraceEvent_PEER_SCORES.Enum(),
Timestamp: &now, PeerID: lt.pid.Pretty(),
PeerScores: peerScores, Timestamp: &now,
} PeerScore: TraceEvent_PeerScore{PeerID: pid.Pretty(), Score: float32(score.Score)},
}
lt.TraceLotusEvent(evt) lt.TraceLotusEvent(evt)
}
} }
func (lt *lotusTracer) TraceLotusEvent(evt *LotusTraceEvent) { func (lt *lotusTracer) TraceLotusEvent(evt *LotusTraceEvent) {