From f7b52d16f5836f405ad42aadfa838daac4c336f6 Mon Sep 17 00:00:00 2001 From: Travis Person Date: Sun, 6 Sep 2020 04:32:05 +0000 Subject: [PATCH 1/2] metrics: add expected height metric --- chain/sync.go | 26 ++++++++++++++++++++++++++ metrics/metrics.go | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/chain/sync.go b/chain/sync.go index 1b1cbdde9c..cc29e35502 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -125,6 +125,8 @@ type Syncer struct { verifier ffiwrapper.Verifier windowSize int + + tickerCtxCancel context.CancelFunc } // NewSyncer creates a new Syncer object. @@ -166,11 +168,35 @@ func NewSyncer(sm *stmgr.StateManager, bsync *blocksync.BlockSync, connmgr connm } func (syncer *Syncer) Start() { + tickerCtx, tickerCtxCancel := context.WithCancel(context.Background()) syncer.syncmgr.Start() + + syncer.tickerCtxCancel = tickerCtxCancel + + go syncer.runMetricsTricker(tickerCtx) +} + +func (syncer *Syncer) runMetricsTricker(tickerCtx context.Context) { + genesisTime := time.Unix(int64(syncer.Genesis.MinTimestamp()), 0) + ticker := build.Clock.Ticker(time.Duration(build.BlockDelaySecs) * time.Second) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + sinceGenesis := build.Clock.Now().Sub(genesisTime) + expectedHeight := int64(sinceGenesis.Seconds()) / int64(build.BlockDelaySecs) + + stats.Record(tickerCtx, metrics.ChainNodeHeightExpected.M(int64(expectedHeight))) + case <-tickerCtx.Done(): + return + } + } } func (syncer *Syncer) Stop() { syncer.syncmgr.Stop() + syncer.tickerCtxCancel() } // InformNewHead informs the syncer about a new potential tipset diff --git a/metrics/metrics.go b/metrics/metrics.go index a6732e8ea0..5dd8652636 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -30,6 +30,7 @@ var ( var ( LotusInfo = stats.Int64("info", "Arbitrary counter to tag lotus info to", stats.UnitDimensionless) ChainNodeHeight = stats.Int64("chain/node_height", "Current Height of the node", stats.UnitDimensionless) + ChainNodeHeightExpected = stats.Int64("chain/node_height_expected", "Expected Height of the node", stats.UnitDimensionless) ChainNodeWorkerHeight = stats.Int64("chain/node_worker_height", "Current Height of workers on the node", stats.UnitDimensionless) MessagePublished = stats.Int64("message/published", "Counter for total locally published messages", stats.UnitDimensionless) MessageReceived = stats.Int64("message/received", "Counter for total received messages", stats.UnitDimensionless) @@ -62,6 +63,10 @@ var ( Measure: ChainNodeHeight, Aggregation: view.LastValue(), } + ChainNodeHeightExpectedView = &view.View{ + Measure: ChainNodeHeightExpected, + Aggregation: view.LastValue(), + } ChainNodeWorkerHeightView = &view.View{ Measure: ChainNodeWorkerHeight, Aggregation: view.LastValue(), @@ -138,6 +143,7 @@ var ( var DefaultViews = append([]*view.View{ InfoView, ChainNodeHeightView, + ChainNodeHeightExpectedView, ChainNodeWorkerHeightView, BlockReceivedView, BlockValidationFailureView, From f6f5405a2c8100c0b20606cc92a14fb3d46bf4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 7 Sep 2020 18:21:45 +0200 Subject: [PATCH 2/2] Fix lint --- chain/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/sync.go b/chain/sync.go index cc29e35502..0bcb290f8d 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -187,7 +187,7 @@ func (syncer *Syncer) runMetricsTricker(tickerCtx context.Context) { sinceGenesis := build.Clock.Now().Sub(genesisTime) expectedHeight := int64(sinceGenesis.Seconds()) / int64(build.BlockDelaySecs) - stats.Record(tickerCtx, metrics.ChainNodeHeightExpected.M(int64(expectedHeight))) + stats.Record(tickerCtx, metrics.ChainNodeHeightExpected.M(expectedHeight)) case <-tickerCtx.Done(): return }