Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

En 3563 update term ui #373

Merged
merged 57 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f484c68
EN-3395 : Create a new branch for termui console implementation, star…
miiu96 Aug 7, 2019
cc8397e
EN-3395 : add more fields in termui console, add some setters to get …
miiu96 Aug 9, 2019
b71a66e
EN-3395 : add feature with big log display, fix unit tests that fails
miiu96 Aug 9, 2019
5b8a1b0
EN-3395 : add event when CTRl+c is pressed, add some unit tests, retu…
miiu96 Aug 9, 2019
ad59337
EN-3395 : fix failing tests
miiu96 Aug 9, 2019
28b3aaa
EN-3395 : renamed, and fixed some encapsulation problem
miiu96 Aug 9, 2019
313d96e
EN-3395 : modify structure of termui console
miiu96 Aug 9, 2019
4b82e47
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 9, 2019
9d5654d
Merge branch 'development' into EN-3395-termui-console
sasurobert Aug 9, 2019
abd4294
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 11, 2019
a74a017
Merge branch 'development' into EN-3395-termui-console
raduchis Aug 12, 2019
357f8d8
EN-3395 : fix after review not done yet
miiu96 Aug 12, 2019
52c464b
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 12, 2019
735de0c
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 12, 2019
85f3318
Fixed termui on windows
Aug 12, 2019
c6f10c6
Merge remote-tracking branch 'origin/EN-3395-termui-console' into EN-…
Aug 12, 2019
c689c98
Merge branch 'development' into EN-3395-termui-console
bogdan-rosianu Aug 12, 2019
70ef87f
EN-3395 :continue to fix after review, modify failing tests
miiu96 Aug 12, 2019
b8c3610
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 12, 2019
0919044
Merge remote-tracking branch 'origin/EN-3395-termui-console' into EN-…
miiu96 Aug 12, 2019
f566f82
EN-3395 :fix after review, add more unit test, fix failing tests
miiu96 Aug 13, 2019
0d71a5c
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 13, 2019
5caca02
EN-3395 :fix after review
miiu96 Aug 13, 2019
0a2a128
Merge branch 'development' into EN-3395-termui-console
miiu96 Aug 13, 2019
84f58eb
EN-3395 :fix after review
miiu96 Aug 13, 2019
dbfe388
Fixed termui on windows
Aug 13, 2019
3f2b04d
Fixed termui on windows
Aug 13, 2019
9bb0a93
added more metrics in app status handler
iulianpascalau Aug 13, 2019
a0f44e9
Merge branch 'EN-3395-termui-console' of https://github.com/ElrondNet…
iulianpascalau Aug 13, 2019
59fffb0
fix after merge, reverted changes
iulianpascalau Aug 13, 2019
806b31f
added for in go funcs in machineStatistics
iulianpascalau Aug 13, 2019
8be5155
Fixed termui on windows
Aug 13, 2019
d050429
refactored network gauge
iulianpascalau Aug 14, 2019
95fdf8c
Fixed Uint64 and Int64
Aug 14, 2019
8eb34c7
removed machineStatistics.go file
iulianpascalau Aug 14, 2019
49e575a
Merge branch 'EN-3395-termui-console' of https://github.com/ElrondNet…
iulianpascalau Aug 14, 2019
63a0e61
minor code changes: removed unused or faulty used mocks, updated test…
iulianpascalau Aug 14, 2019
3165bbe
Merge branch 'development' into EN-3395-termui-console
camilbancioiu Aug 14, 2019
8d39713
Split PrettyBlock after \n for logging
Aug 14, 2019
c837840
fixed log lines
iulianpascalau Aug 14, 2019
97fcd11
widgetsRender refactor
Aug 14, 2019
35be230
Merge branch 'development' into EN-3395-termui-console
iulianpascalau Aug 14, 2019
8bdf6d8
Updated status
Aug 14, 2019
e1b56a6
Merge remote-tracking branch 'origin/EN-3395-termui-console' into EN-…
Aug 14, 2019
c9f4685
fixed getting sync status
iulianpascalau Aug 14, 2019
4ee7ca5
fix after review
Aug 14, 2019
2b6ebcc
Merge remote-tracking branch 'origin/EN-3395-termui-console' into EN-…
Aug 14, 2019
8c74de7
Merge branch 'development' into EN-3395-termui-console
camilbancioiu Aug 14, 2019
26be12b
fixed build
Aug 14, 2019
323e63a
Merge branch 'EN-3395-termui-console' of https://github.com/ElrondNet…
Aug 14, 2019
29a9a6c
fix after review, added interface is nil func on appStatusHandler
iulianpascalau Aug 14, 2019
47dbd83
Merge branch 'EN-3395-termui-console' of https://github.com/ElrondNet…
iulianpascalau Aug 14, 2019
305b91c
updated gin to start in debug mode only if termui is not enabled
iulianpascalau Aug 14, 2019
9cd3287
Merge branch 'development' into EN-3563-update-term-ui
iulianpascalau Aug 14, 2019
1f15605
Merge branch 'development' into EN-3563-update-term-ui
camilbancioiu Aug 14, 2019
c45c840
minor code changes: renamed bool flag from elrond facade
iulianpascalau Aug 14, 2019
0295f50
Merge branch 'EN-3563-update-term-ui' of https://github.com/ElrondNet…
iulianpascalau Aug 14, 2019
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
10 changes: 9 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type prometheus struct {
// MainApiHandler interface defines methods that can be used from `elrondFacade` context variable
type MainApiHandler interface {
RestApiPort() string
GinDebugMode() bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Could rename Gin to RestAPIServer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

PprofEnabled() bool
PrometheusMonitoring() bool
PrometheusJoinURL() string
Expand All @@ -41,7 +42,14 @@ type MainApiHandler interface {

// Start will boot up the api and appropriate routes, handlers and validators
func Start(elrondFacade MainApiHandler) error {
ws := gin.Default()
var ws *gin.Engine
if elrondFacade.GinDebugMode() {
ws = gin.Default()
} else {
ws = gin.New()
ws.Use(gin.Recovery())
gin.SetMode(gin.ReleaseMode)
}
ws.Use(cors.Default())

err := registerValidators()
Expand Down
5 changes: 3 additions & 2 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ var coreServiceContainer serviceContainer.Core
// windows:
// for /f %i in ('git describe --tags --long --dirty') do set VERS=%i
// go build -i -v -ldflags="-X main.appVersion=%VERS%"
var appVersion = "undefined"
var appVersion = core.UnVersionedAppString

func main() {
log := logger.DefaultLogger()
Expand Down Expand Up @@ -529,6 +529,7 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
coreComponents.StatusHandler.SetUInt64Value(core.MetricShardId, uint64(shardCoordinator.SelfId()))
coreComponents.StatusHandler.SetStringValue(core.MetricNodeType, string(nodeType))
coreComponents.StatusHandler.SetUInt64Value(core.MetricRoundTime, nodesConfig.RoundDuration/milisecondsInSecond)
coreComponents.StatusHandler.SetStringValue(core.MetricAppVersion, version)

dataArgs := factory.NewDataComponentsFactoryArgs(generalConfig, shardCoordinator, coreComponents, uniqueDBFolder)
dataComponents, err := factory.DataComponentsFactory(dataArgs)
Expand Down Expand Up @@ -642,7 +643,7 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
return err
}

ef := facade.NewElrondNodeFacade(currentNode, apiResolver)
ef := facade.NewElrondNodeFacade(currentNode, apiResolver, !useTermui)
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability, you could write above: ginDebugMode := !useTermui then pass it as the argument to NewElrondNodeFacade.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


efConfig := &config.FacadeConfig{
RestApiPort: ctx.GlobalString(restApiPort.Name),
Expand Down
7 changes: 7 additions & 0 deletions core/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package core

// UnVersionedAppString represents the default app version that indicate that the binary wasn't build by setting
// the appVersion flag
const UnVersionedAppString = "undefined"

// NodeType represents the node's role in the network
type NodeType string

Expand Down Expand Up @@ -100,3 +104,6 @@ const MetricNetworkSentBpsPeak = "erd_network_sent_bps_peak"

// MetricRoundTime is the metric for round time in seconds
const MetricRoundTime = "erd_round_time"

// MetricAppVersion is the metric for the current app version
const MetricAppVersion = "erd_app_version"
12 changes: 9 additions & 3 deletions facade/elrondNodeFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ type ElrondNodeFacade struct {
log *logger.Logger
tpsBenchmark *statistics.TpsBenchmark
config *config.FacadeConfig
ginDebugMode bool
}

// NewElrondNodeFacade creates a new Facade with a NodeWrapper
func NewElrondNodeFacade(node NodeWrapper, apiResolver ApiResolver) *ElrondNodeFacade {
func NewElrondNodeFacade(node NodeWrapper, apiResolver ApiResolver, ginDebugMode bool) *ElrondNodeFacade {
if node == nil {
return nil
}
Expand All @@ -43,8 +44,9 @@ func NewElrondNodeFacade(node NodeWrapper, apiResolver ApiResolver) *ElrondNodeF
}

return &ElrondNodeFacade{
node: node,
apiResolver: apiResolver,
node: node,
apiResolver: apiResolver,
ginDebugMode: ginDebugMode,
}
}

Expand Down Expand Up @@ -100,6 +102,10 @@ func (ef *ElrondNodeFacade) IsNodeRunning() bool {
return ef.node.IsRunning()
}

func (ef *ElrondNodeFacade) GinDebugMode() bool {
return ef.ginDebugMode
}

// RestApiPort returns the port on which the api should start on, based on the config file provided.
// The API will start on the DefaultRestPort value unless a correct value is passed or
// the value is explicitly set to off, in which case it will not start at all
Expand Down
9 changes: 5 additions & 4 deletions facade/elrondNodeFacade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

func createElrondNodeFacadeWithMockNodeAndResolver() *ElrondNodeFacade {
return NewElrondNodeFacade(&mock.NodeMock{}, &mock.ApiResolverStub{})
return NewElrondNodeFacade(&mock.NodeMock{}, &mock.ApiResolverStub{}, false)
}

func createElrondNodeFacadeWithMockResolver(node *mock.NodeMock) *ElrondNodeFacade {
return NewElrondNodeFacade(node, &mock.ApiResolverStub{})
return NewElrondNodeFacade(node, &mock.ApiResolverStub{}, false)
}

func TestNewElrondFacade_FromValidNodeShouldReturnNotNil(t *testing.T) {
Expand All @@ -30,12 +30,12 @@ func TestNewElrondFacade_FromValidNodeShouldReturnNotNil(t *testing.T) {
}

func TestNewElrondFacade_FromNilNodeShouldReturnNil(t *testing.T) {
ef := NewElrondNodeFacade(nil, &mock.ApiResolverStub{})
ef := NewElrondNodeFacade(nil, &mock.ApiResolverStub{}, false)
assert.Nil(t, ef)
}

func TestNewElrondFacade_FromNilApiResolverShouldReturnNil(t *testing.T) {
ef := NewElrondNodeFacade(&mock.NodeMock{}, nil)
ef := NewElrondNodeFacade(&mock.NodeMock{}, nil, false)
assert.Nil(t, ef)
}

Expand Down Expand Up @@ -507,6 +507,7 @@ func TestElrondNodeFacade_GetDataValue(t *testing.T) {
return make([]byte, 0), nil
},
},
false,
)

_, _ = ef.GetVmValue("", "")
Expand Down
55 changes: 6 additions & 49 deletions statusHandler/termuiStatusHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package statusHandler
import (
"sync"

"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/statusHandler/termuic"
)

Expand All @@ -15,8 +14,9 @@ type TermuiStatusHandler struct {

// NewTermuiStatusHandler will return an instance of the struct
func NewTermuiStatusHandler() *TermuiStatusHandler {
tsh := new(TermuiStatusHandler)
tsh.initMetricsMap()
tsh := &TermuiStatusHandler{
termuiConsoleMetrics: &sync.Map{},
}
tsh.tui = termuic.NewTermuiConsole(tsh.termuiConsoleMetrics)

return tsh
Expand All @@ -43,62 +43,19 @@ func (tsh *TermuiStatusHandler) Termui() *termuic.TermuiConsole {
return tsh.tui
}

// InitMetricsMap will init the map of prometheus metrics
func (tsh *TermuiStatusHandler) initMetricsMap() {
tsh.termuiConsoleMetrics = &sync.Map{}

tsh.termuiConsoleMetrics.Store(core.MetricPublicKeyTxSign, "")
tsh.termuiConsoleMetrics.Store(core.MetricPublicKeyBlockSign, "")
tsh.termuiConsoleMetrics.Store(core.MetricShardId, uint64(0))

tsh.termuiConsoleMetrics.Store(core.MetricNodeType, "")
tsh.termuiConsoleMetrics.Store(core.MetricCountConsensus, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricCountLeader, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricCountAcceptedBlocks, uint64(0))

tsh.termuiConsoleMetrics.Store(core.MetricIsSyncing, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNonce, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricProbableHighestNonce, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricCurrentRound, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricSynchronizedRound, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricRoundTime, uint64(0))

tsh.termuiConsoleMetrics.Store(core.MetricLiveValidatorNodes, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricConnectedNodes, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNumConnectedPeers, uint64(0))

tsh.termuiConsoleMetrics.Store(core.MetricCpuLoadPercent, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricMemLoadPercent, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricTotalMem, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkRecvBps, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkRecvBpsPeak, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkRecvPercent, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkSentBps, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkSentBpsPeak, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricNetworkSentPercent, uint64(0))
tsh.termuiConsoleMetrics.Store(core.MetricTxPoolLoad, uint64(0))

}

// SetInt64Value method - will update the value for a key
func (tsh *TermuiStatusHandler) SetInt64Value(key string, value int64) {
if _, ok := tsh.termuiConsoleMetrics.Load(key); ok {
tsh.termuiConsoleMetrics.Store(key, value)
}
tsh.termuiConsoleMetrics.Store(key, value)
}

// SetUInt64Value method - will update the value for a key
func (tsh *TermuiStatusHandler) SetUInt64Value(key string, value uint64) {
if _, ok := tsh.termuiConsoleMetrics.Load(key); ok {
tsh.termuiConsoleMetrics.Store(key, value)
}
tsh.termuiConsoleMetrics.Store(key, value)
}

// SetStringValue method - will update the value of a key
func (tsh *TermuiStatusHandler) SetStringValue(key string, value string) {
if _, ok := tsh.termuiConsoleMetrics.Load(key); ok {
tsh.termuiConsoleMetrics.Store(key, value)
}
tsh.termuiConsoleMetrics.Store(key, value)
}

// Increment - will increment the value of a key
Expand Down
13 changes: 1 addition & 12 deletions statusHandler/termuiStatusHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,14 @@ func TestTermuiStatusHandler_TermuiShouldPass(t *testing.T) {
assert.NotNil(t, termuiConsole)
}

func TestTermuiStatusHandler_TestIfMetricsAreInitialized(t *testing.T) {
t.Parallel()

termuiStatusHandler := statusHandler.NewTermuiStatusHandler()

// check if nonce metric for example was initialized
_, err := termuiStatusHandler.GetTermuiMetricByKey(core.MetricNonce)

assert.Nil(t, err)
assert.Equal(t, 26, termuiStatusHandler.GetMetricsCount())
}

func TestTermuiStatusHandler_TestIncrement(t *testing.T) {
t.Parallel()

var metricKey = core.MetricNonce

termuiStatusHandler := statusHandler.NewTermuiStatusHandler()

termuiStatusHandler.SetUInt64Value(metricKey, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability, delete var metricKey and use core.MetricNonce directly as the arguments to SetUInt64Value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

termuiStatusHandler.Increment(metricKey)
valueI, err := termuiStatusHandler.GetTermuiMetricByKey(metricKey)
assert.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions statusHandler/termuic/termuiConsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ func (tc *TermuiConsole) eventLoop() {
termWidth, termHeight := ui.TerminalDimensions()
tc.grid.SetRectangle(0, 0, termWidth, termHeight)

time.Sleep(1 * time.Second)

uiEvents := ui.PollEvents()
// handles kill signal sent to gotop
sigTerm := make(chan os.Signal, 2)
signal.Notify(sigTerm, os.Interrupt, syscall.SIGTERM)

tc.consoleRender.RefreshData(tc.logLines)

for {
select {
case <-time.After(refreshInterval):
Expand Down
Loading