Skip to content

Commit

Permalink
fix: more timings and add timing header before err
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Dec 13, 2024
1 parent d765ad7 commit 2d0adfb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/verified-fetch/src/verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ export class VerifiedFetch {

// need to walk path, if it exists, to get the terminal element
const { error, result: pathDetails, header: pathWalkingHeader } = await serverTiming('path-walking', '', async () => handlePathWalking({ cid, path, resource, options, blockstore, log: this.log }))
this.serverTimingHeaders.push(pathWalkingHeader)
if (error != null) {
throw error
}

Check warning on line 263 in packages/verified-fetch/src/verified-fetch.ts

View check run for this annotation

Codecov / codecov/patch

packages/verified-fetch/src/verified-fetch.ts#L262-L263

Added lines #L262 - L263 were not covered by tests
this.serverTimingHeaders.push(pathWalkingHeader)
if (pathDetails instanceof Response) {
return pathDetails
}
Expand Down Expand Up @@ -323,10 +323,10 @@ export class VerifiedFetch {
const byteRangeContext = new ByteRangeContext(this.helia.logger, options?.headers)
const blockstore = this.getBlockstore(cid, resource, session, options)
const { error, result: pathDetails, header: pathWalkingHeader } = await serverTiming('path-walking', '', async () => handlePathWalking({ cid, path, resource, options, blockstore, log: this.log }))
this.serverTimingHeaders.push(pathWalkingHeader)
if (error != null) {
throw error
}
this.serverTimingHeaders.push(pathWalkingHeader)

if (pathDetails instanceof Response) {
return pathDetails
Expand Down Expand Up @@ -362,10 +362,10 @@ export class VerifiedFetch {
signal: options?.signal,
onProgress: options?.onProgress
}))
this.serverTimingHeaders.push(header)
if (error != null) {
throw error
}
this.serverTimingHeaders.push(header)

this.log.trace('found root file at %c/%s with cid %c', dirCid, rootFilePath, entry.cid)
path = rootFilePath
Expand Down Expand Up @@ -394,10 +394,10 @@ export class VerifiedFetch {
signal: options?.signal,
onProgress: options?.onProgress
}))
this.serverTimingHeaders.push(exporterFileHeader)
if (exporterFileErr != null) {
throw exporterFileErr
}
this.serverTimingHeaders.push(exporterFileHeader)

const asyncIter = entry.content({
signal: options?.signal,
Expand All @@ -407,14 +407,14 @@ export class VerifiedFetch {
})
this.log('got async iterator for %c/%s', cid, path)

const { error, result, header: streamAndFirstChunkHeader } = await serverTiming('stream-and-chunk', '', async () => getStreamFromAsyncIterable(asyncIter, path ?? '', this.helia.logger, {
const { error: streamAndChunkErr, result, header: streamAndFirstChunkHeader } = await serverTiming('stream-and-chunk', '', async () => getStreamFromAsyncIterable(asyncIter, path ?? '', this.helia.logger, {
onProgress: options?.onProgress,
signal: options?.signal
}))
if (error != null) {
throw error
}
this.serverTimingHeaders.push(streamAndFirstChunkHeader)
if (streamAndChunkErr != null) {
throw streamAndChunkErr
}
const { stream, firstChunk } = result

byteRangeContext.setBody(stream)
Expand All @@ -423,7 +423,14 @@ export class VerifiedFetch {
redirected
})

await setContentType({ bytes: firstChunk, path, response, contentTypeParser: this.contentTypeParser, log: this.log })
const { error: setContentTypeErr, header: setContentTypeTiming } = await serverTiming('set-content-type', '', async () => setContentType({ bytes: firstChunk, path, response, contentTypeParser: this.contentTypeParser, log: this.log }))
// await setContentType({ bytes: firstChunk, path, response, contentTypeParser: this.contentTypeParser, log: this.log })
this.serverTimingHeaders.push(setContentTypeTiming)

if (setContentTypeErr != null) {
throw setContentTypeErr

Check warning on line 431 in packages/verified-fetch/src/verified-fetch.ts

View check run for this annotation

Codecov / codecov/patch

packages/verified-fetch/src/verified-fetch.ts#L431

Added line #L431 was not covered by tests
}

setIpfsRoots(response, ipfsRoots)

return response
Expand Down

0 comments on commit 2d0adfb

Please sign in to comment.