Skip to content

Commit

Permalink
feat: metric for successful http retrievals (#437)
Browse files Browse the repository at this point in the history
* add: metric for successful http retrievals

* formatting

* add: test for successful http retrievals

* formatting

* Update test/retrieval-stats.test.js

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

* Update test/retrieval-stats.test.js

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

---------

Co-authored-by: Nikolas Haimerl <[email protected]>
Co-authored-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2025
1 parent 1484c8e commit 679265d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
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'
}
]

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

0 comments on commit 679265d

Please sign in to comment.