mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Add Detailed Multi Value Metrics (#13429)
* add it * pingo * gaz * remove pingo * fix for old forks
This commit is contained in:
@@ -66,6 +66,7 @@ type ReadOnlyBeaconState interface {
|
||||
HistoricalSummaries() ([]*ethpb.HistoricalSummary, error)
|
||||
Slashings() []uint64
|
||||
FieldReferencesCount() map[string]uint64
|
||||
RecordStateMetrics()
|
||||
MarshalSSZ() ([]byte, error)
|
||||
IsNil() bool
|
||||
Version() int
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
||||
multi_value_slice "github.com/prysmaticlabs/prysm/v4/container/multi-value-slice"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
@@ -12,24 +13,26 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
multiValueRandaoMixesCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_randao_mixes_count",
|
||||
})
|
||||
multiValueBlockRootsCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_block_roots_count",
|
||||
})
|
||||
multiValueStateRootsCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_state_roots_count",
|
||||
})
|
||||
multiValueBalancesCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_balances_count",
|
||||
})
|
||||
multiValueValidatorsCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_validators_count",
|
||||
})
|
||||
multiValueInactivityScoresCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "multi_value_inactivity_scores_count",
|
||||
})
|
||||
multiValueCountGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "multi_value_object_count",
|
||||
Help: "The number of instances that exist for the multivalue slice for a particular field.",
|
||||
}, []string{"field"})
|
||||
multiValueIndividualElementsCountGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "multi_value_individual_elements_count",
|
||||
Help: "The number of individual elements that exist for the multivalue slice object.",
|
||||
}, []string{"field"})
|
||||
multiValueIndividualElementReferencesCountGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "multi_value_individual_element_references_count",
|
||||
Help: "The number of individual element references that exist for the multivalue slice object.",
|
||||
}, []string{"field"})
|
||||
multiValueAppendedElementsCountGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "multi_value_appended_elements_count",
|
||||
Help: "The number of appended elements that exist for the multivalue slice object.",
|
||||
}, []string{"field"})
|
||||
multiValueAppendedElementReferencesCountGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "multi_value_appended_element_references_count",
|
||||
Help: "The number of appended element references that exist for the multivalue slice object.",
|
||||
}, []string{"field"})
|
||||
)
|
||||
|
||||
// MultiValueRandaoMixes is a multi-value slice of randao mixes.
|
||||
@@ -43,7 +46,7 @@ func NewMultiValueRandaoMixes(mixes [][]byte) *MultiValueRandaoMixes {
|
||||
}
|
||||
mv := &MultiValueRandaoMixes{}
|
||||
mv.Init(items)
|
||||
multiValueRandaoMixesCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.RandaoMixes.String()).Inc()
|
||||
runtime.SetFinalizer(mv, randaoMixesFinalizer)
|
||||
return mv
|
||||
}
|
||||
@@ -59,7 +62,7 @@ func NewMultiValueBlockRoots(roots [][]byte) *MultiValueBlockRoots {
|
||||
}
|
||||
mv := &MultiValueBlockRoots{}
|
||||
mv.Init(items)
|
||||
multiValueBlockRootsCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.BlockRoots.String()).Inc()
|
||||
runtime.SetFinalizer(mv, blockRootsFinalizer)
|
||||
return mv
|
||||
}
|
||||
@@ -75,7 +78,7 @@ func NewMultiValueStateRoots(roots [][]byte) *MultiValueStateRoots {
|
||||
}
|
||||
mv := &MultiValueStateRoots{}
|
||||
mv.Init(items)
|
||||
multiValueStateRootsCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.StateRoots.String()).Inc()
|
||||
runtime.SetFinalizer(mv, stateRootsFinalizer)
|
||||
return mv
|
||||
}
|
||||
@@ -89,7 +92,7 @@ func NewMultiValueBalances(balances []uint64) *MultiValueBalances {
|
||||
copy(items, balances)
|
||||
mv := &MultiValueBalances{}
|
||||
mv.Init(items)
|
||||
multiValueBalancesCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.Balances.String()).Inc()
|
||||
runtime.SetFinalizer(mv, balancesFinalizer)
|
||||
return mv
|
||||
}
|
||||
@@ -103,7 +106,7 @@ func NewMultiValueInactivityScores(scores []uint64) *MultiValueInactivityScores
|
||||
copy(items, scores)
|
||||
mv := &MultiValueInactivityScores{}
|
||||
mv.Init(items)
|
||||
multiValueInactivityScoresCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.InactivityScores.String()).Inc()
|
||||
runtime.SetFinalizer(mv, inactivityScoresFinalizer)
|
||||
return mv
|
||||
}
|
||||
@@ -115,31 +118,31 @@ type MultiValueValidators = multi_value_slice.Slice[*ethpb.Validator]
|
||||
func NewMultiValueValidators(vals []*ethpb.Validator) *MultiValueValidators {
|
||||
mv := &MultiValueValidators{}
|
||||
mv.Init(vals)
|
||||
multiValueValidatorsCountGauge.Inc()
|
||||
multiValueCountGauge.WithLabelValues(types.Validators.String()).Inc()
|
||||
runtime.SetFinalizer(mv, validatorsFinalizer)
|
||||
return mv
|
||||
}
|
||||
|
||||
func randaoMixesFinalizer(m *MultiValueRandaoMixes) {
|
||||
multiValueRandaoMixesCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.RandaoMixes.String()).Dec()
|
||||
}
|
||||
|
||||
func blockRootsFinalizer(m *MultiValueBlockRoots) {
|
||||
multiValueBlockRootsCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.BlockRoots.String()).Dec()
|
||||
}
|
||||
|
||||
func stateRootsFinalizer(m *MultiValueStateRoots) {
|
||||
multiValueStateRootsCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.StateRoots.String()).Dec()
|
||||
}
|
||||
|
||||
func balancesFinalizer(m *MultiValueBalances) {
|
||||
multiValueBalancesCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.Balances.String()).Dec()
|
||||
}
|
||||
|
||||
func validatorsFinalizer(m *MultiValueValidators) {
|
||||
multiValueValidatorsCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.Validators.String()).Dec()
|
||||
}
|
||||
|
||||
func inactivityScoresFinalizer(m *MultiValueInactivityScores) {
|
||||
multiValueInactivityScoresCountGauge.Dec()
|
||||
multiValueCountGauge.WithLabelValues(types.InactivityScores.String()).Dec()
|
||||
}
|
||||
|
||||
@@ -932,6 +932,68 @@ func (b *BeaconState) FieldReferencesCount() map[string]uint64 {
|
||||
return refMap
|
||||
}
|
||||
|
||||
// RecordStateMetrics proceeds to record any state related metrics data.
|
||||
func (b *BeaconState) RecordStateMetrics() {
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
// Only run this for nodes running with the experimental state.
|
||||
if !features.Get().EnableExperimentalState {
|
||||
return
|
||||
}
|
||||
|
||||
// Validators
|
||||
if b.validatorsMultiValue != nil {
|
||||
stats := b.validatorsMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.Validators.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.Validators.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.Validators.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.Validators.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
|
||||
// Balances
|
||||
if b.balancesMultiValue != nil {
|
||||
stats := b.balancesMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.Balances.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.Balances.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.Balances.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.Balances.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
|
||||
// InactivityScores
|
||||
if b.inactivityScoresMultiValue != nil {
|
||||
stats := b.inactivityScoresMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.InactivityScores.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.InactivityScores.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.InactivityScores.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.InactivityScores.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
// BlockRoots
|
||||
if b.blockRootsMultiValue != nil {
|
||||
stats := b.blockRootsMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.BlockRoots.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.BlockRoots.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.BlockRoots.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.BlockRoots.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
|
||||
// StateRoots
|
||||
if b.stateRootsMultiValue != nil {
|
||||
stats := b.stateRootsMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.StateRoots.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.StateRoots.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.StateRoots.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.StateRoots.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
// RandaoMixes
|
||||
if b.randaoMixesMultiValue != nil {
|
||||
stats := b.randaoMixesMultiValue.MultiValueStatistics()
|
||||
multiValueIndividualElementsCountGauge.WithLabelValues(types.RandaoMixes.String()).Set(float64(stats.TotalIndividualElements))
|
||||
multiValueIndividualElementReferencesCountGauge.WithLabelValues(types.RandaoMixes.String()).Set(float64(stats.TotalIndividualElemReferences))
|
||||
multiValueAppendedElementsCountGauge.WithLabelValues(types.RandaoMixes.String()).Set(float64(stats.TotalAppendedElements))
|
||||
multiValueAppendedElementReferencesCountGauge.WithLabelValues(types.RandaoMixes.String()).Set(float64(stats.TotalAppendedElemReferences))
|
||||
}
|
||||
}
|
||||
|
||||
// IsNil checks if the state and the underlying proto
|
||||
// object are nil.
|
||||
func (b *BeaconState) IsNil() bool {
|
||||
|
||||
Reference in New Issue
Block a user