Skip to content

Commit

Permalink
Add replay block count metric (#7060)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored Aug 20, 2020
1 parent 2bf1332 commit 8bdf9db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions beacon-chain/state/stategen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ go_library(
"//shared/featureconfig:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_k8s_client_go//tools/cache:go_default_library",
Expand Down
14 changes: 14 additions & 0 deletions beacon-chain/state/stategen/hot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
Expand All @@ -13,6 +15,16 @@ import (
"go.opencensus.io/trace"
)

var (
replayBlockCount = promauto.NewHistogram(
prometheus.HistogramOpts{
Name: "replay_blocks_count",
Help: "The number of blocks to replay to generate a state",
Buckets: []float64{64, 256, 1024, 2048, 4096},
},
)
)

// HasState returns true if the state exists in cache or in DB.
func (s *State) HasState(ctx context.Context, blockRoot [32]byte) (bool, error) {
if s.hotStateCache.Has(blockRoot) {
Expand Down Expand Up @@ -112,6 +124,8 @@ func (s *State) loadHotStateByRoot(ctx context.Context, blockRoot [32]byte) (*st
return nil, errors.Wrap(err, "could not load blocks for hot state using root")
}

replayBlockCount.Observe(float64(len(blks)))

return s.ReplayBlocks(ctx, startState, blks, targetSlot)
}

Expand Down

0 comments on commit 8bdf9db

Please sign in to comment.