Merge pull request #211 from r4f4ss/hotfix_metrics

Fix error verification in metrics
This commit is contained in:
rafaelss 2024-10-29 08:07:23 -04:00 committed by GitHub
commit a679321ff1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View file

@ -185,7 +185,7 @@ func (bs *BeaconStorage) getLcUpdateValueByRange(start, end uint64) ([]byte, err
func (bs *BeaconStorage) putContentValue(contentId, contentKey, value []byte) error {
length := 32 + len(contentKey) + len(value)
_, err := bs.db.ExecContext(context.Background(), InsertQueryBeacon, contentId, contentKey, value, length)
if metrics.Enabled && err != nil {
if metrics.Enabled && err == nil {
portalStorageMetrics.EntriesCount.Inc(1)
portalStorageMetrics.ContentStorageUsage.Inc(int64(len(value)))
}
@ -194,7 +194,7 @@ func (bs *BeaconStorage) putContentValue(contentId, contentKey, value []byte) er
func (bs *BeaconStorage) putLcUpdate(period uint64, value []byte) error {
_, err := bs.db.ExecContext(context.Background(), InsertLCUpdateQuery, period, value, 0, len(value))
if metrics.Enabled && err != nil {
if metrics.Enabled && err == nil {
portalStorageMetrics.EntriesCount.Inc(1)
portalStorageMetrics.ContentStorageUsage.Inc(int64(len(value)))
}

View file

@ -456,7 +456,7 @@ func (p *ContentStorage) del(contentId []byte) error {
}
}
_, err = p.delStmt.Exec(contentId)
if metrics.Enabled && err != nil {
if metrics.Enabled && err == nil {
portalStorageMetrics.EntriesCount.Dec(1)
portalStorageMetrics.ContentStorageUsage.Dec(int64(sizeDel))
}
@ -480,7 +480,7 @@ func (p *ContentStorage) batchDel(ids [][]byte) error {
// delete items
_, err = p.sqliteDB.Exec(query, args...)
if metrics.Enabled && err != nil {
if metrics.Enabled && err == nil {
portalStorageMetrics.EntriesCount.Dec(int64(len(args)))
portalStorageMetrics.ContentStorageUsage.Dec(int64(sizeDel))
}
@ -509,7 +509,7 @@ func (p *ContentStorage) deleteContentOutOfRadius(radius *uint256.Int) error {
}
count, err := res.RowsAffected()
p.log.Trace("delete items", "count", count)
if metrics.Enabled && err != nil {
if metrics.Enabled && err == nil {
portalStorageMetrics.EntriesCount.Dec(count)
portalStorageMetrics.ContentStorageUsage.Dec(int64(sizeDel))
}