Skip to content

Commit

Permalink
Properly initialize metrics in rpcchainVM
Browse files Browse the repository at this point in the history
Signed-off-by: Yacov Manevich <[email protected]>
  • Loading branch information
yacovm committed Oct 16, 2024
1 parent 814ad2c commit c4d28eb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 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 @@ -87,14 +86,18 @@ type VMServer struct {

// NewServer returns a vm instance connected to a remote vm instance
func NewServer(vm block.ChainVM, allowShutdown *utils.Atomic[bool]) *VMServer {
pluginMetrics := metrics.NewPrefixGatherer()

bVM, _ := vm.(block.BuildBlockWithContextChainVM)
ssVM, _ := vm.(block.StateSyncableVM)
return &VMServer{
vmSrv := &VMServer{
metrics: pluginMetrics,
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 +136,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 +157,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 +171,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 c4d28eb

Please sign in to comment.