Skip to content

Commit

Permalink
feat: add http rsr (#285)
Browse files Browse the repository at this point in the history
* add http success stats

* change dependency and null test§

* Update stats/lib/stats-fetchers.js

Co-authored-by: Julian Gruber <[email protected]>

* test edge cases

* Update stats/test/handler.test.js

Co-authored-by: Miroslav Bajtoš <[email protected]>

* change value check

* formatting

* add miner test

* miner stats unique test

* formatting

* separated miner from summary test

* move test

---------

Co-authored-by: Nikolas Haimerl <[email protected]>
Co-authored-by: Julian Gruber <[email protected]>
Co-authored-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
4 people authored Jan 10, 2025
1 parent 48cbadf commit 611c616
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions stats/lib/stats-fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const fetchRetrievalSuccessRate = async (pgPools, filter) => {
// Fetch the "day" (DATE) as a string (TEXT) to prevent node-postgres for converting it into
// a JavaScript Date with a timezone, as that could change the date one day forward or back.
const { rows } = await pgPools.evaluate.query(`
SELECT day::text, SUM(total) as total, SUM(successful) as successful
SELECT
day::text,
SUM(total) as total,
SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE day >= $1 AND day <= $2 ${filter.nonZero === 'true' ? 'AND successful > 0' : ''}
GROUP BY day
Expand All @@ -20,7 +24,10 @@ export const fetchRetrievalSuccessRate = async (pgPools, filter) => {
day: r.day,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand Down Expand Up @@ -207,7 +214,11 @@ export const fetchParticipantRewardTransfers = async (pgPools, { from, to }, add
*/
export const fetchMinersRSRSummary = async (pgPools, filter) => {
const { rows } = await pgPools.evaluate.query(`
SELECT miner_id, SUM(total) as total, SUM(successful) as successful
SELECT
miner_id,
SUM(total) as total,
SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE day >= $1 AND day <= $2
GROUP BY miner_id
Expand All @@ -219,7 +230,10 @@ export const fetchMinersRSRSummary = async (pgPools, filter) => {
miner_id: r.miner_id,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand All @@ -232,7 +246,10 @@ export const fetchMinersRSRSummary = async (pgPools, filter) => {
*/
export const fetchDailyMinerRSRSummary = async (pgPools, { from, to }, minerId) => {
const { rows } = await pgPools.evaluate.query(`
SELECT day::TEXT, SUM(total) as total, SUM(successful) as successful
SELECT
day::TEXT,
SUM(total) as total, SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE miner_id = $1 AND day >= $2 AND day <= $3
GROUP BY day
Expand All @@ -246,7 +263,10 @@ export const fetchDailyMinerRSRSummary = async (pgPools, { from, to }, minerId)
day: r.day,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand Down
Loading

0 comments on commit 611c616

Please sign in to comment.