Skip to content

Commit

Permalink
Filter 0-byte requests and paths not starting with an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 8, 2024
1 parent 00fdaf2 commit 6f284dc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/athena.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ exports.queryUsage = async (day) => {
const removeRegion = "REGEXP_REPLACE(uri, '\\A/(use1/|usw2/)?')";
const uri = `REGEXP_REPLACE(${removeRegion}, '/[^/]+/[^/]+\\z')`;
const tbl = process.env.ATHENA_TABLE;
const sql = `SELECT ${uri}, SUM(bytes) FROM ${tbl} WHERE date = DATE(?) GROUP BY ${uri}`;
const prefix = `REGEXP_LIKE(${removeRegion}, '\\A[1-9][0-9]*/')`;
const where = `date = DATE(?) AND bytes > 0 AND ${prefix}`;
const sql = `SELECT ${uri}, SUM(bytes) FROM ${tbl} WHERE ${where} GROUP BY ${uri}`;

// NOTE: for some reason, date params must be quoted
return exports.query(sql, [`'${dayStr}'`]);
Expand Down

0 comments on commit 6f284dc

Please sign in to comment.