From 73ba374ea2f166c4536a28043c614662f5f03cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6ckli?= Date: Mon, 17 Jun 2024 13:56:18 +0200 Subject: [PATCH] Get total mined and seen on network --- internal/metamorph/stats_collector.go | 16 +++++++++ .../metamorph/store/postgresql/postgres.go | 33 +++++++++++++++++++ .../store/postgresql/postgres_test.go | 2 ++ internal/metamorph/store/store.go | 2 ++ 4 files changed, 53 insertions(+) diff --git a/internal/metamorph/stats_collector.go b/internal/metamorph/stats_collector.go index a31e5d53d..5696a588e 100644 --- a/internal/metamorph/stats_collector.go +++ b/internal/metamorph/stats_collector.go @@ -32,6 +32,8 @@ type processorStats struct { statusSeenInOrphanMempool prometheus.Gauge statusNotMined prometheus.Gauge statusNotSeen prometheus.Gauge + statusMinedTotal prometheus.Gauge + statusSeenOnNetworkTotal prometheus.Gauge statusNotSeenStat int64 } @@ -80,6 +82,14 @@ func newProcessorStats(opts ...func(stats *processorStats)) *processorStats { Name: "arc_status_seen_in_orphan_mempool_count", Help: "Number of monitored transactions with status SEEN_IN_ORPHAN_MEMPOOL", }), + statusSeenOnNetworkTotal: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "arc_status_seen_on_network_total_count", + Help: "Total number of monitored transactions with status SEEN_ON_NETWORK", + }), + statusMinedTotal: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "arc_status_mined_total_count", + Help: "Total number of monitored transactions with status MINED", + }), notSeenLimit: notSeenLimitDefault, notMinedLimit: notMinedLimitDefault, } @@ -123,6 +133,8 @@ func (p *Processor) StartCollectStats() error { p.stats.statusSeenInOrphanMempool, p.stats.statusNotMined, p.stats.statusNotSeen, + p.stats.statusSeenOnNetworkTotal, + p.stats.statusMinedTotal, ) if err != nil { p.waitGroup.Done() @@ -147,6 +159,8 @@ func (p *Processor) StartCollectStats() error { p.stats.statusSeenInOrphanMempool, p.stats.statusNotMined, p.stats.statusNotSeen, + p.stats.statusSeenOnNetworkTotal, + p.stats.statusMinedTotal, ) for { @@ -176,6 +190,8 @@ func (p *Processor) StartCollectStats() error { p.stats.statusNotMined.Set(float64(collectedStats.StatusNotMined)) p.stats.statusNotSeen.Set(float64(collectedStats.StatusNotSeen)) p.stats.statusNotSeenStat = collectedStats.StatusNotSeen + p.stats.statusSeenOnNetworkTotal.Set(float64(collectedStats.StatusSeenOnNetworkTotal)) + p.stats.statusMinedTotal.Set(float64(collectedStats.StatusMinedTotal)) p.stats.mu.Unlock() } } diff --git a/internal/metamorph/store/postgresql/postgres.go b/internal/metamorph/store/postgresql/postgres.go index 4d39d7800..9f129df60 100644 --- a/internal/metamorph/store/postgresql/postgres.go +++ b/internal/metamorph/store/postgresql/postgres.go @@ -780,6 +780,39 @@ func (p *PostgreSQL) GetStats(ctx context.Context, since time.Time, notSeenLimit return nil, err } + q = ` + SELECT + max(status_counts.status_count) FILTER (where status_counts.status = $2 ) + ,max(status_counts.status_count) FILTER (where status_counts.status = $3 ) + FROM + (SELECT all_statuses.status, COALESCE (found_statuses.status_count, 0) AS status_count FROM + (SELECT unnest(ARRAY[ + $2::integer, + $3::integer]) AS status) AS all_statuses + LEFT JOIN + ( + SELECT + t.status, + count(*) AS status_count + FROM + metamorph.transactions t WHERE t.last_submitted_at > $1 + GROUP BY + t.status + ) AS found_statuses ON found_statuses.status = all_statuses.status) AS status_counts + ; + ` + + err = p.db.QueryRowContext(ctx, q, since, + metamorph_api.Status_SEEN_ON_NETWORK, + metamorph_api.Status_MINED, + ).Scan( + &stats.StatusSeenOnNetworkTotal, + &stats.StatusMinedTotal, + ) + if err != nil { + return nil, err + } + qNotSeen := ` SELECT count(*) diff --git a/internal/metamorph/store/postgresql/postgres_test.go b/internal/metamorph/store/postgresql/postgres_test.go index 3106158b3..1ba939d82 100644 --- a/internal/metamorph/store/postgresql/postgres_test.go +++ b/internal/metamorph/store/postgresql/postgres_test.go @@ -513,5 +513,7 @@ func TestPostgresDB(t *testing.T) { require.Equal(t, int64(0), res.StatusSeenInOrphanMempool) require.Equal(t, int64(1), res.StatusNotMined) require.Equal(t, int64(2), res.StatusNotSeen) + require.Equal(t, int64(6), res.StatusMinedTotal) + require.Equal(t, int64(2), res.StatusSeenOnNetworkTotal) }) } diff --git a/internal/metamorph/store/store.go b/internal/metamorph/store/store.go index 947e3db37..224e80de2 100644 --- a/internal/metamorph/store/store.go +++ b/internal/metamorph/store/store.go @@ -44,6 +44,8 @@ type Stats struct { StatusSeenInOrphanMempool int64 StatusNotSeen int64 StatusNotMined int64 + StatusSeenOnNetworkTotal int64 + StatusMinedTotal int64 } type MetamorphStore interface {