Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove optional gatherer #3052

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/metrics/multi_gatherer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package metrics

import (
"errors"
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"

dto "github.com/prometheus/client_model/go"
Expand All @@ -25,7 +27,7 @@ func TestMultiGathererDuplicatedPrefix(t *testing.T) {
require := require.New(t)

g := NewMultiGatherer()
og := NewOptionalGatherer()
og := prometheus.NewRegistry()

require.NoError(g.Register("", og))

Expand All @@ -40,6 +42,7 @@ func TestMultiGathererAddedError(t *testing.T) {

g := NewMultiGatherer()

errTest := errors.New("non-nil error")
tg := &testGatherer{
err: errTest,
}
Expand Down
61 changes: 0 additions & 61 deletions api/metrics/optional_gatherer.go

This file was deleted.

71 changes: 0 additions & 71 deletions api/metrics/optional_gatherer_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion chains/linearizable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type initializeOnLinearizeVM struct {
vmToInitialize common.VM
vmToLinearize *linearizeOnInitializeVM

registerer metrics.OptionalGatherer
registerer metrics.MultiGatherer
ctx *snow.Context
db database.Database
genesisBytes []byte
Expand Down
15 changes: 5 additions & 10 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
return nil, fmt.Errorf("error while registering DAG metrics %w", err)
}

vmMetrics := metrics.NewOptionalGatherer()
vmMetrics := metrics.NewMultiGatherer()
vmNamespace := metric.AppendNamespace(chainNamespace, "vm")
if err := m.Metrics.Register(vmNamespace, vmMetrics); err != nil {
return nil, fmt.Errorf("error while registering vm's metrics %w", err)
Expand Down Expand Up @@ -642,17 +642,12 @@ func (m *manager) createAvalancheChain(
},
)

avalancheRegisterer := metrics.NewOptionalGatherer()
snowmanRegisterer := metrics.NewOptionalGatherer()

registerer := metrics.NewMultiGatherer()
if err := registerer.Register("avalanche", avalancheRegisterer); err != nil {
return nil, err
}
if err := registerer.Register("", snowmanRegisterer); err != nil {
avalancheRegisterer := metrics.NewMultiGatherer()
snowmanRegisterer := metrics.NewMultiGatherer()
if err := ctx.Context.Metrics.Register("avalanche", avalancheRegisterer); err != nil {
return nil, err
}
if err := ctx.Context.Metrics.Register(registerer); err != nil {
if err := ctx.Context.Metrics.Register("", snowmanRegisterer); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go 1.21.10
require (
github.com/DataDog/zstd v1.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/ava-labs/coreth v0.13.4-rc.0
github.com/ava-labs/coreth v0.13.5-remove-optional-gatherer.2
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.13.4-rc.0 h1:UU7SOlLVeviT59Y+FyDyrdt0Wvl+SOj0EyET8ZtH1ZY=
github.com/ava-labs/coreth v0.13.4-rc.0/go.mod h1:mP1QRzaQKq+y+bqyx3xMR3/K/+TpjHbPJi+revI6Y38=
github.com/ava-labs/coreth v0.13.5-remove-optional-gatherer.2 h1:RX9DcvgWxq42B2aiGzk77Y8w2bcB7ApO/Cdj9hA6QoE=
github.com/ava-labs/coreth v0.13.5-remove-optional-gatherer.2/go.mod h1:cm5c12xo5NiTgtbmeduv8i2nYdzgkczz9Wm3yiwwTRU=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
2 changes: 1 addition & 1 deletion snow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Context struct {
Keystore keystore.BlockchainKeystore
SharedMemory atomic.SharedMemory
BCLookup ids.AliaserReader
Metrics metrics.OptionalGatherer
Metrics metrics.MultiGatherer

WarpSigner warp.Signer

Expand Down
2 changes: 1 addition & 1 deletion snow/snowtest/snowtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func Context(tb testing.TB, chainID ids.ID) *snow.Context {

Log: logging.NoLog{},
BCLookup: aliaser,
Metrics: metrics.NewOptionalGatherer(),
Metrics: metrics.NewMultiGatherer(),

ValidatorState: validatorState,
ChainDataDir: "",
Expand Down
2 changes: 1 addition & 1 deletion vms/avm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (vm *VM) Initialize(
)

registerer := prometheus.NewRegistry()
if err := ctx.Metrics.Register(registerer); err != nil {
if err := ctx.Metrics.Register("", registerer); err != nil {
return err
}
vm.registerer = registerer
Expand Down
10 changes: 3 additions & 7 deletions vms/metervm/block_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,14 @@ func (vm *blockVM) Initialize(
return err
}

optionalGatherer := metrics.NewOptionalGatherer()
multiGatherer := metrics.NewMultiGatherer()
if err := multiGatherer.Register("metervm", registerer); err != nil {
if err := chainCtx.Metrics.Register("metervm", registerer); err != nil {
return err
}
if err := multiGatherer.Register("", optionalGatherer); err != nil {
if err := chainCtx.Metrics.Register("", multiGatherer); err != nil {
return err
}
if err := chainCtx.Metrics.Register(multiGatherer); err != nil {
return err
}
chainCtx.Metrics = optionalGatherer
chainCtx.Metrics = multiGatherer

return vm.ChainVM.Initialize(ctx, chainCtx, db, genesisBytes, upgradeBytes, configBytes, toEngine, fxs, appSender)
}
Expand Down
10 changes: 3 additions & 7 deletions vms/metervm/vertex_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ func (vm *vertexVM) Initialize(
return err
}

optionalGatherer := metrics.NewOptionalGatherer()
multiGatherer := metrics.NewMultiGatherer()
if err := multiGatherer.Register("metervm", registerer); err != nil {
if err := chainCtx.Metrics.Register("metervm", registerer); err != nil {
return err
}
if err := multiGatherer.Register("", optionalGatherer); err != nil {
if err := chainCtx.Metrics.Register("", multiGatherer); err != nil {
return err
}
if err := chainCtx.Metrics.Register(multiGatherer); err != nil {
return err
}
chainCtx.Metrics = optionalGatherer
chainCtx.Metrics = multiGatherer

return vm.LinearizableVMWithEngine.Initialize(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (vm *VM) Initialize(
chainCtx.Log.Info("using VM execution config", zap.Reflect("config", execConfig))

registerer := prometheus.NewRegistry()
if err := chainCtx.Metrics.Register(registerer); err != nil {
if err := chainCtx.Metrics.Register("", registerer); err != nil {
return err
}

Expand Down
13 changes: 4 additions & 9 deletions vms/proposervm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,15 @@ func (vm *VM) Initialize(
) error {
// TODO: Add a helper for this metrics override, it is performed in multiple
// places.
multiGatherer := metrics.NewMultiGatherer()
registerer := prometheus.NewRegistry()
if err := multiGatherer.Register("proposervm", registerer); err != nil {
if err := chainCtx.Metrics.Register("proposervm", registerer); err != nil {
return err
}

optionalGatherer := metrics.NewOptionalGatherer()
if err := multiGatherer.Register("", optionalGatherer); err != nil {
return err
}
if err := chainCtx.Metrics.Register(multiGatherer); err != nil {
multiGatherer := metrics.NewMultiGatherer()
if err := chainCtx.Metrics.Register("", multiGatherer); err != nil {
return err
}
chainCtx.Metrics = optionalGatherer
chainCtx.Metrics = multiGatherer

vm.ctx = chainCtx
vm.db = versiondb.New(prefixdb.New(dbPrefix, db))
Expand Down
15 changes: 4 additions & 11 deletions vms/rpcchainvm/vm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"github.com/ava-labs/avalanchego/api/keystore/gkeystore"
"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/rpcdb"
Expand Down Expand Up @@ -137,15 +136,14 @@ func (vm *VMClient) Initialize(

// Register metrics
registerer := prometheus.NewRegistry()
multiGatherer := metrics.NewMultiGatherer()
vm.grpcServerMetrics = grpc_prometheus.NewServerMetrics()
if err := registerer.Register(vm.grpcServerMetrics); err != nil {
return err
}
if err := multiGatherer.Register("rpcchainvm", registerer); err != nil {
if err := chainCtx.Metrics.Register("rpcchainvm", registerer); err != nil {
return err
}
if err := multiGatherer.Register("", vm); err != nil {
if err := chainCtx.Metrics.Register("", vm); err != nil {
return err
}

Expand Down Expand Up @@ -226,7 +224,7 @@ func (vm *VMClient) Initialize(
time: time,
}

chainState, err := chain.NewMeteredState(
vm.State, err = chain.NewMeteredState(
registerer,
&chain.Config{
DecidedCacheSize: decidedCacheSize,
Expand All @@ -241,12 +239,7 @@ func (vm *VMClient) Initialize(
BuildBlockWithContext: vm.buildBlockWithContext,
},
)
if err != nil {
return err
}
vm.State = chainState

return chainCtx.Metrics.Register(multiGatherer)
return err
}

func (vm *VMClient) newDBServer(db database.Database) *grpc.Server {
Expand Down
2 changes: 1 addition & 1 deletion vms/rpcchainvm/vm_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
Keystore: keystoreClient,
SharedMemory: sharedMemoryClient,
BCLookup: bcLookupClient,
Metrics: metrics.NewOptionalGatherer(),
Metrics: metrics.NewMultiGatherer(),

// Signs warp messages
WarpSigner: warpSignerClient,
Expand Down
Loading