-
Notifications
You must be signed in to change notification settings - Fork 175
/
gossipsub.go
179 lines (152 loc) · 6.72 KB
/
gossipsub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/module"
)
type GossipSubMetrics struct {
receivedIHaveCount prometheus.Counter
receivedIWantCount prometheus.Counter
receivedGraftCount prometheus.Counter
receivedPruneCount prometheus.Counter
incomingRpcAcceptedFullyCount prometheus.Counter
incomingRpcAcceptedOnlyControlCount prometheus.Counter
incomingRpcRejectedCount prometheus.Counter
receivedPublishMessageCount prometheus.Counter
prefix string
}
var _ module.GossipSubRouterMetrics = (*GossipSubMetrics)(nil)
func NewGossipSubMetrics(prefix string) *GossipSubMetrics {
gs := &GossipSubMetrics{prefix: prefix}
gs.receivedIHaveCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_received_ihave_total",
Help: "number of received ihave messages from gossipsub protocol",
},
)
gs.receivedIWantCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_received_iwant_total",
Help: "number of received iwant messages from gossipsub protocol",
},
)
gs.receivedGraftCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_received_graft_total",
Help: "number of received graft messages from gossipsub protocol",
},
)
gs.receivedPruneCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_received_prune_total",
Help: "number of received prune messages from gossipsub protocol",
},
)
gs.incomingRpcAcceptedFullyCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_incoming_rpc_accepted_fully_total",
Help: "number of incoming rpc messages accepted fully by gossipsub protocol",
},
)
gs.incomingRpcAcceptedOnlyControlCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_incoming_rpc_accepted_only_control_total",
Help: "number of incoming rpc messages accepted only control messages by gossipsub protocol",
},
)
gs.incomingRpcRejectedCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_incoming_rpc_rejected_total",
Help: "number of incoming rpc messages rejected by gossipsub protocol",
},
)
gs.receivedPublishMessageCount = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: gs.prefix + "gossipsub_received_publish_message_total",
Help: "number of received publish messages from gossipsub protocol",
},
)
return gs
}
// OnIWantReceived tracks the number of IWANT messages received by the node from other nodes.
// iWant is a control message that is sent by a node to request a message that it has seen advertised in an iHAVE message.
func (nc *GossipSubMetrics) OnIWantReceived(count int) {
nc.receivedIWantCount.Add(float64(count))
}
// OnIHaveReceived tracks the number of IHAVE messages received by the node from other nodes.
// iHave is a control message that is sent by a node to another node to indicate that it has a new gossiped message.
func (nc *GossipSubMetrics) OnIHaveReceived(count int) {
nc.receivedIHaveCount.Add(float64(count))
}
// OnGraftReceived tracks the number of GRAFT messages received by the node from other nodes.
// GRAFT is a control message of GossipSub protocol that connects two nodes over a topic directly as gossip partners.
func (nc *GossipSubMetrics) OnGraftReceived(count int) {
nc.receivedGraftCount.Add(float64(count))
}
// OnPruneReceived tracks the number of PRUNE messages received by the node from other nodes.
// PRUNE is a control message of GossipSub protocol that disconnects two nodes over a topic.
func (nc *GossipSubMetrics) OnPruneReceived(count int) {
nc.receivedPruneCount.Add(float64(count))
}
// OnIncomingRpcAcceptedFully tracks the number of RPC messages received by the node that are fully accepted.
// An RPC may contain any number of control messages, i.e., IHAVE, IWANT, GRAFT, PRUNE, as well as the actual messages.
// A fully accepted RPC means that all the control messages are accepted and all the messages are accepted.
func (nc *GossipSubMetrics) OnIncomingRpcAcceptedFully() {
nc.incomingRpcAcceptedFullyCount.Inc()
}
// OnIncomingRpcAcceptedOnlyForControlMessages tracks the number of RPC messages received by the node that are accepted
// only for the control messages, i.e., only for the included IHAVE, IWANT, GRAFT, PRUNE. However, the actual messages
// included in the RPC are not accepted.
// This happens mostly when the validation pipeline of GossipSub is throttled, and cannot accept more actual messages for
// validation.
func (nc *GossipSubMetrics) OnIncomingRpcAcceptedOnlyForControlMessages() {
nc.incomingRpcAcceptedOnlyControlCount.Inc()
}
// OnIncomingRpcRejected tracks the number of RPC messages received by the node that are rejected.
// This happens mostly when the RPC is coming from a low-scored peer based on the peer scoring module of GossipSub.
func (nc *GossipSubMetrics) OnIncomingRpcRejected() {
nc.incomingRpcRejectedCount.Inc()
}
// OnPublishedGossipMessagesReceived tracks the number of gossip messages received by the node from other nodes over an
// RPC message.
func (nc *GossipSubMetrics) OnPublishedGossipMessagesReceived(count int) {
nc.receivedPublishMessageCount.Add(float64(count))
}
// GossipSubLocalMeshMetrics is a metrics collector for the local mesh of GossipSub protocol.
type GossipSubLocalMeshMetrics struct {
localMeshSize prometheus.GaugeVec
}
func NewGossipSubLocalMeshMetrics(prefix string) *GossipSubLocalMeshMetrics {
return &GossipSubLocalMeshMetrics{
localMeshSize: *promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Name: prefix + "gossipsub_local_mesh_size",
Help: "number of peers in the local mesh of the node",
},
[]string{LabelChannel},
),
}
}
var _ module.GossipSubLocalMeshMetrics = (*GossipSubLocalMeshMetrics)(nil)
// OnLocalMeshSizeUpdated updates the local mesh size metric.
func (g *GossipSubLocalMeshMetrics) OnLocalMeshSizeUpdated(topic string, size int) {
g.localMeshSize.WithLabelValues(topic).Set(float64(size))
}