github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/gossipsub_scoring_registry.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  	"github.com/prometheus/client_golang/prometheus/promauto"
     6  
     7  	"github.com/onflow/flow-go/module"
     8  )
     9  
    10  // GossipSubScoringRegistryMetrics encapsulates the metrics collectors for collecting metrics related to the Gossipsub scoring registry, offering insights into penalties and
    11  // other factors used by the scoring registry to compute the application-specific score. It focuses on tracking internal
    12  // aspects of the application-specific score, distinguishing itself from GossipSubScoringMetrics.
    13  type GossipSubScoringRegistryMetrics struct {
    14  	prefix                    string
    15  	duplicateMessagePenalties prometheus.Histogram
    16  	duplicateMessageCounts    prometheus.Histogram
    17  }
    18  
    19  var _ module.GossipSubScoringRegistryMetrics = (*GossipSubScoringRegistryMetrics)(nil)
    20  
    21  // NewGossipSubScoringRegistryMetrics returns a new *GossipSubScoringRegistryMetrics.
    22  func NewGossipSubScoringRegistryMetrics(prefix string) *GossipSubScoringRegistryMetrics {
    23  	gc := &GossipSubScoringRegistryMetrics{prefix: prefix}
    24  	gc.duplicateMessagePenalties = promauto.NewHistogram(
    25  		prometheus.HistogramOpts{
    26  			Namespace: namespaceNetwork,
    27  			Subsystem: subsystemGossip,
    28  			Name:      gc.prefix + "gossipsub_scoring_registry_duplicate_message_penalties",
    29  			Help:      "duplicate message penalty applied to the overall application specific score of a node",
    30  			Buckets:   []float64{-1, -0.01, -0.001},
    31  		},
    32  	)
    33  	gc.duplicateMessageCounts = promauto.NewHistogram(
    34  		prometheus.HistogramOpts{
    35  			Namespace: namespaceNetwork,
    36  			Subsystem: subsystemGossip,
    37  			Name:      gc.prefix + "gossipsub_scoring_registry_duplicate_message_counts",
    38  			Help:      "duplicate message count of a node at the time it is used to compute the duplicate message penalty",
    39  			Buckets:   []float64{25, 50, 100, 1000},
    40  		},
    41  	)
    42  	return gc
    43  }
    44  
    45  // DuplicateMessagePenalties tracks the duplicate message penalty for a node.
    46  func (g GossipSubScoringRegistryMetrics) DuplicateMessagePenalties(penalty float64) {
    47  	g.duplicateMessagePenalties.Observe(penalty)
    48  }
    49  
    50  // DuplicateMessagesCounts tracks the duplicate message count for a node.
    51  func (g GossipSubScoringRegistryMetrics) DuplicateMessagesCounts(count float64) {
    52  	g.duplicateMessageCounts.Observe(count)
    53  }