Skip to content

Commit

Permalink
Just ignore paths under 10K bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 3, 2024
1 parent 0067d13 commit 7f4e74f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const log = require("lambda-log");

const IGNORE_PATHS = [/^$/, /^favicon\.ico$/, /^robots.txt$/];
const IGNORE_BYTES_UNDER = 10000;

/**
* Parse string to date array
Expand Down Expand Up @@ -71,7 +72,8 @@ exports.parseUsage = (dayDate, rows) =>
/* eslint-enable camelcase */
}

if (!IGNORE_PATHS.some((r) => r.test(uri))) {
const ignored = IGNORE_PATHS.find((r) => r.test(uri));
if (bytes >= IGNORE_BYTES_UNDER && !ignored) {
log.warn(`unrecognized uri: '${uri}' (${bytes} bytes)`);
}
return null;
Expand Down
10 changes: 6 additions & 4 deletions lib/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ describe("util", () => {
});
});

it("warns for unrecognized paths", () => {
it("warns for unrecognized paths over 10K bytes", () => {
jest.spyOn(log, "warn").mockImplementation(() => null);

const day = new Date("2024-03-04");
const rows = util.parseUsage(day, [
["whatev", "99"],
["robots.txt", "88"],
["string/string", "77"],
["whatev", "10001"],
["robots.txt", "10001"],
["string/string", "10001"],
["too/few/bytes", "9999"],
["not-much", "4"],
]);

expect(rows.length).toEqual(0);
Expand Down

0 comments on commit 7f4e74f

Please sign in to comment.