From 83021da4d49b36b086499a037f07439b05c8346a Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 11:25:59 -0700 Subject: [PATCH 1/9] introduces block_time_seconds --- consensus/metrics.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index dcaaae9399..dced8a8c65 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -48,6 +48,8 @@ type Metrics struct { // Time between this and the last block. BlockIntervalSeconds metrics.Histogram + // Block time in seconds. + BlockTimeSeconds metrics.Gauge // Number of transactions. NumTxs metrics.Gauge @@ -57,9 +59,9 @@ type Metrics struct { TotalTxs metrics.Gauge // The latest block height. CommittedHeight metrics.Gauge - // Whether or not a node is fast syncing. 1 if yes, 0 if no. + // Whether a node is fast syncing. 1 if yes, 0 if no. FastSyncing metrics.Gauge - // Whether or not a node is state syncing. 1 if yes, 0 if no. + // Whether a node is state syncing. 1 if yes, 0 if no. StateSyncing metrics.Gauge // Number of blockparts transmitted by peer. @@ -171,6 +173,12 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Name: "block_interval_seconds", Help: "Time between this and the last block.", }, labels).With(labelsAndValues...), + BlockTimeSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "block_time_seconds", + Help: "Duration between this block and the preceding one.", + }, labels).With(labelsAndValues...), NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Namespace: namespace, Subsystem: MetricsSubsystem, From 31ce3d98fe957880c1e8d08b71c1833739a7cdf8 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 11:27:07 -0700 Subject: [PATCH 2/9] adds block height label --- consensus/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index dced8a8c65..d1a482aaa0 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -178,7 +178,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Subsystem: MetricsSubsystem, Name: "block_time_seconds", Help: "Duration between this block and the preceding one.", - }, labels).With(labelsAndValues...), + }, append(labels, "block_height")).With(labelsAndValues...), NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Namespace: namespace, Subsystem: MetricsSubsystem, From f9a2ea36b83d147668c41e0087e331250add54d5 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 11:37:13 -0700 Subject: [PATCH 3/9] records block time in the block time gauge --- consensus/metrics.go | 1 + consensus/state.go | 11 +++++++---- test/maverick/consensus/state.go | 12 +++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index d1a482aaa0..5e574f0f94 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -272,6 +272,7 @@ func NopMetrics() *Metrics { ByzantineValidatorsPower: discard.NewGauge(), BlockIntervalSeconds: discard.NewHistogram(), + BlockTimeSeconds: discard.NewGauge(), NumTxs: discard.NewGauge(), BlockSizeBytes: discard.NewGauge(), diff --git a/consensus/state.go b/consensus/state.go index bbbb1d3d44..31e048ae01 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1830,9 +1830,11 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { if height > 1 { lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1) if lastBlockMeta != nil { - cs.metrics.BlockIntervalSeconds.Observe( - block.Time.Sub(lastBlockMeta.Header.Time).Seconds(), - ) + elapsedTime := block.Time.Sub(lastBlockMeta.Header.Time).Seconds() + cs.metrics.BlockIntervalSeconds.Observe(elapsedTime) + cs.metrics.BlockTimeSeconds.With("block_height", + fmt.Sprintf("%d", block.Height)).Set(elapsedTime) + } } @@ -1844,6 +1846,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { cs.metrics.NumTxs.Set(float64(len(block.Data.Txs))) cs.metrics.TotalTxs.Add(float64(len(block.Data.Txs))) cs.metrics.BlockSizeBytes.Set(float64(blockSize)) + // cs.metrics.BlockTimeSeconds cs.metrics.CommittedHeight.Set(float64(block.Height)) } @@ -2003,7 +2006,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - //nolint: gocritic + // nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index f73e4a14c6..7f129888bd 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -1668,9 +1668,11 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { if height > 1 { lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1) if lastBlockMeta != nil { - cs.metrics.BlockIntervalSeconds.Observe( - block.Time.Sub(lastBlockMeta.Header.Time).Seconds(), - ) + elapsedTime := block.Time.Sub(lastBlockMeta.Header.Time).Seconds() + cs.metrics.BlockIntervalSeconds.Observe(elapsedTime) + cs.metrics.BlockTimeSeconds.With("block_height", + fmt.Sprintf("%d", block.Height)).Set(elapsedTime) + } } @@ -1776,7 +1778,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - //nolint: gocritic + // nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet @@ -1892,7 +1894,7 @@ func (cs *State) signAddVote(msgType cmtproto.SignedMsgType, hash []byte, header } // if !cs.replayMode { cs.Logger.Error("Error signing vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err) - //} + // } return nil } From 14c9debfb90ba094a58ce4903d424644d3d46162 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 12:02:53 -0700 Subject: [PATCH 4/9] removes leading spaces for directives --- consensus/state.go | 2 +- test/maverick/consensus/state.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 31e048ae01..e0b24b2150 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -2006,7 +2006,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - // nolint: gocritic + //nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 7f129888bd..7106923fa1 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -1778,7 +1778,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - // nolint: gocritic + //nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet From 32a04c096caaddc833ffa363ca7457586d672608 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 12:48:33 -0700 Subject: [PATCH 5/9] uses strconv for conversion from int64 to string --- test/maverick/consensus/state.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 7106923fa1..d557f27869 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -8,6 +8,7 @@ import ( "os" "reflect" "runtime/debug" + "strconv" "sync" "time" @@ -1671,7 +1672,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { elapsedTime := block.Time.Sub(lastBlockMeta.Header.Time).Seconds() cs.metrics.BlockIntervalSeconds.Observe(elapsedTime) cs.metrics.BlockTimeSeconds.With("block_height", - fmt.Sprintf("%d", block.Height)).Set(elapsedTime) + strconv.FormatInt(block.Height, 10)).Set(elapsedTime) } } From a86066341e29b399f5fabf59f4e4a6ca2153b218 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 21 Sep 2023 13:20:45 -0700 Subject: [PATCH 6/9] deletes a commented code --- consensus/state.go | 1 - 1 file changed, 1 deletion(-) diff --git a/consensus/state.go b/consensus/state.go index e0b24b2150..2ca4b26e8b 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1846,7 +1846,6 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { cs.metrics.NumTxs.Set(float64(len(block.Data.Txs))) cs.metrics.TotalTxs.Add(float64(len(block.Data.Txs))) cs.metrics.BlockSizeBytes.Set(float64(blockSize)) - // cs.metrics.BlockTimeSeconds cs.metrics.CommittedHeight.Set(float64(block.Height)) } From 763616f01ee584b9f1a845490a1c6f6132e2ba0a Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 25 Sep 2023 11:19:38 -0600 Subject: [PATCH 7/9] removes block height label --- consensus/state.go | 3 +-- test/maverick/consensus/state.go | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 2ca4b26e8b..398abc0856 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1832,8 +1832,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { if lastBlockMeta != nil { elapsedTime := block.Time.Sub(lastBlockMeta.Header.Time).Seconds() cs.metrics.BlockIntervalSeconds.Observe(elapsedTime) - cs.metrics.BlockTimeSeconds.With("block_height", - fmt.Sprintf("%d", block.Height)).Set(elapsedTime) + cs.metrics.BlockTimeSeconds.Set(elapsedTime) } } diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index d557f27869..71e4fb5182 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -8,7 +8,6 @@ import ( "os" "reflect" "runtime/debug" - "strconv" "sync" "time" @@ -1671,8 +1670,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { if lastBlockMeta != nil { elapsedTime := block.Time.Sub(lastBlockMeta.Header.Time).Seconds() cs.metrics.BlockIntervalSeconds.Observe(elapsedTime) - cs.metrics.BlockTimeSeconds.With("block_height", - strconv.FormatInt(block.Height, 10)).Set(elapsedTime) + cs.metrics.BlockTimeSeconds.Set(elapsedTime) } } From 38ded280d90f10cfde59f5a70b68ce3e58c30d8e Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 25 Sep 2023 11:30:21 -0600 Subject: [PATCH 8/9] removes block height label from the metric definition as well --- consensus/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index 5e574f0f94..c684c339f6 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -178,7 +178,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Subsystem: MetricsSubsystem, Name: "block_time_seconds", Help: "Duration between this block and the preceding one.", - }, append(labels, "block_height")).With(labelsAndValues...), + }, labels).With(labelsAndValues...), NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Namespace: namespace, Subsystem: MetricsSubsystem, From 94f2c81f10a66ed59f0b62d2054940681f09ace3 Mon Sep 17 00:00:00 2001 From: Sanaz Taheri <35961250+staheri14@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:58:01 -0600 Subject: [PATCH 9/9] deletes an excess space --- test/maverick/consensus/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 71e4fb5182..ae5afad0ae 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -1893,7 +1893,7 @@ func (cs *State) signAddVote(msgType cmtproto.SignedMsgType, hash []byte, header } // if !cs.replayMode { cs.Logger.Error("Error signing vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err) - // } + //} return nil }