From 77bb1fe5468aba13d5d577060775c09231ecfd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 2 Oct 2024 17:27:11 +0200 Subject: [PATCH] feat: expose adsMissingPieceCID and entriesNotRetrievable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- api/lib/handler.js | 2 ++ api/test/handler.test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/api/lib/handler.js b/api/lib/handler.js index 014c0b4..db0d772 100644 --- a/api/lib/handler.js +++ b/api/lib/handler.js @@ -102,6 +102,8 @@ async function getProviderIngestionStatus (req, res, repository, providerId) { // Is it a problem if our observability API does not tell the provider address? ingestionStatus: walkerState.status, lastHeadWalkedFrom: walkerState.lastHead ?? walkerState.head, + adsMissingPieceCID: walkerState.adsMissingPieceCID ?? 0, + entriesNotRetrievable: walkerState.entriesNotRetrievable ?? 0, piecesIndexed: await repository.countPiecesIndexed(providerId) }) } diff --git a/api/test/handler.test.js b/api/test/handler.test.js index c6fa1fd..e39397d 100644 --- a/api/test/handler.test.js +++ b/api/test/handler.test.js @@ -123,6 +123,8 @@ describe('HTTP request handler', () => { // providerAddress: "state.providerAddress", ingestionStatus: 'walking', lastHeadWalkedFrom: 'last-head', + adsMissingPieceCID: 0, + entriesNotRetrievable: 0, piecesIndexed: 1 }) @@ -167,6 +169,8 @@ describe('HTTP request handler', () => { providerId: 'provider-id', ingestionStatus: 'walking', lastHeadWalkedFrom: 'head', + adsMissingPieceCID: 0, + entriesNotRetrievable: 0, piecesIndexed: 1 }) @@ -175,5 +179,32 @@ describe('HTTP request handler', () => { `public, max-age=${60}` ) }) + + it('returns the number of adsMissingPieceCID and entriesNotRetrievable', async () => { + await repository.setWalkerState('provider-id', { + status: 'walking', + head: 'head', + entriesNotRetrievable: 10, + adsMissingPieceCID: 20 + }) + + const res = await fetch(new URL('/ingestion-status/provider-id', baseUrl)) + await assertResponseStatus(res, 200) + const body = await res.json() + + assert.deepStrictEqual(body, { + providerId: 'provider-id', + ingestionStatus: 'walking', + lastHeadWalkedFrom: 'head', + entriesNotRetrievable: 10, + adsMissingPieceCID: 20, + piecesIndexed: 0 + }) + + assert.strictEqual( + res.headers.get('cache-control'), + `public, max-age=${60}` + ) + }) }) })