diff --git a/cmd/termui/view/termuic/termuiRenders/widgetsRender.go b/cmd/termui/view/termuic/termuiRenders/widgetsRender.go index aa54480274f..56f40c9c5f2 100644 --- a/cmd/termui/view/termuic/termuiRenders/widgetsRender.go +++ b/cmd/termui/view/termuic/termuiRenders/widgetsRender.go @@ -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() @@ -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, ), } diff --git a/facade/initial/initialStatusMetricsProvider.go b/facade/initial/initialStatusMetricsProvider.go index 94443d4bb41..b311c44b3a1 100644 --- a/facade/initial/initialStatusMetricsProvider.go +++ b/facade/initial/initialStatusMetricsProvider.go @@ -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 diff --git a/facade/initial/initialStatusMetricsProvider_test.go b/facade/initial/initialStatusMetricsProvider_test.go index 31c9a68eb2f..801ce6108ff 100644 --- a/facade/initial/initialStatusMetricsProvider_test.go +++ b/facade/initial/initialStatusMetricsProvider_test.go @@ -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) diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 2b631c7f239..d1ebbd873fc 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -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)) + + return nil +} + // InitMetrics will init metrics for status handler func InitMetrics( appStatusHandler core.AppStatusHandler, diff --git a/node/nodeRunner.go b/node/nodeRunner.go index 73f37114f61..b8a1f697139 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -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, @@ -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) @@ -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 }