moved metrics sub packages types to metrics (#8119)

This is a non functional change which consolidates the various packages
under metrics into the top level package now that the dead code is
removed.

It is a precursor to the removal of Victoria metrics after which all
erigon metrics code will be contained in this single package.
This commit is contained in:
Mark Holt 2023-09-03 02:09:27 +01:00 committed by GitHub
parent 5a9f430c5a
commit 8ea0096d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 43 additions and 47 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
lru "github.com/hashicorp/golang-lru/v2" lru "github.com/hashicorp/golang-lru/v2"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
) )
// Cache is a wrapper around hashicorp lru but with metric for Get // Cache is a wrapper around hashicorp lru but with metric for Get

View File

@ -1,29 +1,28 @@
package state package state
import ( import (
"github.com/ledgerwatch/erigon/metrics/methelp"
"github.com/ledgerwatch/erigon-lib/types/clonable" "github.com/ledgerwatch/erigon-lib/types/clonable"
"github.com/ledgerwatch/erigon/metrics"
) )
func (b *CachingBeaconState) EncodeSSZ(buf []byte) ([]byte, error) { func (b *CachingBeaconState) EncodeSSZ(buf []byte) ([]byte, error) {
h := methelp.NewHistTimer("encode_ssz_beacon_state_dur") h := metrics.NewHistTimer("encode_ssz_beacon_state_dur")
bts, err := b.BeaconState.EncodeSSZ(buf) bts, err := b.BeaconState.EncodeSSZ(buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
h.PutSince() h.PutSince()
sz := methelp.NewHistTimer("encode_ssz_beacon_state_size") sz := metrics.NewHistTimer("encode_ssz_beacon_state_size")
sz.Update(float64(len(bts))) sz.Update(float64(len(bts)))
return bts, err return bts, err
} }
func (b *CachingBeaconState) DecodeSSZ(buf []byte, version int) error { func (b *CachingBeaconState) DecodeSSZ(buf []byte, version int) error {
h := methelp.NewHistTimer("decode_ssz_beacon_state_dur") h := metrics.NewHistTimer("decode_ssz_beacon_state_dur")
if err := b.BeaconState.DecodeSSZ(buf, version); err != nil { if err := b.BeaconState.DecodeSSZ(buf, version); err != nil {
return err return err
} }
sz := methelp.NewHistTimer("decode_ssz_beacon_state_size") sz := metrics.NewHistTimer("decode_ssz_beacon_state_size")
sz.Update(float64(len(buf))) sz.Update(float64(len(buf)))
h.PutSince() h.PutSince()
return b.initBeaconState() return b.initBeaconState()

View File

@ -8,9 +8,9 @@ import (
"time" "time"
"github.com/ledgerwatch/erigon/cl/abstract" "github.com/ledgerwatch/erigon/cl/abstract"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange" "github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
"github.com/ledgerwatch/erigon/metrics/methelp"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common"
@ -480,7 +480,7 @@ func (I *impl) VerifyKzgCommitmentsAgainstTransactions(transactions *solid.Trans
func (I *impl) ProcessAttestations(s abstract.BeaconState, attestations *solid.ListSSZ[*solid.Attestation]) error { func (I *impl) ProcessAttestations(s abstract.BeaconState, attestations *solid.ListSSZ[*solid.Attestation]) error {
attestingIndiciesSet := make([][]uint64, attestations.Len()) attestingIndiciesSet := make([][]uint64, attestations.Len())
h := methelp.NewHistTimer("beacon_process_attestations") h := metrics.NewHistTimer("beacon_process_attestations")
baseRewardPerIncrement := s.BaseRewardPerIncrement() baseRewardPerIncrement := s.BaseRewardPerIncrement()
c := h.Tag("attestation_step", "process") c := h.Tag("attestation_step", "process")
@ -519,7 +519,7 @@ func processAttestationPostAltair(s abstract.BeaconState, attestation *solid.Att
stateSlot := s.Slot() stateSlot := s.Slot()
beaconConfig := s.BeaconConfig() beaconConfig := s.BeaconConfig()
h := methelp.NewHistTimer("beacon_process_attestation_post_altair") h := metrics.NewHistTimer("beacon_process_attestation_post_altair")
c := h.Tag("step", "get_participation_flag") c := h.Tag("step", "get_participation_flag")
participationFlagsIndicies, err := s.GetAttestationParticipationFlagIndicies(attestation.AttestantionData(), stateSlot-data.Slot()) participationFlagsIndicies, err := s.GetAttestationParticipationFlagIndicies(attestation.AttestantionData(), stateSlot-data.Slot())

View File

@ -3,12 +3,13 @@ package machine
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/ledgerwatch/erigon/cl/abstract" "github.com/ledgerwatch/erigon/cl/abstract"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/cltypes/solid"
"github.com/ledgerwatch/erigon/metrics/methelp"
) )
// ProcessBlock processes a block with the block processor // ProcessBlock processes a block with the block processor
@ -19,7 +20,7 @@ func ProcessBlock(impl BlockProcessor, s abstract.BeaconState, signedBlock *clty
if signedBlock.Version() != version { if signedBlock.Version() != version {
return fmt.Errorf("processBlock: wrong state version for block at slot %d", block.Slot) return fmt.Errorf("processBlock: wrong state version for block at slot %d", block.Slot)
} }
h := methelp.NewHistTimer("beacon_process_block") h := metrics.NewHistTimer("beacon_process_block")
// Process the block header. // Process the block header.
if err := impl.ProcessBlockHeader(s, block); err != nil { if err := impl.ProcessBlockHeader(s, block); err != nil {
return fmt.Errorf("processBlock: failed to process block header: %v", err) return fmt.Errorf("processBlock: failed to process block header: %v", err)

View File

@ -3,7 +3,7 @@ package main
import ( import (
"flag" "flag"
"github.com/ledgerwatch/erigon/metrics/exp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/turbo/debug" "github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes"
@ -43,7 +43,7 @@ func main() {
) )
if *pprof { if *pprof {
// Server for pprof // Server for pprof
debug.StartPProf("localhost:6060", exp.Setup("localhost:6060", log.Root())) debug.StartPProf("localhost:6060", metrics.Setup("localhost:6060", log.Root()))
} }
if err != nil { if err != nil {

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/erigon-lib/common/dbg"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
"github.com/pelletier/go-toml" "github.com/pelletier/go-toml"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"

View File

@ -13,7 +13,7 @@ import (
"time" "time"
"github.com/holiman/uint256" "github.com/holiman/uint256"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru" "github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
"github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
) )
@ -120,7 +120,7 @@ func (m *Manager) run(ctx context.Context) {
func (m *Manager) gc() { func (m *Manager) gc() {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
t := methelp.NewHistTimer("beacon_peer_manager_gc_time") t := metrics.NewHistTimer("beacon_peer_manager_gc_time")
defer t.PutSince() defer t.PutSince()
deleted := 0 deleted := 0
saw := 0 saw := 0

View File

@ -4,9 +4,8 @@ import (
"context" "context"
"time" "time"
"github.com/VictoriaMetrics/metrics"
metrics2 "github.com/VictoriaMetrics/metrics" metrics2 "github.com/VictoriaMetrics/metrics"
"github.com/ledgerwatch/erigon/metrics/methelp"
metrics "github.com/ledgerwatch/erigon/metrics/methelp"
) )
type ( type (
@ -56,7 +55,7 @@ var (
true: metrics.GetOrCreateCounter("client_requests_checkpoint_valid"), true: metrics.GetOrCreateCounter("client_requests_checkpoint_valid"),
false: metrics.GetOrCreateCounter("client_requests_checkpoint_invalid"), false: metrics.GetOrCreateCounter("client_requests_checkpoint_invalid"),
}, },
timer: methelp.GetOrCreateSummary("client_requests_checkpoint_duration"), timer: metrics.GetOrCreateSummary("client_requests_checkpoint_duration"),
}, },
checkpointCountRequest: { checkpointCountRequest: {
request: map[bool]*metrics2.Counter{ request: map[bool]*metrics2.Counter{

View File

@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"time" "time"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"

View File

@ -7,7 +7,7 @@ import (
"github.com/huandu/xstrings" "github.com/huandu/xstrings"
"github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages" "github.com/ledgerwatch/erigon/eth/stagedsync/stages"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
) )
var syncMetrics = map[stages.SyncStage]*metrics2.Counter{} var syncMetrics = map[stages.SyncStage]*metrics2.Counter{}

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package prometheus package metrics
import ( import (
"bytes" "bytes"

View File

@ -1,13 +1,11 @@
// Hook go-metrics into expvar // Hook go-metrics into expvar
// on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler // on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
package exp package metrics
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/metrics/prometheus"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
) )
@ -16,7 +14,7 @@ import (
func Setup(address string, logger log.Logger) *http.ServeMux { func Setup(address string, logger log.Logger) *http.ServeMux {
prometheusMux := http.NewServeMux() prometheusMux := http.NewServeMux()
prometheusMux.Handle("/debug/metrics/prometheus", prometheus.Handler(metrics.DefaultRegistry)) prometheusMux.Handle("/debug/metrics/prometheus", Handler(DefaultRegistry))
promServer := &http.Server{ promServer := &http.Server{
Addr: address, Addr: address,

View File

@ -15,7 +15,7 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package prometheus exposes go-metrics into a Prometheus format. // Package prometheus exposes go-metrics into a Prometheus format.
package prometheus package metrics
import ( import (
"fmt" "fmt"
@ -23,14 +23,13 @@ import (
"sort" "sort"
metrics2 "github.com/VictoriaMetrics/metrics" metrics2 "github.com/VictoriaMetrics/metrics"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
) )
// Handler returns an HTTP handler which dump metrics in Prometheus format. // Handler returns an HTTP handler which dump metrics in Prometheus format.
func Handler(reg metrics.Registry) http.Handler { func Handler(reg Registry) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Gather and pre-sort the metrics to avoid random listings // Gather and pre-sort the metrics to avoid random listings
var names []string var names []string

View File

@ -1,36 +1,35 @@
package methelp package metrics
import ( import (
metrics2 "github.com/VictoriaMetrics/metrics" metrics2 "github.com/VictoriaMetrics/metrics"
metrics "github.com/ledgerwatch/erigon/metrics"
) )
func GetOrCreateCounter(s string, isGauge ...bool) *metrics2.Counter { func GetOrCreateCounter(s string, isGauge ...bool) *metrics2.Counter {
counter := metrics2.GetOrCreateCounter(s, isGauge...) counter := metrics2.GetOrCreateCounter(s, isGauge...)
metrics.DefaultRegistry.Register(s, counter) DefaultRegistry.Register(s, counter)
return counter return counter
} }
func GetOrCreateGauge(s string, f func() float64) *metrics2.Gauge { func GetOrCreateGauge(s string, f func() float64) *metrics2.Gauge {
gauge := metrics2.GetOrCreateGauge(s, f) gauge := metrics2.GetOrCreateGauge(s, f)
metrics.DefaultRegistry.Register(s, gauge) DefaultRegistry.Register(s, gauge)
return gauge return gauge
} }
func GetOrCreateFloatCounter(s string) *metrics2.FloatCounter { func GetOrCreateFloatCounter(s string) *metrics2.FloatCounter {
floatCounter := metrics2.GetOrCreateFloatCounter(s) floatCounter := metrics2.GetOrCreateFloatCounter(s)
metrics.DefaultRegistry.Register(s, floatCounter) DefaultRegistry.Register(s, floatCounter)
return floatCounter return floatCounter
} }
func GetOrCreateSummary(s string) *metrics2.Summary { func GetOrCreateSummary(s string) *metrics2.Summary {
summary := metrics2.GetOrCreateSummary(s) summary := metrics2.GetOrCreateSummary(s)
metrics.DefaultRegistry.Register(s, summary) DefaultRegistry.Register(s, summary)
return summary return summary
} }
func GetOrCreateHistogram(s string) *metrics2.Histogram { func GetOrCreateHistogram(s string) *metrics2.Histogram {
histogram := metrics2.GetOrCreateHistogram(s) histogram := metrics2.GetOrCreateHistogram(s)
metrics.DefaultRegistry.Register(s, histogram) DefaultRegistry.Register(s, histogram)
return histogram return histogram
} }

View File

@ -1,4 +1,4 @@
package methelp package metrics
import ( import (
"fmt" "fmt"

View File

@ -21,7 +21,7 @@ package p2p
import ( import (
"net" "net"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
) )
const ( const (

View File

@ -30,7 +30,7 @@ import (
"github.com/ledgerwatch/erigon/common/debug" "github.com/ledgerwatch/erigon/common/debug"
"github.com/ledgerwatch/erigon/common/mclock" "github.com/ledgerwatch/erigon/common/mclock"
"github.com/ledgerwatch/erigon/event" "github.com/ledgerwatch/erigon/event"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/p2p/enode" "github.com/ledgerwatch/erigon/p2p/enode"
"github.com/ledgerwatch/erigon/p2p/enr" "github.com/ledgerwatch/erigon/p2p/enr"
"github.com/ledgerwatch/erigon/rlp" "github.com/ledgerwatch/erigon/rlp"

View File

@ -19,11 +19,12 @@ package p2p
import ( import (
"bytes" "bytes"
"errors" "errors"
"github.com/ledgerwatch/erigon/rlp"
"reflect" "reflect"
"sync" "sync"
"testing" "testing"
"github.com/ledgerwatch/erigon/rlp"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/p2p/simulations/pipes" "github.com/ledgerwatch/erigon/p2p/simulations/pipes"

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
metrics2 "github.com/VictoriaMetrics/metrics" metrics2 "github.com/VictoriaMetrics/metrics"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
) )
var ( var (

View File

@ -32,7 +32,7 @@ import (
"github.com/ledgerwatch/erigon/common/fdlimit" "github.com/ledgerwatch/erigon/common/fdlimit"
"github.com/ledgerwatch/erigon/diagnostics" "github.com/ledgerwatch/erigon/diagnostics"
"github.com/ledgerwatch/erigon/metrics/exp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/turbo/logging" "github.com/ledgerwatch/erigon/turbo/logging"
) )
@ -159,7 +159,7 @@ func SetupCobra(cmd *cobra.Command, filePrefix string) log.Logger {
if metricsEnabled && metricsAddr != "" { if metricsEnabled && metricsAddr != "" {
metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort) metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort)
metricsMux = exp.Setup(metricsAddress, logger) metricsMux = metrics.Setup(metricsAddress, logger)
} }
if pprof { if pprof {
@ -207,7 +207,7 @@ func Setup(ctx *cli.Context, rootLogger bool) (log.Logger, error) {
if metricsEnabled && (!pprofEnabled || metricsAddr != "") { if metricsEnabled && (!pprofEnabled || metricsAddr != "") {
metricsPort := ctx.Int(metricsPortFlag.Name) metricsPort := ctx.Int(metricsPortFlag.Name)
metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort) metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort)
metricsMux = exp.Setup(metricsAddress, logger) metricsMux = metrics.Setup(metricsAddress, logger)
diagnostics.SetupLogsAccess(ctx, metricsMux) diagnostics.SetupLogsAccess(ctx, metricsMux)
diagnostics.SetupDbAccess(ctx, metricsMux) diagnostics.SetupDbAccess(ctx, metricsMux)
diagnostics.SetupCmdLineAccess(metricsMux) diagnostics.SetupCmdLineAccess(metricsMux)

View File

@ -10,7 +10,7 @@ import (
"github.com/google/btree" "github.com/google/btree"
"github.com/holiman/uint256" "github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common"
metrics "github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/types/accounts" "github.com/ledgerwatch/erigon/core/types/accounts"