Skip to content

Commit

Permalink
Merge pull request optimism-java#211 from r4f4ss/hotfix_metrics
Browse files Browse the repository at this point in the history
Fix error verification in metrics
  • Loading branch information
r4f4ss authored Oct 29, 2024
2 parents 9c4f3b2 + 06201c3 commit a679321
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions portalnetwork/beacon/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand All @@ -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)))
}
Expand Down
6 changes: 3 additions & 3 deletions portalnetwork/history/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit a679321

Please sign in to comment.