Skip to content

Commit

Permalink
Update blockchain metrics (#4747)
Browse files Browse the repository at this point in the history
* Make new metrics the canonical one
* Both threads share same metric set
* Comments
* Fix vis
  • Loading branch information
terencechain committed Feb 4, 2020
1 parent b705ab0 commit 8c5c735
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 217 deletions.
4 changes: 1 addition & 3 deletions beacon-chain/blockchain/BUILD.bazel
Expand Up @@ -6,7 +6,6 @@ go_library(
"chain_info.go",
"info.go",
"log.go",
"metrics.go",
"process_attestation.go",
"process_attestation_helpers.go",
"process_block.go",
Expand All @@ -19,6 +18,7 @@ go_library(
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/blockchain/forkchoice:go_default_library",
"//beacon-chain/blockchain/metrics:go_default_library",
"//beacon-chain/cache:go_default_library",
"//beacon-chain/cache/depositcache:go_default_library",
"//beacon-chain/core/blocks:go_default_library",
Expand Down Expand Up @@ -46,8 +46,6 @@ go_library(
"@com_github_emicklei_dot//:go_default_library",
"@com_github_gogo_protobuf//proto: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_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
5 changes: 1 addition & 4 deletions beacon-chain/blockchain/forkchoice/BUILD.bazel
Expand Up @@ -5,17 +5,16 @@ go_library(
srcs = [
"doc.go",
"log.go",
"metrics.go",
"process_attestation.go",
"process_block.go",
"service.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/forkchoice",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/blockchain/metrics:go_default_library",
"//beacon-chain/cache:go_default_library",
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/state:go_default_library",
"//beacon-chain/db:go_default_library",
Expand All @@ -30,8 +29,6 @@ go_library(
"//shared/traceutil:go_default_library",
"@com_github_gogo_protobuf//proto: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_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
160 changes: 0 additions & 160 deletions beacon-chain/blockchain/forkchoice/metrics.go

This file was deleted.

5 changes: 3 additions & 2 deletions beacon-chain/blockchain/forkchoice/process_block.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain/metrics"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) (*
// Epoch boundary bookkeeping such as logging epoch summaries.
if postState.Slot() >= s.nextEpochBoundarySlot {
logEpochData(postState)
reportEpochMetrics(postState)
metrics.ReportEpochMetrics(postState)

// Update committees cache at epoch boundary slot.
if err := helpers.UpdateCommitteeCache(postState, helpers.CurrentEpoch(postState)); err != nil {
Expand Down Expand Up @@ -259,7 +260,7 @@ func (s *Store) OnBlockInitialSyncStateTransition(ctx context.Context, signed *e

// Epoch boundary bookkeeping such as logging epoch summaries.
if postState.Slot() >= s.nextEpochBoundarySlot {
reportEpochMetrics(postState)
metrics.ReportEpochMetrics(postState)

s.nextEpochBoundarySlot = helpers.StartSlot(helpers.NextEpoch(postState))
}
Expand Down
16 changes: 16 additions & 0 deletions beacon-chain/blockchain/metrics/BUILD.bazel
@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["metrics.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/metrics",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/state:go_default_library",
"//shared/bytesutil: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",
],
)
@@ -1,4 +1,4 @@
package blockchain
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -18,97 +18,84 @@ var (
Name: "beacon_head_slot",
Help: "Slot of the head block of the beacon chain",
})
competingBlks = promauto.NewCounter(prometheus.CounterOpts{
// CompetingBlks is the number of the competing blocks happened over time.
CompetingBlks = promauto.NewCounter(prometheus.CounterOpts{
Name: "competing_blocks",
Help: "The # of blocks received and processed from a competing chain",
})
processedBlkNoPubsub = promauto.NewCounter(prometheus.CounterOpts{
Name: "processed_no_pubsub_block_counter",
Help: "The # of processed block without pubsub, this usually means the blocks from sync",
})
processedBlkNoPubsubForkchoice = promauto.NewCounter(prometheus.CounterOpts{
Name: "processed_no_pubsub_forkchoice_block_counter",
Help: "The # of processed block without pubsub and forkchoice, this means indicate blocks from initial sync",
})
processedBlk = promauto.NewCounter(prometheus.CounterOpts{
Name: "processed_block_counter",
Help: "The # of total processed in block chain service, with fork choice and pubsub",
})
processedAttNoPubsub = promauto.NewCounter(prometheus.CounterOpts{
Name: "processed_no_pubsub_attestation_counter",
Help: "The # of processed attestation without pubsub, this usually means the attestations from sync",
})
headFinalizedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_head_finalized_epoch",
Name: "head_finalized_epoch",
Help: "Last finalized epoch of the head state",
})
headFinalizedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_head_finalized_root",
Name: "head_finalized_root",
Help: "Last finalized root of the head state",
})
beaconFinalizedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_finalized_epoch",
Name: "beacon_finalized_epoch",
Help: "Last finalized epoch of the processed state",
})
beaconFinalizedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_finalized_root",
Name: "beacon_finalized_root",
Help: "Last finalized root of the processed state",
})
beaconCurrentJustifiedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_current_justified_epoch",
Name: "beacon_current_justified_epoch",
Help: "Current justified epoch of the processed state",
})
beaconCurrentJustifiedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_current_justified_root",
Name: "beacon_current_justified_root",
Help: "Current justified root of the processed state",
})
beaconPrevJustifiedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_previous_justified_epoch",
Name: "beacon_previous_justified_epoch",
Help: "Previous justified epoch of the processed state",
})
beaconPrevJustifiedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_beacon_previous_justified_root",
Name: "beacon_previous_justified_root",
Help: "Previous justified root of the processed state",
})
validatorsCount = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "chain_service_validator_count",
Name: "validator_count",
Help: "The total number of validators",
}, []string{"state"})
validatorsBalance = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "chain_service_validators_total_balance",
Name: "validators_total_balance",
Help: "The total balance of validators, in GWei",
}, []string{"state"})
validatorsEffectiveBalance = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "chain_service_validators_total_effective_balance",
Name: "validators_total_effective_balance",
Help: "The total effective balance of validators, in GWei",
}, []string{"state"})
currentEth1DataDepositCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_current_eth1_data_deposit_count",
Name: "current_eth1_data_deposit_count",
Help: "The current eth1 deposit count in the last processed state eth1data field.",
})
totalEligibleBalances = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_total_eligible_balances",
Name: "total_eligible_balances",
Help: "The total amount of ether, in gwei, that has been used in voting attestation target of previous epoch",
})
totalVotedTargetBalances = promauto.NewGauge(prometheus.GaugeOpts{
Name: "chain_service_total_voted_target_balances",
Name: "total_voted_target_balances",
Help: "The total amount of ether, in gwei, that is eligible for voting of previous epoch",
})
)

func (s *Service) reportSlotMetrics(currentSlot uint64) {
// ReportSlotMetrics reports slot related metrics.
func ReportSlotMetrics(currentSlot uint64, headSlot uint64, headState *stateTrie.BeaconState) {
beaconSlot.Set(float64(currentSlot))
beaconHeadSlot.Set(float64(s.HeadSlot()))
if s.headState != nil {
finalizedCpt := s.headState.FinalizedCheckpoint()
beaconHeadSlot.Set(float64(headSlot))
if headState != nil {
finalizedCpt := headState.FinalizedCheckpoint()
if finalizedCpt != nil {
headFinalizedEpoch.Set(float64(finalizedCpt.Epoch))
headFinalizedRoot.Set(float64(bytesutil.ToLowInt64(finalizedCpt.Root)))
}
}
}

func reportEpochMetrics(state *stateTrie.BeaconState) {
// ReportEpochMetrics reports epoch related metrics.
func ReportEpochMetrics(state *stateTrie.BeaconState) {
currentEpoch := state.Slot() / params.BeaconConfig().SlotsPerEpoch

// Validator instances
Expand Down

0 comments on commit 8c5c735

Please sign in to comment.