From c5d13e4b74a2b5d7e3b02547b51418880eef02d2 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio <5679073+r4f4ss@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:02:47 -0300 Subject: [PATCH] metric radius rate --- portalnetwork/history/storage.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/portalnetwork/history/storage.go b/portalnetwork/history/storage.go index 9844f96f89..7878093f6b 100644 --- a/portalnetwork/history/storage.go +++ b/portalnetwork/history/storage.go @@ -14,12 +14,17 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/portalnetwork/storage" "github.com/holiman/uint256" "github.com/mattn/go-sqlite3" ) +var ( + radiusRatio metrics.GaugeFloat64 +) + const ( sqliteName = "history.sqlite" contentDeletionFraction = 0.05 // 5% of the content will be deleted when the storage capacity is hit and radius gets adjusted. @@ -107,6 +112,10 @@ func NewHistoryStorage(config storage.PortalStorageConfig) (storage.ContentStora log: log.New("storage", config.NetworkName), } hs.radius.Store(storage.MaxDistance) + if metrics.Enabled { + radiusRatio = metrics.NewRegisteredGaugeFloat64("portal/radius_ratio", nil) + radiusRatio.Update(1) + } err := hs.createTable() if err != nil { return nil, err @@ -332,6 +341,12 @@ func (p *ContentStorage) EstimateNewRadius(currentRadius *uint256.Int) (*uint256 sizeRatio := currrentSize / p.storageCapacityInBytes if sizeRatio > 0 { bigFormat := new(big.Int).SetUint64(sizeRatio) + if metrics.Enabled { + newRadius := new(uint256.Int).Div(currentRadius, uint256.MustFromBig(bigFormat)) + newRadius.Mul(newRadius, uint256.NewInt(100)) + newRadius.Mod(newRadius, storage.MaxDistance) + radiusRatio.Update(newRadius.Float64() / 100) + } return new(uint256.Int).Div(currentRadius, uint256.MustFromBig(bigFormat)), nil } return currentRadius, nil @@ -391,6 +406,11 @@ func (p *ContentStorage) deleteContentFraction(fraction float64) (deleteCount in return 0, err } p.radius.Store(dis) + if metrics.Enabled { + dis.Mul(dis, uint256.NewInt(100)) + dis.Mod(dis, storage.MaxDistance) + radiusRatio.Update(dis.Float64() / 100) + } } // row must close first, or database is locked // rows.Close() can call multi times