From ce6cbbd1368e3937d39ca73db94e7ba393fc445a Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Mon, 8 Apr 2024 19:48:09 +0200 Subject: [PATCH] remove miner stats --- lib/handler.js | 8 ------ lib/stats-fetchers.js | 21 --------------- test/handler.test.js | 59 +++---------------------------------------- 3 files changed, 3 insertions(+), 85 deletions(-) diff --git a/lib/handler.js b/lib/handler.js index f38017e..40e91a4 100644 --- a/lib/handler.js +++ b/lib/handler.js @@ -5,7 +5,6 @@ import { URLSearchParams } from 'node:url' import { fetchDailyParticipants, - fetchMinersRSRSummary, fetchMonthlyParticipants, fetchRetrievalSuccessRate } from './stats-fetchers.js' @@ -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') diff --git a/lib/stats-fetchers.js b/lib/stats-fetchers.js index a323b68..516e05b 100644 --- a/lib/stats-fetchers.js +++ b/lib/stats-fetchers.js @@ -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 -} diff --git a/test/handler.test.js b/test/handler.test.js index 71b6f3c..f26cdb4 100644 --- a/test/handler.test.js +++ b/test/handler.test.js @@ -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', () => { @@ -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) => { @@ -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] ) }