Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: return rate in/out as number #3798

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/core-api/STATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Each yielded object contains the following keys:

- `totalIn` - is a [BigInt][bigNumber], in bytes.
- `totalOut` - is a [BigInt][bigNumber], in bytes.
- `rateIn` - is a [BigInt][bigNumber], in bytes.
- `rateOut` - is a [BigInt][bigNumber], in bytes.
- `rateIn` - is a `float`, in bytes.
- `rateOut` - is a `float`, in bytes.

### Example

Expand All @@ -62,8 +62,8 @@ for await (const stats of ipfs.stats.bw()) {
}
// { totalIn: BigInt {...},
// totalOut: BigInt {...},
// rateIn: BigInt {...},
// rateOut: BigInt {...} }
// rateIn: number {...},
// rateOut: number {...} }
```

A great source of [examples][] can be found in the tests for this API.
Expand Down
4 changes: 2 additions & 2 deletions packages/interface-ipfs-core/src/stats/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ exports.expectIsBandwidth = (err, stats) => {
expect(stats).to.have.a.property('rateOut')
expect(isBigInt(stats.totalIn)).to.eql(true)
expect(isBigInt(stats.totalOut)).to.eql(true)
expect(isBigInt(stats.rateIn)).to.eql(true)
expect(isBigInt(stats.rateOut)).to.eql(true)
expect(stats.rateIn).to.be.a('number')
expect(stats.rateOut).to.be.a('number')
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-types/src/stats/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export interface BWOptions extends AbortOptions {
export interface BWResult {
totalIn: bigint
totalOut: bigint
rateIn: bigint
rateOut: bigint
rateIn: number
rateOut: number
}
12 changes: 6 additions & 6 deletions packages/ipfs-core/src/components/stats/bw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
* @typedef {Object} BandwidthInfo
* @property {bigint} totalIn
* @property {bigint} totalOut
* @property {bigint} rateIn
* @property {bigint} rateOut
* @property {number} rateIn
* @property {number} rateOut
*
* @typedef {import('libp2p')} libp2p
* @typedef {import('peer-id')} PeerId
Expand Down Expand Up @@ -45,8 +45,8 @@ function getBandwidthStats (libp2p, opts) {
return {
totalIn: BigInt(0),
totalOut: BigInt(0),
rateIn: BigInt(0),
rateOut: BigInt(0)
rateIn: 0.0,
rateOut: 0.0
}
}

Expand All @@ -55,8 +55,8 @@ function getBandwidthStats (libp2p, opts) {
return {
totalIn: BigInt(snapshot.dataReceived.integerValue().toString()),
totalOut: BigInt(snapshot.dataSent.integerValue().toString()),
rateIn: BigInt(Math.round(movingAverages.dataReceived[60000].movingAverage() / 60)),
rateOut: BigInt(Math.round(movingAverages.dataSent[60000].movingAverage() / 60))
rateIn: movingAverages.dataReceived[60000].movingAverage() / 60,
rateOut: movingAverages.dataSent[60000].movingAverage() / 60
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-http-client/src/stats/bw.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = configure(api => {
transform: (stats) => ({
totalIn: BigInt(stats.TotalIn),
totalOut: BigInt(stats.TotalOut),
rateIn: BigInt(stats.RateIn),
rateOut: BigInt(stats.RateOut)
rateIn: parseFloat(stats.RateIn),
rateOut: parseFloat(stats.RateOut)
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-http-server/src/api/resources/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ exports.bw = {
yield * map(source, stat => ({
TotalIn: stat.totalIn.toString(),
TotalOut: stat.totalOut.toString(),
RateIn: stat.rateIn.toString(),
RateOut: stat.rateOut.toString()
RateIn: stat.rateIn,
RateOut: stat.rateOut
}))
}
))
Expand Down