Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add http rsr #285

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

feat: add http rsr #285

wants to merge 14 commits into from

Conversation

NikolasHaimerl
Copy link
Contributor

This MR proposes the following changes:

  1. Add http rsr metric
  2. Change the spark-evalute dependency hash to account for the recent changes made to the spar-evalute db

Related to Issue #192

@NikolasHaimerl NikolasHaimerl marked this pull request as ready for review January 9, 2025 09:50
@juliangruber
Copy link
Member

This MR proposes the following changes:

@NikolasHaimerl what does MR stand for?

stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
@NikolasHaimerl
Copy link
Contributor Author

This MR proposes the following changes:

@NikolasHaimerl what does MR stand for?

Just a habit from from working with Gitlab: MR= Merge Request, PR = Pull request. Means the same thing

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 === undefined || r.successful_http === null) ? r.successful_http / r.total : null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
success_rate_http: r.total > 0 && !(r.successful_http === undefined || r.successful_http === null) ? r.successful_http / r.total : null
success_rate_http: r.total > 0 && typeof r.successful_http === 'number' ? r.successful_http / r.total : null

I think this is simpler and still covers all cases

Copy link
Contributor Author

@NikolasHaimerl NikolasHaimerl Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this works. successful_http is a string representation of a number.
We could use something like this for the check to be more concise and reuse the expression:
const isValidNumber = value => value != null && !isNaN(+value)
And then call:
success_rate_http: r.total > 0 && isValidNumber(r.successful_http) ? r.successful_http / r.total : null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI:
node-pg represents 64-bit integers coming from Postgres as JavaScript strings to preserve precision.

Even if the column successful_http is represented as a 32-bit integer, SUM(successful_http) yields a 64-bit integer.

We could cast successful_http to INT in the Postgres query so that we receive a Number on the JavaScript side, but that would create an inconsistency with how we handle successful, so this is not a good solution.

I think we can trust that the database returns either null (when the column value is not set) or a string representation of a number.

Suggested change
success_rate_http: r.total > 0 && !(r.successful_http === undefined || r.successful_http === null) ? r.successful_http / r.total : null
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great at the high level, let's improve the details now 👍🏻

stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
stats/lib/stats-fetchers.js Outdated Show resolved Hide resolved
stats/test/handler.test.js Show resolved Hide resolved
stats/test/handler.test.js Outdated Show resolved Hide resolved
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised we are missing one test (see my comment below). The rest LGTM.

{ day, success_rate: 0.1, successful: '1', total: '10', successful_http: '1', success_rate_http: 0.1 }
])
})
it('handles successful_http values 0, null, undefined', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a similar test for per-miner RSR endpoint. I find it important to verify that SUM() and our logic detecting null values work as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


res = await fetch(
new URL(
'/miners/retrieval-success-rate/summary?from=2024-01-20&to=2024-01-22',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case (it('handles successful_http values 0, null, undefined',) is nested inside the test suite describe('GET /retrieval-success-rate',. It should test the endpoint GET /retrieval-success-rate only.

Please move this new block testing /miners/retrieval-success-rate/summary to a new test case inside the test suite describe('GET /miners/retrieval-success-rate/summary' later in this file.

describe('GET /miners/retrieval-success-rate/summary', () => {

@NikolasHaimerl NikolasHaimerl requested a review from bajtos January 10, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants