Skip to content

Commit

Permalink
Properly initialize metrics in rpcchainVM (#3477)
Browse files Browse the repository at this point in the history
Signed-off-by: Yacov Manevich <[email protected]>
  • Loading branch information
yacovm authored Oct 16, 2024
1 parent 3f202a5 commit d81292a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vms/rpcchainvm/vm_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"google.golang.org/protobuf/types/known/emptypb"

Expand Down Expand Up @@ -74,7 +73,7 @@ type VMServer struct {

allowShutdown *utils.Atomic[bool]

metrics prometheus.Gatherer
metrics metrics.MultiGatherer
db database.Database
log logging.Logger

Expand All @@ -89,12 +88,14 @@ type VMServer struct {
func NewServer(vm block.ChainVM, allowShutdown *utils.Atomic[bool]) *VMServer {
bVM, _ := vm.(block.BuildBlockWithContextChainVM)
ssVM, _ := vm.(block.StateSyncableVM)
return &VMServer{
vmSrv := &VMServer{
metrics: metrics.NewPrefixGatherer(),
vm: vm,
bVM: bVM,
ssVM: ssVM,
allowShutdown: allowShutdown,
}
return vmSrv
}

func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) (*vmpb.InitializeResponse, error) {
Expand Down Expand Up @@ -133,11 +134,8 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
return nil, err
}

pluginMetrics := metrics.NewPrefixGatherer()
vm.metrics = pluginMetrics

processMetrics, err := metrics.MakeAndRegister(
pluginMetrics,
vm.metrics,
"process",
)
if err != nil {
Expand All @@ -157,7 +155,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
}

grpcMetrics, err := metrics.MakeAndRegister(
pluginMetrics,
vm.metrics,
"grpc",
)
if err != nil {
Expand All @@ -171,7 +169,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
}

vmMetrics := metrics.NewPrefixGatherer()
if err := pluginMetrics.Register("vm", vmMetrics); err != nil {
if err := vm.metrics.Register("vm", vmMetrics); err != nil {
return nil, err
}

Expand Down

0 comments on commit d81292a

Please sign in to comment.