Skip to content

Commit

Permalink
moved metrics sub packages types to metrics (#8119)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mh0lt authored Sep 3, 2023
1 parent 5a9f430 commit 8ea0096
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cl/phase1/core/state/lru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

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
Expand Down
11 changes: 5 additions & 6 deletions cl/phase1/core/state/ssz.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package state

import (
"github.com/ledgerwatch/erigon/metrics/methelp"

"github.com/ledgerwatch/erigon-lib/types/clonable"
"github.com/ledgerwatch/erigon/metrics"
)

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)
if err != nil {
return nil, err
}
h.PutSince()
sz := methelp.NewHistTimer("encode_ssz_beacon_state_size")
sz := metrics.NewHistTimer("encode_ssz_beacon_state_size")
sz.Update(float64(len(bts)))
return bts, err
}

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 {
return err
}
sz := methelp.NewHistTimer("decode_ssz_beacon_state_size")
sz := metrics.NewHistTimer("decode_ssz_beacon_state_size")
sz.Update(float64(len(buf)))
h.PutSince()
return b.initBeaconState()
Expand Down
6 changes: 3 additions & 3 deletions cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"time"

"github.com/ledgerwatch/erigon/cl/abstract"
"github.com/ledgerwatch/erigon/metrics"

"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
"github.com/ledgerwatch/erigon/metrics/methelp"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -480,7 +480,7 @@ func (I *impl) VerifyKzgCommitmentsAgainstTransactions(transactions *solid.Trans

func (I *impl) ProcessAttestations(s abstract.BeaconState, attestations *solid.ListSSZ[*solid.Attestation]) error {
attestingIndiciesSet := make([][]uint64, attestations.Len())
h := methelp.NewHistTimer("beacon_process_attestations")
h := metrics.NewHistTimer("beacon_process_attestations")
baseRewardPerIncrement := s.BaseRewardPerIncrement()

c := h.Tag("attestation_step", "process")
Expand Down Expand Up @@ -519,7 +519,7 @@ func processAttestationPostAltair(s abstract.BeaconState, attestation *solid.Att
stateSlot := s.Slot()
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")
participationFlagsIndicies, err := s.GetAttestationParticipationFlagIndicies(attestation.AttestantionData(), stateSlot-data.Slot())
Expand Down
5 changes: 3 additions & 2 deletions cl/transition/machine/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package machine
import (
"errors"
"fmt"

"github.com/ledgerwatch/erigon/cl/abstract"
"github.com/ledgerwatch/erigon/metrics"

"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
"github.com/ledgerwatch/erigon/metrics/methelp"
)

// ProcessBlock processes a block with the block processor
Expand All @@ -19,7 +20,7 @@ func ProcessBlock(impl BlockProcessor, s abstract.BeaconState, signedBlock *clty
if signedBlock.Version() != version {
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.
if err := impl.ProcessBlockHeader(s, block); err != nil {
return fmt.Errorf("processBlock: failed to process block header: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/caplin-regression/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"

"github.com/ledgerwatch/erigon/metrics/exp"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/turbo/debug"

"github.com/ledgerwatch/erigon/cl/cltypes"
Expand Down Expand Up @@ -43,7 +43,7 @@ func main() {
)
if *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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/erigon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"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/pelletier/go-toml"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

"github.com/holiman/uint256"
metrics "github.com/ledgerwatch/erigon/metrics/methelp"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"

Expand Down
4 changes: 2 additions & 2 deletions cmd/sentinel/sentinel/peers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"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/peer"
)
Expand Down Expand Up @@ -120,7 +120,7 @@ func (m *Manager) run(ctx context.Context) {
func (m *Manager) gc() {
m.mu.Lock()
defer m.mu.Unlock()
t := methelp.NewHistTimer("beacon_peer_manager_gc_time")
t := metrics.NewHistTimer("beacon_peer_manager_gc_time")
defer t.PutSince()
deleted := 0
saw := 0
Expand Down
5 changes: 2 additions & 3 deletions consensus/bor/heimdall/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"time"

"github.com/VictoriaMetrics/metrics"
metrics2 "github.com/VictoriaMetrics/metrics"
"github.com/ledgerwatch/erigon/metrics/methelp"
metrics "github.com/ledgerwatch/erigon/metrics/methelp"
)

type (
Expand Down Expand Up @@ -56,7 +55,7 @@ var (
true: metrics.GetOrCreateCounter("client_requests_checkpoint_valid"),
false: metrics.GetOrCreateCounter("client_requests_checkpoint_invalid"),
},
timer: methelp.GetOrCreateSummary("client_requests_checkpoint_duration"),
timer: metrics.GetOrCreateSummary("client_requests_checkpoint_duration"),
},
checkpointCountRequest: {
request: map[bool]*metrics2.Counter{
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"time"

metrics "github.com/ledgerwatch/erigon/metrics/methelp"
"github.com/ledgerwatch/erigon/metrics"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"

Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/all_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/huandu/xstrings"
"github.com/ledgerwatch/erigon-lib/kv"
"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{}
Expand Down
2 changes: 1 addition & 1 deletion metrics/prometheus/collector.go → metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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/>.

package prometheus
package metrics

import (
"bytes"
Expand Down
6 changes: 2 additions & 4 deletions metrics/exp/exp.go → metrics/exp.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Hook go-metrics into expvar
// on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
package exp
package metrics

import (
"fmt"
"net/http"

"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/metrics/prometheus"
"github.com/ledgerwatch/log/v3"
)

Expand All @@ -16,7 +14,7 @@ import (
func Setup(address string, logger log.Logger) *http.ServeMux {
prometheusMux := http.NewServeMux()

prometheusMux.Handle("/debug/metrics/prometheus", prometheus.Handler(metrics.DefaultRegistry))
prometheusMux.Handle("/debug/metrics/prometheus", Handler(DefaultRegistry))

promServer := &http.Server{
Addr: address,
Expand Down
5 changes: 2 additions & 3 deletions metrics/prometheus/prometheus.go → metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
// 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
package metrics

import (
"fmt"
"net/http"
"sort"

metrics2 "github.com/VictoriaMetrics/metrics"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/log/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
)

// 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) {
// Gather and pre-sort the metrics to avoid random listings
var names []string
Expand Down
13 changes: 6 additions & 7 deletions metrics/methelp/register.go → metrics/register.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package methelp
package metrics

import (
metrics2 "github.com/VictoriaMetrics/metrics"
metrics "github.com/ledgerwatch/erigon/metrics"
)

func GetOrCreateCounter(s string, isGauge ...bool) *metrics2.Counter {
counter := metrics2.GetOrCreateCounter(s, isGauge...)
metrics.DefaultRegistry.Register(s, counter)
DefaultRegistry.Register(s, counter)
return counter
}

func GetOrCreateGauge(s string, f func() float64) *metrics2.Gauge {
gauge := metrics2.GetOrCreateGauge(s, f)
metrics.DefaultRegistry.Register(s, gauge)
DefaultRegistry.Register(s, gauge)
return gauge
}

func GetOrCreateFloatCounter(s string) *metrics2.FloatCounter {
floatCounter := metrics2.GetOrCreateFloatCounter(s)
metrics.DefaultRegistry.Register(s, floatCounter)
DefaultRegistry.Register(s, floatCounter)
return floatCounter
}

func GetOrCreateSummary(s string) *metrics2.Summary {
summary := metrics2.GetOrCreateSummary(s)
metrics.DefaultRegistry.Register(s, summary)
DefaultRegistry.Register(s, summary)
return summary
}

func GetOrCreateHistogram(s string) *metrics2.Histogram {
histogram := metrics2.GetOrCreateHistogram(s)
metrics.DefaultRegistry.Register(s, histogram)
DefaultRegistry.Register(s, histogram)
return histogram
}
2 changes: 1 addition & 1 deletion metrics/methelp/timer.go → metrics/timer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package methelp
package metrics

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package p2p
import (
"net"

metrics "github.com/ledgerwatch/erigon/metrics/methelp"
"github.com/ledgerwatch/erigon/metrics"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/ledgerwatch/erigon/common/debug"
"github.com/ledgerwatch/erigon/common/mclock"
"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/enr"
"github.com/ledgerwatch/erigon/rlp"
Expand Down
3 changes: 2 additions & 1 deletion p2p/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package p2p
import (
"bytes"
"errors"
"github.com/ledgerwatch/erigon/rlp"
"reflect"
"sync"
"testing"

"github.com/ledgerwatch/erigon/rlp"

"github.com/davecgh/go-spew/spew"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/p2p/simulations/pipes"
Expand Down
2 changes: 1 addition & 1 deletion rpc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

metrics2 "github.com/VictoriaMetrics/metrics"
metrics "github.com/ledgerwatch/erigon/metrics/methelp"
"github.com/ledgerwatch/erigon/metrics"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions turbo/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

"github.com/ledgerwatch/erigon/common/fdlimit"
"github.com/ledgerwatch/erigon/diagnostics"
"github.com/ledgerwatch/erigon/metrics/exp"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/turbo/logging"
)

Expand Down Expand Up @@ -159,7 +159,7 @@ func SetupCobra(cmd *cobra.Command, filePrefix string) log.Logger {

if metricsEnabled && metricsAddr != "" {
metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort)
metricsMux = exp.Setup(metricsAddress, logger)
metricsMux = metrics.Setup(metricsAddress, logger)
}

if pprof {
Expand Down Expand Up @@ -207,7 +207,7 @@ func Setup(ctx *cli.Context, rootLogger bool) (log.Logger, error) {
if metricsEnabled && (!pprofEnabled || metricsAddr != "") {
metricsPort := ctx.Int(metricsPortFlag.Name)
metricsAddress = fmt.Sprintf("%s:%d", metricsAddr, metricsPort)
metricsMux = exp.Setup(metricsAddress, logger)
metricsMux = metrics.Setup(metricsAddress, logger)
diagnostics.SetupLogsAccess(ctx, metricsMux)
diagnostics.SetupDbAccess(ctx, metricsMux)
diagnostics.SetupCmdLineAccess(metricsMux)
Expand Down
2 changes: 1 addition & 1 deletion turbo/shards/state_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/btree"
"github.com/holiman/uint256"
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/core/types/accounts"
Expand Down

0 comments on commit 8ea0096

Please sign in to comment.