From 6751f706c5986b3fab9e99a7b573f9a60b017b48 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Thu, 10 Oct 2024 08:38:18 -0400 Subject: [PATCH 1/5] chore: log tarball retrieval from cache --- lib/fetcher.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fetcher.js b/lib/fetcher.js index cc2c2db..5b81809 100644 --- a/lib/fetcher.js +++ b/lib/fetcher.js @@ -188,6 +188,9 @@ class FetcherBase { // private // Note: cacache will raise a EINTEGRITY error if the integrity doesn't match #tarballFromCache () { + log.silly('tarball', `getting data for ${ + this.spec + } from cache`) return cacache.get.stream.byDigest(this.cache, this.integrity, this.opts) } From b42945d117c88801d7245d2091e32b861390ded8 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:04:32 -0400 Subject: [PATCH 2/5] log as cache hit --- lib/fetcher.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/fetcher.js b/lib/fetcher.js index 5b81809..f2ac976 100644 --- a/lib/fetcher.js +++ b/lib/fetcher.js @@ -188,10 +188,15 @@ class FetcherBase { // private // Note: cacache will raise a EINTEGRITY error if the integrity doesn't match #tarballFromCache () { - log.silly('tarball', `getting data for ${ - this.spec - } from cache`) - return cacache.get.stream.byDigest(this.cache, this.integrity, this.opts) + const startTime = Date.now() + const stream = cacache.get.stream.byDigest(this.cache, this.integrity, this.opts) + const elapsedTime = Date.now() - startTime + // cache is good, so log it as a hit in particular since there was no fetch logged + log.http( + 'cache', + `${this.spec} ${elapsedTime}ms (cache hit)` + ) + return stream } get [_.cacheFetches] () { From eb838eb084701aaa70c07996890fc9c63267aec0 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:26:43 -0400 Subject: [PATCH 3/5] Update fetcher.js --- test/fetcher.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/fetcher.js b/test/fetcher.js index 8b2adb3..765266b 100644 --- a/test/fetcher.js +++ b/test/fetcher.js @@ -207,6 +207,10 @@ t.test('extract', t => { }).extract(target + '/badcache') .then(({ resolved, integrity }) => { t.match(logs, [ + [ 'http', + 'cache', + /file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/, + ], ['warn', 'tar', 'zlib: incorrect header check'], [ 'silly', @@ -298,7 +302,11 @@ t.test('extract', t => { algorithm: 'sha512', sri: Object, }, 'got expected error') - t.same(logs, [ + t.match(logs, [ + [ 'http', + 'cache', + /file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/, + ], [ 'silly', 'tarball', From 937b6b9464f32096f28dbe24c35d7a07c05ceaa5 Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 15 Oct 2024 07:17:28 -0700 Subject: [PATCH 4/5] fixup: linting --- test/fetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetcher.js b/test/fetcher.js index 765266b..1c400cf 100644 --- a/test/fetcher.js +++ b/test/fetcher.js @@ -207,7 +207,7 @@ t.test('extract', t => { }).extract(target + '/badcache') .then(({ resolved, integrity }) => { t.match(logs, [ - [ 'http', + ['http', 'cache', /file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/, ], From 6c6fa7cf4067a6a0c95903683ac73a1eb40da985 Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 15 Oct 2024 07:17:36 -0700 Subject: [PATCH 5/5] fixup: linting --- test/fetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetcher.js b/test/fetcher.js index 1c400cf..6f857b3 100644 --- a/test/fetcher.js +++ b/test/fetcher.js @@ -303,7 +303,7 @@ t.test('extract', t => { sri: Object, }, 'got expected error') t.match(logs, [ - [ 'http', + ['http', 'cache', /file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/, ],