mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Update state metrics on save state (#2083)
* Update state metrics on save state * fix tests
This commit is contained in:
parent
6012d0a5d1
commit
ac7d5a7780
@ -491,6 +491,7 @@ func TestLMDGhost_TrivialHeadUpdate(t *testing.T) {
|
|||||||
state := &pb.BeaconState{
|
state := &pb.BeaconState{
|
||||||
Slot: 10,
|
Slot: 10,
|
||||||
ValidatorBalances: []uint64{params.BeaconConfig().MaxDepositAmount},
|
ValidatorBalances: []uint64{params.BeaconConfig().MaxDepositAmount},
|
||||||
|
ValidatorRegistry: []*pb.Validator{{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||||
@ -548,6 +549,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
|
|||||||
params.BeaconConfig().MaxDepositAmount,
|
params.BeaconConfig().MaxDepositAmount,
|
||||||
params.BeaconConfig().MaxDepositAmount,
|
params.BeaconConfig().MaxDepositAmount,
|
||||||
params.BeaconConfig().MaxDepositAmount},
|
params.BeaconConfig().MaxDepositAmount},
|
||||||
|
ValidatorRegistry: []*pb.Validator{{}, {}, {}, {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||||
@ -631,6 +633,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
|
|||||||
params.BeaconConfig().MaxDepositAmount,
|
params.BeaconConfig().MaxDepositAmount,
|
||||||
params.BeaconConfig().MaxDepositAmount,
|
params.BeaconConfig().MaxDepositAmount,
|
||||||
params.BeaconConfig().MaxDepositAmount},
|
params.BeaconConfig().MaxDepositAmount},
|
||||||
|
ValidatorRegistry: []*pb.Validator{{}, {}, {}, {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||||
|
@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
|||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"metrics.go",
|
|
||||||
"state.go",
|
"state.go",
|
||||||
"transition.go",
|
"transition.go",
|
||||||
],
|
],
|
||||||
@ -20,8 +19,6 @@ go_library(
|
|||||||
"//shared/featureconfig:go_default_library",
|
"//shared/featureconfig:go_default_library",
|
||||||
"//shared/hashutil:go_default_library",
|
"//shared/hashutil:go_default_library",
|
||||||
"//shared/params:go_default_library",
|
"//shared/params:go_default_library",
|
||||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
|
||||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
|
||||||
"@com_github_sirupsen_logrus//:go_default_library",
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
"@io_opencensus_go//trace:go_default_library",
|
"@io_opencensus_go//trace:go_default_library",
|
||||||
],
|
],
|
||||||
@ -30,7 +27,6 @@ go_library(
|
|||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"metrics_test.go",
|
|
||||||
"state_test.go",
|
"state_test.go",
|
||||||
"transition_test.go",
|
"transition_test.go",
|
||||||
],
|
],
|
||||||
@ -43,6 +39,5 @@ go_test(
|
|||||||
"//shared/forkutil:go_default_library",
|
"//shared/forkutil:go_default_library",
|
||||||
"//shared/hashutil:go_default_library",
|
"//shared/hashutil:go_default_library",
|
||||||
"//shared/params:go_default_library",
|
"//shared/params:go_default_library",
|
||||||
"@com_github_prometheus_client_golang//prometheus/testutil:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package state
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
||||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestReportEpochTransitionMetrics_validatorBalances(t *testing.T) {
|
|
||||||
state := &pb.BeaconState{
|
|
||||||
ValidatorBalances: []uint64{1, 15},
|
|
||||||
ValidatorRegistry: []*pb.Validator{
|
|
||||||
{Pubkey: []byte{1}},
|
|
||||||
{Pubkey: []byte{2}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
reportEpochTransitionMetrics(state)
|
|
||||||
expectedMetadata := `
|
|
||||||
# HELP state_validator_balances Balances of validators, updated on epoch transition
|
|
||||||
# TYPE state_validator_balances gauge
|
|
||||||
`
|
|
||||||
expectedValues := `
|
|
||||||
state_validator_balances{validator="0x01"} 1
|
|
||||||
state_validator_balances{validator="0x02"} 15
|
|
||||||
`
|
|
||||||
expected := expectedMetadata + expectedValues
|
|
||||||
if err := testutil.CollectAndCompare(validatorBalancesGauge, strings.NewReader(expected)); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -466,7 +466,5 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState, config *Transition
|
|||||||
log.Infof("Validator balances: %v", state.ValidatorBalances)
|
log.Infof("Validator balances: %v", state.ValidatorBalances)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report interesting metrics.
|
|
||||||
reportEpochTransitionMetrics(state)
|
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ go_library(
|
|||||||
"schema.go",
|
"schema.go",
|
||||||
"setup_db.go",
|
"setup_db.go",
|
||||||
"state.go",
|
"state.go",
|
||||||
|
"state_metrics.go",
|
||||||
"validator.go",
|
"validator.go",
|
||||||
"verify_contract.go",
|
"verify_contract.go",
|
||||||
],
|
],
|
||||||
|
@ -148,6 +148,7 @@ func (db *BeaconDB) SaveState(beaconState *pb.BeaconState) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stateBytes.Set(float64(len(beaconStateEnc)))
|
stateBytes.Set(float64(len(beaconStateEnc)))
|
||||||
|
reportStateMetrics(beaconState)
|
||||||
return chainInfo.Put(stateLookupKey, beaconStateEnc)
|
return chainInfo.Put(stateLookupKey, beaconStateEnc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package state
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
@ -34,7 +34,7 @@ var (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
func reportEpochTransitionMetrics(state *pb.BeaconState) {
|
func reportStateMetrics(state *pb.BeaconState) {
|
||||||
// Validator balances
|
// Validator balances
|
||||||
for i, bal := range state.ValidatorBalances {
|
for i, bal := range state.ValidatorBalances {
|
||||||
validatorBalancesGauge.WithLabelValues(
|
validatorBalancesGauge.WithLabelValues(
|
Loading…
Reference in New Issue
Block a user