Skip to content
Open
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
32 changes: 26 additions & 6 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,36 @@ func (wr *WidgetsRender) RefreshData(numMillisecondsRefreshTime int) {
wr.prepareLoads()
}

func (wr *WidgetsRender) getShardIdStr() string {
currentRound := wr.presenter.GetCurrentRound()
nodesProcessed := wr.presenter.GetTrieSyncNumProcessedNodes()
isNodeSyncingTrie := nodesProcessed != 0

synchronizedRound := wr.presenter.GetSynchronizedRound()
isRoundNotSynchronized := synchronizedRound < currentRound

isNodeSyncing := isNodeSyncingTrie || isRoundNotSynchronized || currentRound == 0

if isNodeSyncing {
return "N/A"
}

shardID := wr.presenter.GetShardId()

shardIdStr := fmt.Sprintf("%d", shardID)
if shardID == uint64(core.MetachainShardId) {
shardIdStr = "meta"
}

return shardIdStr
}

func (wr *WidgetsRender) prepareInstanceInfo() {
// 8 rows and one column
numRows := 8
rows := make([][]string, numRows)

nodeName := wr.presenter.GetNodeName()
shardId := wr.presenter.GetShardId()
instanceType := wr.presenter.GetNodeType()
peerType := wr.presenter.GetPeerType()
peerSubType := wr.presenter.GetPeerSubType()
Expand All @@ -139,15 +162,12 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
if peerSubType == core.FullHistoryObserver.String() {
nodeTypeAndListDisplay += " - full archive"
}
shardIdStr := fmt.Sprintf("%d", shardId)
if shardId == uint64(core.MetachainShardId) {
shardIdStr = "meta"
}

wr.instanceInfo.RowStyles[0] = ui.NewStyle(ui.ColorYellow)
rows[0] = []string{
fmt.Sprintf("Node name: %s (Shard %s - %s)",
nodeName,
shardIdStr,
wr.getShardIdStr(),
nodeTypeAndListDisplay,
),
}
Expand Down
2 changes: 1 addition & 1 deletion facade/initial/initialStatusMetricsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (provider *initialStatusMetricsProvider) BootstrapMetrics() (map[string]int

// StatusMetricsMapWithoutP2P returns an empty map and the error which specifies that the node is starting
func (provider *initialStatusMetricsProvider) StatusMetricsMapWithoutP2P() (map[string]interface{}, error) {
return getEmptyReturnValues()
return provider.realStatusMetricsProvider.StatusMetricsMapWithoutP2P()
}

// StatusP2pMetricsMap returns an empty map and the error which specifies that the node is starting
Expand Down
1 change: 0 additions & 1 deletion facade/initial/initialStatusMetricsProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestNewInitialStatusMetricsProvider(t *testing.T) {
assert.Nil(t, err)
assert.False(t, check.IfNil(provider))

testDisabledGetter(t, provider.StatusMetricsMapWithoutP2P)
testDisabledGetter(t, provider.StatusP2pMetricsMap)
testDisabledGetter(t, provider.EconomicsMetrics)
testDisabledGetter(t, provider.ConfigMetrics)
Expand Down
47 changes: 47 additions & 0 deletions node/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,53 @@ func InitRatingsMetrics(appStatusHandler core.AppStatusHandler, ratingsConfig co
return nil
}

// InitInitialMetrics will set initial metrics for status handler (before bootstrapping process is completed)
func InitInitialMetrics(
appStatusHandler core.AppStatusHandler,
pubkeyStr string,
nodesConfig sharding.GenesisNodesSetupHandler,
version string,
economicsConfig *config.EconomicsConfig,
minTransactionVersion uint32,
) error {
if check.IfNil(appStatusHandler) {
return ErrNilAppStatusHandler
}
if nodesConfig == nil {
return fmt.Errorf("nil nodes config when initializing metrics")
}
if economicsConfig == nil {
return fmt.Errorf("nil economics config when initializing metrics")
}

isSyncing := uint64(1)

leaderPercentage := float64(0)
rewardsConfigs := make([]config.EpochRewardSettings, len(economicsConfig.RewardsSettings.RewardsConfigByEpoch))
_ = copy(rewardsConfigs, economicsConfig.RewardsSettings.RewardsConfigByEpoch)

sort.Slice(rewardsConfigs, func(i, j int) bool {
return rewardsConfigs[i].EpochEnable < rewardsConfigs[j].EpochEnable
})

if len(rewardsConfigs) > 0 {
leaderPercentage = rewardsConfigs[0].LeaderPercentage
}

appStatusHandler.SetStringValue(common.MetricPublicKeyBlockSign, pubkeyStr)
appStatusHandler.SetStringValue(common.MetricAppVersion, version)
appStatusHandler.SetStringValue(common.MetricCrossCheckBlockHeight, "0")
appStatusHandler.SetUInt64Value(common.MetricCrossCheckBlockHeightMeta, 0)
appStatusHandler.SetUInt64Value(common.MetricIsSyncing, isSyncing)
appStatusHandler.SetStringValue(common.MetricLeaderPercentage, fmt.Sprintf("%f", leaderPercentage))
appStatusHandler.SetUInt64Value(common.MetricDenomination, uint64(economicsConfig.GlobalSettings.Denomination))

appStatusHandler.SetUInt64Value(common.MetricStartTime, uint64(nodesConfig.GetStartTime()))
appStatusHandler.SetUInt64Value(common.MetricMinTransactionVersion, uint64(minTransactionVersion))
Comment on lines +311 to +320
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these set of metrics will be overwritten after bootstrap is finished


return nil
}

// InitMetrics will init metrics for status handler
func InitMetrics(
appStatusHandler core.AppStatusHandler,
Expand Down
61 changes: 48 additions & 13 deletions node/nodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ func (nr *nodeRunner) executeOneComponentCreationCycle(
return true, err
}

log.Debug("creating metrics before bootstrap")
err = nr.createMetricsBeforeBootrapping(managedStatusCoreComponents, managedCoreComponents, managedCryptoComponents)
if err != nil {
return true, err
}

log.Debug("creating bootstrap components")
managedBootstrapComponents, err := nr.CreateManagedBootstrapComponents(
managedStatusCoreComponents,
Expand Down Expand Up @@ -828,34 +834,32 @@ func (nr *nodeRunner) createHttpServer(managedStatusCoreComponents mainFactory.S
return httpServerWrapper, nil
}

func (nr *nodeRunner) createMetrics(
func (nr *nodeRunner) createMetricsBeforeBootrapping(
statusCoreComponents mainFactory.StatusCoreComponentsHolder,
coreComponents mainFactory.CoreComponentsHolder,
cryptoComponents mainFactory.CryptoComponentsHolder,
bootstrapComponents mainFactory.BootstrapComponentsHolder,
) error {

chainParameters, err := coreComponents.ChainParametersHandler().ChainParametersForEpoch(bootstrapComponents.EpochBootstrapParams().Epoch())
if err != nil {
return err
}

err = metrics.InitMetrics(
err := metrics.InitInitialMetrics(
statusCoreComponents.AppStatusHandler(),
cryptoComponents.PublicKeyString(),
bootstrapComponents.NodeType(),
bootstrapComponents.ShardCoordinator(),
coreComponents.GenesisNodesSetup(),
nr.configs.FlagsConfig.Version,
nr.configs.EconomicsConfig,
chainParameters,
coreComponents.MinTransactionVersion(),
)

if err != nil {
return err
}

nr.setMetricsAtInit(statusCoreComponents, coreComponents)

return nil
}

func (nr *nodeRunner) setMetricsAtInit(
statusCoreComponents mainFactory.StatusCoreComponentsHolder,
coreComponents mainFactory.CoreComponentsHolder,
) {
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricNodeDisplayName, nr.configs.PreferencesConfig.Preferences.NodeDisplayName)
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricRedundancyLevel, fmt.Sprintf("%d", nr.configs.PreferencesConfig.Preferences.RedundancyLevel))
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricRedundancyIsMainActive, common.MetricValueNA)
Expand All @@ -874,6 +878,37 @@ func (nr *nodeRunner) createMetrics(
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricPeerType, core.ObserverPeer.String())
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricPeerSubType, core.FullHistoryObserver.String())
}
}

func (nr *nodeRunner) createMetrics(
statusCoreComponents mainFactory.StatusCoreComponentsHolder,
coreComponents mainFactory.CoreComponentsHolder,
cryptoComponents mainFactory.CryptoComponentsHolder,
bootstrapComponents mainFactory.BootstrapComponentsHolder,
) error {

chainParameters, err := coreComponents.ChainParametersHandler().ChainParametersForEpoch(bootstrapComponents.EpochBootstrapParams().Epoch())
if err != nil {
return err
}

err = metrics.InitMetrics(
statusCoreComponents.AppStatusHandler(),
cryptoComponents.PublicKeyString(),
bootstrapComponents.NodeType(),
bootstrapComponents.ShardCoordinator(),
coreComponents.GenesisNodesSetup(),
nr.configs.FlagsConfig.Version,
nr.configs.EconomicsConfig,
chainParameters,
coreComponents.MinTransactionVersion(),
)

if err != nil {
return err
}

nr.setMetricsAtInit(statusCoreComponents, coreComponents)

return nil
}
Expand Down
Loading