Skip to content

Commit

Permalink
Register VM and snowman metrics after chain creation (#3489)
Browse files Browse the repository at this point in the history
Signed-off-by: Yacov Manevich <[email protected]>
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
yacovm and StephenButtolph authored Oct 24, 2024
1 parent 05295f0 commit 993d169
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api/health"
Expand Down Expand Up @@ -490,19 +491,6 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
return nil, fmt.Errorf("error while creating chain's log %w", err)
}

snowmanMetrics, err := metrics.MakeAndRegister(
m.snowmanGatherer,
primaryAlias,
)
if err != nil {
return nil, err
}

vmMetrics, err := m.getOrMakeVMRegisterer(chainParams.VMID, primaryAlias)
if err != nil {
return nil, err
}

ctx := &snow.ConsensusContext{
Context: &snow.Context{
NetworkID: m.NetworkID,
Expand All @@ -520,15 +508,15 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
Keystore: m.Keystore.NewBlockchainKeyStore(chainParams.ID),
SharedMemory: m.AtomicMemory.NewSharedMemory(chainParams.ID),
BCLookup: m,
Metrics: vmMetrics,
Metrics: metrics.NewPrefixGatherer(),

WarpSigner: warp.NewSigner(m.StakingBLSKey, m.NetworkID, chainParams.ID),

ValidatorState: m.validatorState,
ChainDataDir: chainDataDir,
},
PrimaryAlias: primaryAlias,
Registerer: snowmanMetrics,
Registerer: prometheus.NewRegistry(),
BlockAcceptor: m.BlockAcceptorGroup,
TxAcceptor: m.TxAcceptorGroup,
VertexAcceptor: m.VertexAcceptorGroup,
Expand Down Expand Up @@ -601,7 +589,15 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
return nil, err
}

return chain, nil
vmGatherer, err := m.getOrMakeVMGatherer(chainParams.VMID)
if err != nil {
return nil, err
}

return chain, errors.Join(
m.snowmanGatherer.Register(primaryAlias, ctx.Registerer),
vmGatherer.Register(primaryAlias, ctx.Metrics),
)
}

func (m *manager) AddRegistrant(r Registrant) {
Expand Down Expand Up @@ -1556,26 +1552,22 @@ func (m *manager) getChainConfig(id ids.ID) (ChainConfig, error) {
return ChainConfig{}, nil
}

func (m *manager) getOrMakeVMRegisterer(vmID ids.ID, chainAlias string) (metrics.MultiGatherer, error) {
func (m *manager) getOrMakeVMGatherer(vmID ids.ID) (metrics.MultiGatherer, error) {
vmGatherer, ok := m.vmGatherer[vmID]
if !ok {
vmName := constants.VMName(vmID)
vmNamespace := metric.AppendNamespace(constants.PlatformName, vmName)
vmGatherer = metrics.NewLabelGatherer(ChainLabel)
err := m.Metrics.Register(
vmNamespace,
vmGatherer,
)
if err != nil {
return nil, err
}
m.vmGatherer[vmID] = vmGatherer
if ok {
return vmGatherer, nil
}

chainReg := metrics.NewPrefixGatherer()
err := vmGatherer.Register(
chainAlias,
chainReg,
vmName := constants.VMName(vmID)
vmNamespace := metric.AppendNamespace(constants.PlatformName, vmName)
vmGatherer = metrics.NewLabelGatherer(ChainLabel)
err := m.Metrics.Register(
vmNamespace,
vmGatherer,
)
return chainReg, err
if err != nil {
return nil, err
}
m.vmGatherer[vmID] = vmGatherer
return vmGatherer, nil
}

0 comments on commit 993d169

Please sign in to comment.