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

Commit

Permalink
remove miner stats
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Apr 8, 2024
1 parent 010170f commit ce6cbbd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 85 deletions.
8 changes: 0 additions & 8 deletions lib/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { URLSearchParams } from 'node:url'

import {
fetchDailyParticipants,
fetchMinersRSRSummary,
fetchMonthlyParticipants,
fetchRetrievalSuccessRate
} from './stats-fetchers.js'
Expand Down Expand Up @@ -61,13 +60,6 @@ const handler = async (req, res, pgPool) => {
res,
pgPool,
fetchMonthlyParticipants)
} else if (req.method === 'GET' && segs.join('/') === 'miners/retrieval-success-rate/summary') {
await getStatsWithFilterAndCaching(
pathname,
searchParams,
res,
pgPool,
fetchMinersRSRSummary)
} else if (req.method === 'GET' && segs.length === 0) {
// health check - required by Grafana datasources
res.end('OK')
Expand Down
21 changes: 0 additions & 21 deletions lib/stats-fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,3 @@ export const fetchMonthlyParticipants = async (pgPool, filter) => {
])
return rows
}

/**
* @param {import('pg').Pool} pgPool
* @param {import('./typings').Filter} filter
*/
export const fetchMinersRSRSummary = async (pgPool, filter) => {
const { rows } = await pgPool.query(`
SELECT miner_id, SUM(total) as total, SUM(successful) as successful
FROM retrieval_stats
WHERE day >= $1 AND day <= $2
GROUP BY miner_id
`, [
filter.from,
filter.to
])
const stats = rows.map(r => ({
miner_id: r.miner_id,
success_rate: r.total > 0 ? r.successful / r.total : null
}))
return stats
}
59 changes: 3 additions & 56 deletions test/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,6 @@ describe('HTTP request handler', () => {
await assertResponseStatus(res, 200)
assert.strictEqual(res.headers.get('cache-control'), 'public, max-age=31536000, immutable')
})

it('sums daily retrievals from all miners', async () => {
await givenRetrievalStats(pgPool, { day: '2024-01-10', minerId: 'f1one', total: 10, successful: 1 })
await givenRetrievalStats(pgPool, { day: '2024-01-10', minerId: 'f1two', total: 100, successful: 50 })
await givenRetrievalStats(pgPool, { day: '2024-01-11', minerId: 'f1one', total: 20, successful: 1 })
await givenRetrievalStats(pgPool, { day: '2024-01-11', minerId: 'f1two', total: 200, successful: 60 })

const res = await fetch(
new URL(
'/retrieval-success-rate?from=2024-01-10&to=2024-01-11',
baseUrl
), {
redirect: 'manual'
}
)
await assertResponseStatus(res, 200)
/** @type {{ day: string, success_rate: number }[]} */
const stats = await res.json()
stats.sort((a, b) => new Date(a.day) - new Date(b.day))
assert.deepStrictEqual(stats, [
{ day: '2024-01-10', success_rate: 51 / 110 },
{ day: '2024-01-11', success_rate: 61 / 220 }
])
})
})

describe('GET /participants/daily', () => {
Expand Down Expand Up @@ -215,35 +191,6 @@ describe('HTTP request handler', () => {
])
})
})

describe('GET /miners/retrieval-success-rate/summary', () => {
it('returns a summary of miners RSR for the given date range', async () => {
// before the range
await givenRetrievalStats(pgPool, { day: '2024-01-10', minerId: 'f1one', total: 10, successful: 1 })
await givenRetrievalStats(pgPool, { day: '2024-01-10', minerId: 'f1two', total: 100, successful: 20 })
// in the range
await givenRetrievalStats(pgPool, { day: '2024-01-11', minerId: 'f1one', total: 20, successful: 1 })
await givenRetrievalStats(pgPool, { day: '2024-01-11', minerId: 'f1two', total: 200, successful: 150 })
// after the range
await givenRetrievalStats(pgPool, { day: '2024-01-12', minerId: 'f1one', total: 30, successful: 1 })
await givenRetrievalStats(pgPool, { day: '2024-01-12', minerId: 'f1two', total: 300, successful: 60 })

const res = await fetch(
new URL(
'/miners/retrieval-success-rate/summary?from=2024-01-11&to=2024-01-11',
baseUrl
), {
redirect: 'manual'
}
)
await assertResponseStatus(res, 200)
const stats = await res.json()
assert.deepStrictEqual(stats, [
{ miner_id: 'f1one', success_rate: 0.05 },
{ miner_id: 'f1two', success_rate: 0.75 }
])
})
})
})

const assertResponseStatus = async (res, status) => {
Expand All @@ -256,10 +203,10 @@ const assertResponseStatus = async (res, status) => {
}
}

const givenRetrievalStats = async (pgPool, { day, minerId, total, successful }) => {
const givenRetrievalStats = async (pgPool, { day, total, successful }) => {
await pgPool.query(
'INSERT INTO retrieval_stats (day, miner_id, total, successful) VALUES ($1, $2, $3, $4)',
[day, minerId ?? 'f1test', total, successful]
'INSERT INTO retrieval_stats (day, total, successful) VALUES ($1, $2, $3, $4)',
[day, total, successful]
)
}

Expand Down

0 comments on commit ce6cbbd

Please sign in to comment.