From d1b8af338e04a2c97459e9ea928ee87c04abe5bd Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 30 Oct 2023 08:07:09 +0000 Subject: [PATCH 1/3] Export Mpool-count Record the current size of the mpool and export through Prometheus --- chain/messagepool/messagepool.go | 4 ++++ metrics/metrics.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index d1496ceb920..505ef9d3df5 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -21,6 +21,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/minio/blake2b-simd" "github.com/raulk/clock" + "go.opencensus.io/stats" "golang.org/x/xerrors" ffi "github.com/filecoin-project/filecoin-ffi" @@ -1213,6 +1214,9 @@ func (mp *MessagePool) remove(ctx context.Context, from address.Address, nonce u return } } + + // Record the current size of the Mpool + stats.Record(ctx, metrics.MpoolMessageCount.M(int64(mp.currentSize))) } func (mp *MessagePool) Pending(ctx context.Context) ([]*types.SignedMessage, *types.TipSet) { diff --git a/metrics/metrics.go b/metrics/metrics.go index 822974f81ea..244ae59d27d 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -106,6 +106,7 @@ var ( MpoolAddTsDuration = stats.Float64("mpool/addts_ms", "Duration of addTs in mpool", stats.UnitMilliseconds) MpoolAddDuration = stats.Float64("mpool/add_ms", "Duration of Add in mpool", stats.UnitMilliseconds) MpoolPushDuration = stats.Float64("mpool/push_ms", "Duration of Push in mpool", stats.UnitMilliseconds) + MpoolMessageCount = stats.Int64("mpool/message_count", "Number of messages in the mpool", stats.UnitDimensionless) BlockPublished = stats.Int64("block/published", "Counter for total locally published blocks", stats.UnitDimensionless) BlockReceived = stats.Int64("block/received", "Counter for total received blocks", stats.UnitDimensionless) BlockValidationFailure = stats.Int64("block/failure", "Counter for block validation failures", stats.UnitDimensionless) @@ -307,6 +308,10 @@ var ( Measure: MpoolPushDuration, Aggregation: defaultMillisecondsDistribution, } + MpoolMessageCountView = &view.View{ + Measure: MpoolMessageCount, + Aggregation: view.LastValue(), + } PeerCountView = &view.View{ Measure: PeerCount, Aggregation: view.LastValue(), @@ -761,6 +766,7 @@ var ChainNodeViews = append([]*view.View{ MpoolAddTsDurationView, MpoolAddDurationView, MpoolPushDurationView, + MpoolMessageCountView, PubsubPublishMessageView, PubsubDeliverMessageView, PubsubRejectMessageView, From d121760172cbbcf9e0dd0f4ba963450a0ffc3bb1 Mon Sep 17 00:00:00 2001 From: Phi Date: Fri, 3 Nov 2023 08:59:01 +0100 Subject: [PATCH 2/3] Record currentSize on addLocked Record currentSize on addLocked --- chain/messagepool/messagepool.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 505ef9d3df5..7d55b0b16f5 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -1022,6 +1022,9 @@ func (mp *MessagePool) addLocked(ctx context.Context, m *types.SignedMessage, st } }) + // Record the current size of the Mpool + stats.Record(ctx, metrics.MpoolMessageCount.M(int64(mp.currentSize))) + return nil } From 9d58fff806fc95cb2c1bd992e874262ef3712e5f Mon Sep 17 00:00:00 2001 From: Phi Date: Fri, 3 Nov 2023 14:33:31 +0100 Subject: [PATCH 3/3] Update unreleased changelog Update unreleased changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f51d3c88127..32107f76e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # UNRELEASED - chore: Auto remove local chain data when importing chain file or snapshot ([filecoin-project/lotus#11277](https://github.com/filecoin-project/lotus/pull/11277)) +- feat: metric: export Mpool message count ([filecoin-project/lotus#11361](https://github.com/filecoin-project/lotus/pull/11361)) ## New features - feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100))