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: metric for successful http retrievals #437

Merged
merged 7 commits into from
Jan 8, 2025
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
7 changes: 6 additions & 1 deletion lib/retrieval-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const buildRetrievalStats = (measurements, telemetryPoint) => {
const ttfbValues = []
const durationValues = []
const sizeValues = []
let httpSuccesses = 0

for (const m of measurements) {
// `retrievalResult` should be always set by lib/preprocess.js, so we should never encounter
Expand Down Expand Up @@ -99,11 +100,15 @@ export const buildRetrievalStats = (measurements, telemetryPoint) => {
const taskId = getTaskId(m)
if (m.indexerResult) tasksWithIndexerResults.add(taskId)
if (m.indexerResult === 'OK') tasksWithHttpAdvertisement.add(taskId)

// A successful HTTP response is a response with result breakdown set to OK and the protocol being used is set to HTTP.
if (m.retrievalResult === 'OK' && m.protocol.toLowerCase() === 'http') { httpSuccesses++ }
}
const successRate = resultBreakdown.OK / totalCount

const successRateHttp = httpSuccesses / totalCount
telemetryPoint.intField('unique_tasks', uniqueTasksCount)
telemetryPoint.floatField('success_rate', successRate)
telemetryPoint.floatField('success_rate_http', successRateHttp)
telemetryPoint.intField('participants', participants.size)
telemetryPoint.intField('inet_groups', inetGroups.size)
telemetryPoint.intField('measurements', totalCount)
Expand Down
3 changes: 3 additions & 0 deletions test/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,16 @@ describe('evaluate', async function () {
assertPointFieldValue(point, 'measurements', '1i')
assertPointFieldValue(point, 'unique_tasks', '1i')
assertPointFieldValue(point, 'success_rate', '1')
// The default protocol is not http. While the overall success rate is 1, we expect the http success rate to be 0.
assertPointFieldValue(point, 'success_rate_http', '0')

point = telemetry.find(p => p.name === 'retrieval_stats_all')
assert(!!point,
`No telemetry point "retrieval_stats_all" was recorded. Actual points: ${JSON.stringify(telemetry.map(p => p.name))}`)
assertPointFieldValue(point, 'measurements', '10i')
assertPointFieldValue(point, 'unique_tasks', '2i')
assertPointFieldValue(point, 'success_rate', '0.5')
assertPointFieldValue(point, 'success_rate_http', '0')
})

it('prepares provider retrieval result stats', async () => {
Expand Down
35 changes: 35 additions & 0 deletions test/retrieval-stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,41 @@ describe('retrieval statistics', () => {
assertPointFieldValue(point, 'nano_score_per_inet_group_p50', '333333333i' /* =2/6 */)
assertPointFieldValue(point, 'nano_score_per_inet_group_max', '500000000i' /* =3/6 */)
})

it('records successful http rate', async () => {
/** @type {Measurement[]} */
const measurements = [
{
// Standard measurement, no http protocol used
...VALID_MEASUREMENT,
protocol: 'graphsync'
},
{
// A successful http measurement
...VALID_MEASUREMENT,
protocol: 'http'
},
{
...VALID_MEASUREMENT,
protocol: 'http',
retrievalResult: 'HTTP_500'
},
{
...VALID_MEASUREMENT,
// Should not be picked up, as the retrieval timed out
retrievalResult: 'TIMEOUT',
protocol: 'http'
}
NikolasHaimerl marked this conversation as resolved.
Show resolved Hide resolved
]

const point = new Point('stats')
buildRetrievalStats(measurements, point)
debug('stats', point.fields)

assertPointFieldValue(point, 'success_rate', '0.5')
// Only one of the successful measurements used http
assertPointFieldValue(point, 'success_rate_http', '0.25')
})
})

describe('getValueAtPercentile', () => {
Expand Down
Loading