Skip to content

Commit

Permalink
feat: Better self-service commands for DHT providing (#815)
Browse files Browse the repository at this point in the history
* Add LastRun and NextRun stats.
* Update the changelog.
* removed NextRun from stats

---------

Co-authored-by: Guillaume Michel <[email protected]>
Co-authored-by: guillaumemichel <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 3c70cf3 commit 5c158ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ The following emojis are used to highlight certain changes:
### Security


## [v0.27.3]

### Added

- `provider`: Added `ReprovideInterval` and `LastRun` stats to the Reprovider [#815](https://github.com/ipfs/boxo/pull/815)


## [v0.27.2]

### Fixed
Expand Down
9 changes: 7 additions & 2 deletions provider/reprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type reprovider struct {
statLk sync.Mutex
totalProvides, lastReprovideBatchSize uint64
avgProvideDuration, lastReprovideDuration time.Duration
lastRun time.Time

throughputCallback ThroughputCallback
// throughputProvideCurrentCount counts how many provides has been done since the last call to throughputCallback
Expand Down Expand Up @@ -363,6 +364,7 @@ func (s *reprovider) run() {
if performedReprovide {
s.lastReprovideBatchSize = uint64(len(keys))
s.lastReprovideDuration = dur
s.lastRun = time.Now()

s.statLk.Unlock()

Expand Down Expand Up @@ -537,8 +539,9 @@ func (s *reprovider) shouldReprovide() bool {
}

type ReproviderStats struct {
TotalProvides, LastReprovideBatchSize uint64
AvgProvideDuration, LastReprovideDuration time.Duration
TotalProvides, LastReprovideBatchSize uint64
ReprovideInterval, AvgProvideDuration, LastReprovideDuration time.Duration
LastRun time.Time
}

// Stat returns various stats about this provider system
Expand All @@ -548,8 +551,10 @@ func (s *reprovider) Stat() (ReproviderStats, error) {
return ReproviderStats{
TotalProvides: s.totalProvides,
LastReprovideBatchSize: s.lastReprovideBatchSize,
ReprovideInterval: s.reprovideInterval,
AvgProvideDuration: s.avgProvideDuration,
LastReprovideDuration: s.lastReprovideDuration,
LastRun: s.lastRun,
}, nil
}

Expand Down

0 comments on commit 5c158ec

Please sign in to comment.