github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/gossipsub_rpc_validation_inspector.go (about) 1 package metrics 2 3 import ( 4 "time" 5 6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus/promauto" 8 9 "github.com/onflow/flow-go/module" 10 p2pmsg "github.com/onflow/flow-go/network/p2p/message" 11 ) 12 13 const ( 14 labelIHaveMessageIds = "ihave_message_ids" 15 labelIWantMessageIds = "iwant_message_ids" 16 ) 17 18 // GossipSubRpcValidationInspectorMetrics metrics collector for the gossipsub RPC validation inspector. 19 type GossipSubRpcValidationInspectorMetrics struct { 20 prefix string 21 rpcCtrlMsgInAsyncPreProcessingGauge prometheus.Gauge 22 rpcCtrlMsgAsyncProcessingTimeHistogram prometheus.Histogram 23 rpcCtrlMsgTruncation prometheus.HistogramVec 24 ctrlMsgInvalidTopicIdCount prometheus.CounterVec 25 receivedIWantMsgCount prometheus.Counter 26 receivedIWantMsgIDsHistogram prometheus.Histogram 27 receivedIHaveMsgCount prometheus.Counter 28 receivedIHaveMsgIDsHistogram prometheus.HistogramVec 29 receivedPruneCount prometheus.Counter 30 receivedGraftCount prometheus.Counter 31 receivedPublishMessageCount prometheus.Counter 32 incomingRpcCount prometheus.Counter 33 34 // graft inspection 35 graftDuplicateTopicIdsHistogram prometheus.Histogram 36 graftInvalidTopicIdsHistogram prometheus.Histogram 37 graftDuplicateTopicIdsExceedThresholdCount prometheus.Counter 38 graftInvalidTopicIdsExceedThresholdCount prometheus.Counter 39 40 // prune inspection 41 pruneDuplicateTopicIdsHistogram prometheus.Histogram 42 pruneInvalidTopicIdsHistogram prometheus.Histogram 43 pruneDuplicateTopicIdsExceedThresholdCount prometheus.Counter 44 pruneInvalidTopicIdsExceedThresholdCount prometheus.Counter 45 46 // iHave inspection 47 iHaveDuplicateMessageIdHistogram prometheus.Histogram 48 iHaveDuplicateTopicIdHistogram prometheus.Histogram 49 iHaveInvalidTopicIdHistogram prometheus.Histogram 50 iHaveDuplicateMessageIdExceedThresholdCount prometheus.Counter 51 iHaveDuplicateTopicIdExceedThresholdCount prometheus.Counter 52 iHaveInvalidTopicIdExceedThresholdCount prometheus.Counter 53 54 // iWant inspection 55 iWantDuplicateMessageIdHistogram prometheus.Histogram 56 iWantCacheMissHistogram prometheus.Histogram 57 iWantDuplicateMessageIdExceedThresholdCount prometheus.Counter 58 iWantCacheMissMessageIdExceedThresholdCount prometheus.Counter 59 60 // inspection result 61 errActiveClusterIdsNotSetCount prometheus.Counter 62 errUnstakedPeerInspectionFailedCount prometheus.Counter 63 invalidControlMessageNotificationSentCount prometheus.Counter 64 unstakedNodeRPCRejectedCount prometheus.Counter 65 66 // publish messages 67 publishMessageInspectionErrExceedThresholdCount prometheus.Counter 68 publishMessageInvalidSenderCountHistogram prometheus.Histogram 69 publishMessageInvalidSubscriptionsHistogram prometheus.Histogram 70 publishMessageInvalidTopicIdHistogram prometheus.Histogram 71 publishMessageInspectedErrHistogram prometheus.Histogram 72 } 73 74 var _ module.GossipSubRpcValidationInspectorMetrics = (*GossipSubRpcValidationInspectorMetrics)(nil) 75 76 // NewGossipSubRPCValidationInspectorMetrics returns a new *GossipSubRpcValidationInspectorMetrics. 77 func NewGossipSubRPCValidationInspectorMetrics(prefix string) *GossipSubRpcValidationInspectorMetrics { 78 gc := &GossipSubRpcValidationInspectorMetrics{prefix: prefix} 79 gc.rpcCtrlMsgInAsyncPreProcessingGauge = promauto.NewGauge( 80 prometheus.GaugeOpts{ 81 Namespace: namespaceNetwork, 82 Subsystem: subsystemGossip, 83 Name: gc.prefix + "control_messages_in_async_processing_total", 84 Help: "the number of rpc control messages currently being processed asynchronously by workers from the rpc validator worker pool", 85 }, 86 ) 87 gc.rpcCtrlMsgAsyncProcessingTimeHistogram = promauto.NewHistogram( 88 prometheus.HistogramOpts{ 89 Namespace: namespaceNetwork, 90 Subsystem: subsystemGossip, 91 Name: gc.prefix + "rpc_control_message_validator_async_processing_time_seconds", 92 Help: "duration [seconds; measured with float64 precision] of how long it takes rpc control message validator to asynchronously process a rpc message", 93 Buckets: []float64{.1, 1}, 94 }, 95 ) 96 97 gc.rpcCtrlMsgTruncation = *promauto.NewHistogramVec(prometheus.HistogramOpts{ 98 Namespace: namespaceNetwork, 99 Subsystem: subsystemGossip, 100 Name: gc.prefix + "rpc_control_message_truncation", 101 Help: "the number of times a control message was truncated", 102 Buckets: []float64{10, 100, 1000}, 103 }, []string{LabelMessage}) 104 105 gc.receivedIHaveMsgCount = promauto.NewCounter(prometheus.CounterOpts{ 106 Namespace: namespaceNetwork, 107 Subsystem: subsystemGossip, 108 Name: gc.prefix + "gossipsub_received_ihave_total", 109 Help: "number of received ihave messages from gossipsub protocol", 110 }) 111 112 gc.receivedIHaveMsgIDsHistogram = *promauto.NewHistogramVec(prometheus.HistogramOpts{ 113 Namespace: namespaceNetwork, 114 Subsystem: subsystemGossip, 115 Name: gc.prefix + "gossipsub_received_ihave_message_ids", 116 Help: "histogram of received ihave message ids from gossipsub protocol per channel", 117 }, []string{LabelChannel}) 118 119 gc.receivedIWantMsgCount = promauto.NewCounter(prometheus.CounterOpts{ 120 Namespace: namespaceNetwork, 121 Subsystem: subsystemGossip, 122 Name: gc.prefix + "gossipsub_received_iwant_total", 123 Help: "total number of received iwant messages from gossipsub protocol", 124 }) 125 126 gc.receivedIWantMsgIDsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 127 Namespace: namespaceNetwork, 128 Subsystem: subsystemGossip, 129 Name: gc.prefix + "gossipsub_received_iwant_message_ids", 130 Help: "histogram of received iwant message ids from gossipsub protocol per channel", 131 }) 132 133 gc.receivedGraftCount = promauto.NewCounter(prometheus.CounterOpts{ 134 Namespace: namespaceNetwork, 135 Subsystem: subsystemGossip, 136 Name: gc.prefix + "gossipsub_received_graft_total", 137 Help: "total number of received graft messages from gossipsub protocol", 138 }) 139 140 gc.receivedPruneCount = promauto.NewCounter(prometheus.CounterOpts{ 141 Namespace: namespaceNetwork, 142 Subsystem: subsystemGossip, 143 Name: gc.prefix + "gossipsub_received_prune_total", 144 Help: "total number of received prune messages from gossipsub protocol", 145 }) 146 147 gc.receivedPublishMessageCount = promauto.NewCounter(prometheus.CounterOpts{ 148 Namespace: namespaceNetwork, 149 Subsystem: subsystemGossip, 150 Name: gc.prefix + "gossipsub_received_publish_message_total", 151 Help: "total number of received publish messages from gossipsub protocol", 152 }) 153 154 gc.incomingRpcCount = promauto.NewCounter(prometheus.CounterOpts{ 155 Namespace: namespaceNetwork, 156 Subsystem: subsystemGossip, 157 Name: gc.prefix + "gossipsub_incoming_rpc_total", 158 Help: "total number of incoming rpc messages from gossipsub protocol", 159 }) 160 161 gc.iHaveDuplicateMessageIdHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 162 Namespace: namespaceNetwork, 163 Subsystem: subsystemGossip, 164 Buckets: []float64{1, 100, 1000}, 165 Name: gc.prefix + "rpc_inspection_ihave_duplicate_message_ids_count", 166 Help: "number of duplicate message ids received from gossipsub protocol during the async inspection of a single RPC", 167 }) 168 169 gc.iHaveDuplicateTopicIdHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 170 Namespace: namespaceNetwork, 171 Subsystem: subsystemGossip, 172 Buckets: []float64{1, 100, 1000}, 173 Name: gc.prefix + "rpc_inspection_ihave_duplicate_topic_ids_count", 174 Help: "number of duplicate topic ids received from gossipsub protocol during the async inspection of a single RPC", 175 }) 176 177 gc.iHaveInvalidTopicIdHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 178 Namespace: namespaceNetwork, 179 Subsystem: subsystemGossip, 180 Buckets: []float64{1, 100, 1000}, 181 Name: gc.prefix + "rpc_inspection_ihave_invalid_topic_ids_count", 182 Help: "number of invalid topic ids received from gossipsub protocol during the async inspection of a single RPC", 183 }) 184 185 gc.iHaveDuplicateMessageIdExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 186 Namespace: namespaceNetwork, 187 Subsystem: subsystemGossip, 188 Name: gc.prefix + "rpc_inspection_ihave_duplicate_message_ids_exceed_threshold_total", 189 Help: "total number of times that the async inspection of iHave messages failed due to the number of duplicate message ids exceeding the threshold", 190 }) 191 192 gc.iHaveDuplicateTopicIdExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 193 Namespace: namespaceNetwork, 194 Subsystem: subsystemGossip, 195 Name: gc.prefix + "rpc_inspection_ihave_duplicate_topic_ids_exceed_threshold_total", 196 Help: "total number of times that the async inspection of iHave messages failed due to the number of duplicate topic ids exceeding the threshold", 197 }) 198 199 gc.iHaveInvalidTopicIdExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 200 Namespace: namespaceNetwork, 201 Subsystem: subsystemGossip, 202 Name: gc.prefix + "rpc_inspection_ihave_invalid_topic_ids_exceed_threshold_total", 203 Help: "total number of times that the async inspection of iHave messages failed due to the number of invalid topic ids exceeding the threshold", 204 }) 205 206 gc.iWantDuplicateMessageIdHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 207 Namespace: namespaceNetwork, 208 Subsystem: subsystemGossip, 209 Name: gc.prefix + "rpc_inspection_iwant_duplicate_message_ids_count", 210 Buckets: []float64{1, 100, 1000}, 211 Help: "number of duplicate message ids received from gossipsub protocol during the async inspection of a single RPC", 212 }) 213 214 gc.iWantCacheMissHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 215 Namespace: namespaceNetwork, 216 Subsystem: subsystemGossip, 217 Name: gc.prefix + "rpc_inspection_iwant_cache_miss_message_ids_count", 218 Buckets: []float64{1, 100, 1000}, 219 Help: "total number of cache miss message ids received from gossipsub protocol during the async inspection of a single RPC", 220 }) 221 222 gc.iWantDuplicateMessageIdExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 223 Namespace: namespaceNetwork, 224 Subsystem: subsystemGossip, 225 Name: gc.prefix + "rpc_inspection_iwant_duplicate_message_ids_exceed_threshold_total", 226 Help: "total number of times that the async inspection of iWant messages failed due to the number of duplicate message ids ", 227 }) 228 229 gc.iWantCacheMissMessageIdExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 230 Namespace: namespaceNetwork, 231 Subsystem: subsystemGossip, 232 Name: gc.prefix + "rpc_inspection_iwant_cache_miss_message_ids_exceed_threshold_total", 233 Help: "total number of times that the async inspection of iWant messages failed due to the number of cache miss message ids ", 234 }) 235 236 gc.ctrlMsgInvalidTopicIdCount = *promauto.NewCounterVec(prometheus.CounterOpts{ 237 Namespace: namespaceNetwork, 238 Subsystem: subsystemGossip, 239 Name: gc.prefix + "control_message_invalid_topic_id_total", 240 Help: "total number of control messages with invalid topic id received from gossipsub protocol during the async inspection", 241 }, []string{LabelMessage}) 242 243 gc.errActiveClusterIdsNotSetCount = promauto.NewCounter(prometheus.CounterOpts{ 244 Namespace: namespaceNetwork, 245 Subsystem: subsystemGossip, 246 Name: gc.prefix + "active_cluster_ids_not_inspection_error_total", 247 Help: "total number of inspection errors due to active cluster ids not set inspection failure", 248 }) 249 250 gc.errUnstakedPeerInspectionFailedCount = promauto.NewCounter(prometheus.CounterOpts{ 251 Namespace: namespaceNetwork, 252 Subsystem: subsystemGossip, 253 Name: gc.prefix + "unstaked_peer_inspection_error_total", 254 Help: "total number of inspection errors due to unstaked peer inspection failure", 255 }) 256 257 gc.invalidControlMessageNotificationSentCount = promauto.NewCounter(prometheus.CounterOpts{ 258 Namespace: namespaceNetwork, 259 Subsystem: subsystemGossip, 260 Name: gc.prefix + "invalid_control_message_notification_sent_total", 261 Help: "number of invalid control message notifications (i.e., misbehavior report) sent due to async inspection of rpcs failure", 262 }) 263 264 gc.unstakedNodeRPCRejectedCount = promauto.NewCounter(prometheus.CounterOpts{ 265 Namespace: namespaceNetwork, 266 Subsystem: subsystemGossip, 267 Name: gc.prefix + "unstaked_node_rejection_total", 268 Help: "number of rpcs rejected from unstaked node", 269 }) 270 271 gc.graftDuplicateTopicIdsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 272 Namespace: namespaceNetwork, 273 Subsystem: subsystemGossip, 274 Name: gc.prefix + "rpc_inspection_graft_duplicate_topic_ids_count", 275 Buckets: []float64{1, 100, 1000}, 276 Help: "number of duplicate topic ids on graft messages of a single RPC during the async inspection, regardless of the result of the inspection", 277 }) 278 279 gc.graftInvalidTopicIdsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 280 Namespace: namespaceNetwork, 281 Subsystem: subsystemGossip, 282 Name: gc.prefix + "rpc_inspection_graft_invalid_topic_ids_count", 283 Buckets: []float64{1, 100, 1000}, 284 Help: "number of invalid topic ids on graft messages of a single RPC during the async inspection, regardless of the result of the inspection", 285 }) 286 287 gc.graftDuplicateTopicIdsExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 288 Namespace: namespaceNetwork, 289 Subsystem: subsystemGossip, 290 Name: gc.prefix + "rpc_inspection_graft_duplicate_topic_ids_exceed_threshold_total", 291 Help: "number of times that the async inspection of graft messages of an rpc failed due to the number of duplicate topic ids exceeding the threshold", 292 }) 293 294 gc.graftInvalidTopicIdsExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 295 Namespace: namespaceNetwork, 296 Subsystem: subsystemGossip, 297 Name: gc.prefix + "rpc_inspection_graft_invalid_topic_ids_exceed_threshold_total", 298 Help: "number of times that the async inspection of graft messages of an rpc failed due to the number of invalid topic ids exceeding the threshold", 299 }) 300 301 gc.pruneDuplicateTopicIdsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 302 Namespace: namespaceNetwork, 303 Subsystem: subsystemGossip, 304 Buckets: []float64{1, 100, 1000}, 305 Name: gc.prefix + "rpc_inspection_prune_duplicate_topic_ids_count", 306 Help: "number of duplicate topic ids on prune messages of a single RPC during the async inspection, regardless of the result of the inspection", 307 }) 308 309 gc.pruneInvalidTopicIdsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 310 Namespace: namespaceNetwork, 311 Subsystem: subsystemGossip, 312 Buckets: []float64{1, 100, 1000}, 313 Name: gc.prefix + "rpc_inspection_prune_invalid_topic_ids_count", 314 Help: "number of invalid topic ids on prune messages of a single RPC during the async inspection, regardless of the result of the inspection", 315 }) 316 317 gc.pruneDuplicateTopicIdsExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 318 Namespace: namespaceNetwork, 319 Subsystem: subsystemGossip, 320 Name: gc.prefix + "rpc_inspection_prune_duplicate_topic_ids_exceed_threshold_total", 321 Help: "number of times that the async inspection of prune messages failed due to the number of duplicate topic ids exceeding the threshold", 322 }) 323 324 gc.pruneInvalidTopicIdsExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 325 Namespace: namespaceNetwork, 326 Subsystem: subsystemGossip, 327 Name: gc.prefix + "rpc_inspection_prune_invalid_topic_ids_exceed_threshold_total", 328 Help: "number of times that the async inspection of prune messages failed due to the number of invalid topic ids exceeding the threshold", 329 }) 330 331 gc.publishMessageInspectedErrHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 332 Namespace: namespaceNetwork, 333 Subsystem: subsystemGossip, 334 Name: gc.prefix + "publish_message_inspected_error_count", 335 Buckets: []float64{10, 100, 1000}, 336 Help: "number of errors that occurred during the async inspection of publish messages on a single RPC, regardless pof the result", 337 }) 338 339 gc.publishMessageInvalidSenderCountHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 340 Namespace: namespaceNetwork, 341 Subsystem: subsystemGossip, 342 Name: gc.prefix + "rpc_inspection_publish_message_invalid_sender_count", 343 Buckets: []float64{1, 100, 1000}, 344 Help: "number of invalid senders observed during the async inspection of publish messages on a single RPC, regardless of the result", 345 }) 346 347 gc.publishMessageInvalidTopicIdHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 348 Namespace: namespaceNetwork, 349 Subsystem: subsystemGossip, 350 Name: gc.prefix + "rpc_inspection_publish_message_invalid_topic_id_count", 351 Buckets: []float64{1, 100, 1000}, 352 Help: "number of invalid topic ids observed during the async inspection of publish messages on a single RPC, regardless of the result", 353 }) 354 355 gc.publishMessageInvalidSubscriptionsHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ 356 Namespace: namespaceNetwork, 357 Subsystem: subsystemGossip, 358 Name: gc.prefix + "rpc_inspection_publish_message_invalid_subscriptions_count", 359 Buckets: []float64{1, 100, 1000}, 360 Help: "number of invalid subscriptions observed during the async inspection of publish messages on a single RPC, regardless of the result", 361 }) 362 363 gc.publishMessageInspectionErrExceedThresholdCount = promauto.NewCounter(prometheus.CounterOpts{ 364 Namespace: namespaceNetwork, 365 Subsystem: subsystemGossip, 366 Name: gc.prefix + "publish_message_inspection_err_exceed_threshold_total", 367 Help: "number of rpcs fail on inspection due to published message inspection errors exceeding the threshold", 368 }) 369 370 return gc 371 } 372 373 // AsyncProcessingStarted increments the metric tracking the number of RPC's being processed asynchronously by the rpc validation inspector. 374 func (c *GossipSubRpcValidationInspectorMetrics) AsyncProcessingStarted() { 375 c.rpcCtrlMsgInAsyncPreProcessingGauge.Inc() 376 } 377 378 // AsyncProcessingFinished tracks the time spent by the rpc validation inspector to process an RPC asynchronously and decrements the metric tracking 379 // the number of RPC's being processed asynchronously by the rpc validation inspector. 380 func (c *GossipSubRpcValidationInspectorMetrics) AsyncProcessingFinished(duration time.Duration) { 381 c.rpcCtrlMsgInAsyncPreProcessingGauge.Dec() 382 c.rpcCtrlMsgAsyncProcessingTimeHistogram.Observe(duration.Seconds()) 383 } 384 385 // OnControlMessagesTruncated tracks the number of times a control message was truncated. 386 // Args: 387 // 388 // messageType: the type of the control message that was truncated 389 // diff: the number of message ids truncated. 390 func (c *GossipSubRpcValidationInspectorMetrics) OnControlMessagesTruncated(messageType p2pmsg.ControlMessageType, diff int) { 391 c.rpcCtrlMsgTruncation.WithLabelValues(messageType.String()).Observe(float64(diff)) 392 } 393 394 // OnIHaveControlMessageIdsTruncated tracks the number of times message ids on an iHave message were truncated. 395 // Note that this function is called only when the message ids are truncated from an iHave message, not when the iHave message itself is truncated. 396 // This is different from the OnControlMessagesTruncated function which is called when a slice of control messages truncated from an RPC with all their message ids. 397 // Args: 398 // 399 // diff: the number of actual messages truncated. 400 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveControlMessageIdsTruncated(diff int) { 401 c.OnControlMessagesTruncated(labelIHaveMessageIds, diff) 402 } 403 404 // OnIWantControlMessageIdsTruncated tracks the number of times message ids on an iWant message were truncated. 405 // Note that this function is called only when the message ids are truncated from an iWant message, not when the iWant message itself is truncated. 406 // This is different from the OnControlMessagesTruncated function which is called when a slice of control messages truncated from an RPC with all their message ids. 407 // Args: 408 // 409 // diff: the number of actual messages truncated. 410 func (c *GossipSubRpcValidationInspectorMetrics) OnIWantControlMessageIdsTruncated(diff int) { 411 c.OnControlMessagesTruncated(labelIWantMessageIds, diff) 412 } 413 414 // OnIWantMessageIDsReceived tracks the number of message ids received by the node from other nodes on an RPC. 415 // Note: this function is called on each IWANT message received by the node. 416 // Args: 417 // - msgIdCount: the number of message ids received on the IWANT message. 418 func (c *GossipSubRpcValidationInspectorMetrics) OnIWantMessageIDsReceived(msgIdCount int) { 419 c.receivedIWantMsgIDsHistogram.Observe(float64(msgIdCount)) 420 } 421 422 // OnIHaveMessageIDsReceived tracks the number of message ids received by the node from other nodes on an iHave message. 423 // This function is called on each iHave message received by the node. 424 // Args: 425 // - channel: the channel on which the iHave message was received. 426 // - msgIdCount: the number of message ids received on the iHave message. 427 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveMessageIDsReceived(channel string, msgIdCount int) { 428 c.receivedIHaveMsgIDsHistogram.WithLabelValues(channel).Observe(float64(msgIdCount)) 429 } 430 431 // OnIncomingRpcReceived tracks the number of incoming RPC messages received by the node. 432 func (c *GossipSubRpcValidationInspectorMetrics) OnIncomingRpcReceived(iHaveCount, iWantCount, graftCount, pruneCount, msgCount int) { 433 c.incomingRpcCount.Inc() 434 c.receivedPublishMessageCount.Add(float64(msgCount)) 435 c.receivedPruneCount.Add(float64(pruneCount)) 436 c.receivedGraftCount.Add(float64(graftCount)) 437 c.receivedIWantMsgCount.Add(float64(iWantCount)) 438 c.receivedIHaveMsgCount.Add(float64(iHaveCount)) 439 } 440 441 // OnIWantMessagesInspected tracks the number of duplicate and cache miss message ids received by the node on iWant messages at the end of the async inspection iWants 442 // across one RPC, regardless of the result of the inspection. 443 // 444 // duplicateCount: the total number of duplicate message ids received by the node on the iWant messages at the end of the async inspection of the RPC. 445 // cacheMissCount: the total number of cache miss message ids received by the node on the iWant message at the end of the async inspection of the RPC. 446 func (c *GossipSubRpcValidationInspectorMetrics) OnIWantMessagesInspected(duplicateCount int, cacheMissCount int) { 447 c.iWantDuplicateMessageIdHistogram.Observe(float64(duplicateCount)) 448 c.iWantCacheMissHistogram.Observe(float64(cacheMissCount)) 449 } 450 451 // OnIWantDuplicateMessageIdsExceedThreshold tracks the number of times that async inspection of iWant messages failed due to the total number of duplicate message ids 452 // received by the node on the iWant messages of a single RPC exceeding the threshold, which results in a misbehaviour report. 453 func (c *GossipSubRpcValidationInspectorMetrics) OnIWantDuplicateMessageIdsExceedThreshold() { 454 c.iWantDuplicateMessageIdExceedThresholdCount.Inc() 455 } 456 457 // OnIWantCacheMissMessageIdsExceedThreshold tracks the number of times that async inspection of iWant messages failed due to the total 458 // number of cache miss message ids received by the node on the iWant messages of a single RPC exceeding the threshold, which results in a misbehaviour report. 459 func (c *GossipSubRpcValidationInspectorMetrics) OnIWantCacheMissMessageIdsExceedThreshold() { 460 c.iWantCacheMissMessageIdExceedThresholdCount.Inc() 461 } 462 463 // OnIHaveMessagesInspected is called at the end of the async inspection of iHave messages of a single RPC, regardless of the result of the inspection. 464 // It tracks the number of duplicate topic ids and duplicate message ids received by the node on the iHave messages of that single RPC at the end of the async inspection iHaves. 465 // Args: 466 // 467 // duplicateTopicIds: the total number of duplicate topic ids received by the node on the iHave messages at the end of the async inspection of the RPC. 468 // duplicateMessageIds: the number of duplicate message ids received by the node on the iHave messages at the end of the async inspection of the RPC. 469 // invalidTopicIds: the number of invalid message ids received by the node on the iHave messages at the end of the async inspection of the RPC. 470 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveMessagesInspected(duplicateTopicIds, duplicateMessageIds, invalidTopicIds int) { 471 c.iHaveDuplicateTopicIdHistogram.Observe(float64(duplicateTopicIds)) 472 c.iHaveDuplicateMessageIdHistogram.Observe(float64(duplicateMessageIds)) 473 c.iHaveInvalidTopicIdHistogram.Observe(float64(invalidTopicIds)) 474 } 475 476 // OnIHaveDuplicateTopicIdsExceedThreshold tracks the number of times that the async inspection of iHave messages of a single RPC failed due to the total number of duplicate topic ids 477 // received by the node on the iHave messages of that RPC exceeding the threshold, which results in a misbehaviour report. 478 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveDuplicateTopicIdsExceedThreshold() { 479 c.iHaveDuplicateTopicIdExceedThresholdCount.Inc() 480 } 481 482 // OnIHaveDuplicateMessageIdsExceedThreshold tracks the number of times that the async inspection of iHave messages of a single RPC failed due to the total number of duplicate message ids 483 // received by the node on an iHave message exceeding the threshold, which results in a misbehaviour report. 484 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveDuplicateMessageIdsExceedThreshold() { 485 c.iHaveDuplicateMessageIdExceedThresholdCount.Inc() 486 } 487 488 // OnIHaveInvalidTopicIdsExceedThreshold tracks the number of times that the async inspection of iHave messages of a single RPC failed due to the total number of invalid topic ids 489 // received by the node on the iHave messages of that RPC exceeding the threshold, which results in a misbehaviour report. 490 func (c *GossipSubRpcValidationInspectorMetrics) OnIHaveInvalidTopicIdsExceedThreshold() { 491 c.iHaveInvalidTopicIdExceedThresholdCount.Inc() 492 } 493 494 // OnInvalidTopicIdDetectedForControlMessage tracks the number of times that the async inspection of a control message type on a single RPC failed due to an invalid topic id. 495 // Args: 496 // - messageType: the type of the control message that was truncated. 497 func (c *GossipSubRpcValidationInspectorMetrics) OnInvalidTopicIdDetectedForControlMessage(messageType p2pmsg.ControlMessageType) { 498 c.ctrlMsgInvalidTopicIdCount.WithLabelValues(messageType.String()).Inc() 499 } 500 501 // OnActiveClusterIDsNotSetErr tracks the number of times that the async inspection of a control message type on a single RPC failed due to active cluster ids not set inspection failure. 502 // This is not causing a misbehaviour report. 503 func (c *GossipSubRpcValidationInspectorMetrics) OnActiveClusterIDsNotSetErr() { 504 c.errActiveClusterIdsNotSetCount.Inc() 505 } 506 507 // OnUnstakedPeerInspectionFailed tracks the number of times that the async inspection of a control message type on a single RPC failed due to unstaked peer inspection failure. 508 // This is not causing a misbehaviour report. 509 func (c *GossipSubRpcValidationInspectorMetrics) OnUnstakedPeerInspectionFailed() { 510 c.errUnstakedPeerInspectionFailedCount.Inc() 511 } 512 513 // OnInvalidControlMessageNotificationSent tracks the number of times that the async inspection of a control message failed and resulted in dissemination of an invalid control message was sent (i.e., a 514 // misbehavior report). 515 func (c *GossipSubRpcValidationInspectorMetrics) OnInvalidControlMessageNotificationSent() { 516 c.invalidControlMessageNotificationSentCount.Inc() 517 } 518 519 // OnRpcRejectedFromUnknownSender tracks the number of rpc's rejected from unstaked nodes. 520 func (c *GossipSubRpcValidationInspectorMetrics) OnRpcRejectedFromUnknownSender() { 521 c.unstakedNodeRPCRejectedCount.Inc() 522 } 523 524 // OnPruneDuplicateTopicIdsExceedThreshold tracks the number of times that the async inspection of prune messages for an RPC failed due to the number of duplicate topic ids 525 // received by the node on prune messages of the same RPC excesses threshold, which results in a misbehaviour report. 526 func (c *GossipSubRpcValidationInspectorMetrics) OnPruneDuplicateTopicIdsExceedThreshold() { 527 c.pruneDuplicateTopicIdsExceedThresholdCount.Inc() 528 } 529 530 // OnPruneInvalidTopicIdsExceedThreshold tracks the number of times that the async inspection of prune messages for an RPC failed due to the number of invalid topic ids 531 // received by the node on prune messages of the same RPC excesses threshold, which results in a misbehaviour report. 532 func (c *GossipSubRpcValidationInspectorMetrics) OnPruneInvalidTopicIdsExceedThreshold() { 533 c.pruneInvalidTopicIdsExceedThresholdCount.Inc() 534 } 535 536 // OnPruneMessageInspected is called at the end of the async inspection of prune messages of the RPC, regardless of the result of the inspection. 537 // Args: 538 // 539 // duplicateTopicIds: the number of duplicate topic ids received by the node on the prune messages of the RPC at the end of the async inspection prunes. 540 // invalidTopicIds: the number of invalid message ids received by the node on the prune messages at the end of the async inspection of the RPC. 541 func (c *GossipSubRpcValidationInspectorMetrics) OnPruneMessageInspected(duplicateTopicIds, invalidTopicIds int) { 542 c.pruneDuplicateTopicIdsHistogram.Observe(float64(duplicateTopicIds)) 543 c.pruneInvalidTopicIdsHistogram.Observe(float64(invalidTopicIds)) 544 } 545 546 // OnGraftDuplicateTopicIdsExceedThreshold tracks the number of times that the async inspection of a graft message failed due to the number of duplicate topic ids. 547 // received by the node on graft messages of the same rpc excesses threshold, which results in a misbehaviour report. 548 func (c *GossipSubRpcValidationInspectorMetrics) OnGraftDuplicateTopicIdsExceedThreshold() { 549 c.graftDuplicateTopicIdsExceedThresholdCount.Inc() 550 } 551 552 // OnGraftInvalidTopicIdsExceedThreshold tracks the number of times that the async inspection of the graft messages of a single RPC failed due to the number of invalid topic ids 553 // received by the node on graft messages of the same RPC excesses threshold, which results in a misbehaviour report. 554 func (c *GossipSubRpcValidationInspectorMetrics) OnGraftInvalidTopicIdsExceedThreshold() { 555 c.graftInvalidTopicIdsExceedThresholdCount.Inc() 556 } 557 558 // OnGraftMessageInspected is called at the end of the async inspection of graft messages of a single RPC, regardless of the result of the inspection. 559 // Args: 560 // 561 // duplicateTopicIds: the number of duplicate topic ids received by the node on the graft messages at the end of the async inspection of a single RPC. 562 // invalidTopicIds: the number of invalid message ids received by the node on the graft messages at the end of the async inspection of the RPC. 563 func (c *GossipSubRpcValidationInspectorMetrics) OnGraftMessageInspected(duplicateTopicIds, invalidTopicIds int) { 564 c.graftDuplicateTopicIdsHistogram.Observe(float64(duplicateTopicIds)) 565 c.graftInvalidTopicIdsHistogram.Observe(float64(invalidTopicIds)) 566 } 567 568 // OnPublishMessageInspected is called at the end of the async inspection of publish messages of a single RPC, regardless of the result of the inspection. 569 // It tracks the total number of errors detected during the async inspection of the rpc together with their individual breakdown. 570 // Args: 571 // - errCount: the number of errors that occurred during the async inspection of publish messages. 572 // - invalidTopicIdsCount: the number of times that an invalid topic id was detected during the async inspection of publish messages. 573 // - invalidSubscriptionsCount: the number of times that an invalid subscription was detected during the async inspection of publish messages. 574 // - invalidSendersCount: the number of times that an invalid sender was detected during the async inspection of publish messages. 575 func (c *GossipSubRpcValidationInspectorMetrics) OnPublishMessageInspected(totalErrCount int, invalidTopicIdsCount int, invalidSubscriptionsCount int, invalidSendersCount int) { 576 c.publishMessageInspectedErrHistogram.Observe(float64(totalErrCount)) 577 c.publishMessageInvalidSenderCountHistogram.Observe(float64(invalidSendersCount)) 578 c.publishMessageInvalidSubscriptionsHistogram.Observe(float64(invalidSubscriptionsCount)) 579 c.publishMessageInvalidTopicIdHistogram.Observe(float64(invalidTopicIdsCount)) 580 } 581 582 // OnPublishMessagesInspectionErrorExceedsThreshold tracks the number of times that async inspection of publish messages failed due to the number of errors exceeding the threshold. 583 // Note that it causes a misbehaviour report. 584 func (c *GossipSubRpcValidationInspectorMetrics) OnPublishMessagesInspectionErrorExceedsThreshold() { 585 c.publishMessageInspectionErrExceedThresholdCount.Inc() 586 }