Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-analytics): correctly track NZTM2000Quad tileMatrix #2602

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/geo/src/tms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ export const TileMatrixSets = {
/**
* Find a tile matrix set given a identifier or epsg string
* @param identifier Tile matrix set identifier
* @param caseSensitive Should this compare case sensitively
*/
find(identifier: string | Nullish): TileMatrixSet | null {
find(identifier: string | Nullish, caseSensitive = true): TileMatrixSet | null {
if (identifier == null) return null;
const epsg = Epsg.parse(identifier);
if (epsg != null) return TileMatrixSets.tryGet(epsg);
if (caseSensitive) {
for (const tileMatrix of TileMatrixSets.All) {
if (tileMatrix.identifier === identifier) return tileMatrix;
}
return null;
}
for (const tileMatrix of TileMatrixSets.All) {
if (tileMatrix.identifier === identifier) return tileMatrix;
if (tileMatrix.identifier.toLowerCase() === identifier.toLowerCase()) return tileMatrix;
}
return null;
},
Expand Down
4 changes: 2 additions & 2 deletions packages/lambda-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface TileRequestStats {
/** Tile exensions used */
extension: { webp: 0; jpeg: 0; png: 0; wmts: 0; other: 0 };
/** Projections used */
projection: { 2193: 0; 3857: 0 };
tileMatrix: { NZTM2000Quad: number, WebMercatorQuad: number, NZTM2000Old: number },
/** Tilesets accessed */
tileSet: { aerial: 0; aerialIndividual: 0; topo50: 0; direct: 0 };
tileSet: Record<string, number>;
/** How was this rollup generated */
generated: {
timestamp: string;
Expand Down
18 changes: 10 additions & 8 deletions packages/lambda-analytics/src/__tests__/file.process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const ClientApiKey = 'c' + ulid().toLowerCase();
export const ExampleLogs = `#Version: 1.0
#Fields: date time x-edge-location sc-bytes c-ip cs-method cs(Host) cs-uri-stem sc-status cs(Referer) cs(User-Agent) cs-uri-query cs(Cookie) x-edge-result-type x-edge-request-id x-host-header cs-protocol cs-bytes time-taken x-forwarded-for ssl-protocol ssl-cipher x-edge-response-result-type cs-protocol-version fle-status fle-encrypted-fields c-port time-to-first-byte x-edge-detailed-result-type sc-content-type sc-content-len sc-range-start sc-range-end
2020-07-28 01:11:25 AKL50-C1 20753 255.255.255.141 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/aerial/EPSG:3857/19/516588/320039.webp 200 https://bar.com/ Mozilla/5.0%20(X11;%20Linux%20x86_64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/85.0.4183.101%20Safari/537.36 api=${DevApiKey} - Hit sBUoz03SwR_hVZkdj0LVC1s_bKakd9ONcKTYRrQLuIR3VPBQUx5xog== basemaps.linz.govt.nz https 82 0.049 - TLSv1.3 TLS_AES_128_GCM_SHA256 Hit HTTP/2.0 -- 21780 0.049 Hit image/webp 20320 - -
2020-07-28 01:16:13 SYD1-C2 156474 255.255.255.4 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/aerial/EPSG:3857/19/516542/319785.png 200 https://www.bar.com/ Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_4)%20AppleWebKit/605.1.15%20(KHTML,%20like%20Gecko)%20Version/13.1.2%20Safari/605.1.15 api=${DevApiKey}&foo=bar - Hit 9KNnEESjZA-yVs62ffwtRYNaa0gpYKLeEEHH490dmO7AAu3ZxnPc8Q== basemaps.linz.govt.nz https 77 1.791 - TLSv1.3 TLS_AES_128_GCM_SHA256 Hit HTTP/2.0 - - 19468 0.028 Hit image/png 155886 - -
2020-07-28 01:16:13 SYD1-C2 156474 255.255.255.4 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/aerial/NZTM2000Quad/19/516542/319785.png 200 https://www.bar.com/ Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_4)%20AppleWebKit/605.1.15%20(KHTML,%20like%20Gecko)%20Version/13.1.2%20Safari/605.1.15 api=${DevApiKey}&foo=bar - Hit 9KNnEESjZA-yVs62ffwtRYNaa0gpYKLeEEHH490dmO7AAu3ZxnPc8Q== basemaps.linz.govt.nz https 77 1.791 - TLSv1.3 TLS_AES_128_GCM_SHA256 Hit HTTP/2.0 - - 19468 0.028 Hit image/png 155886 - -
2020-07-28 01:16:21 SYD1-C2 21223 255.255.255.73 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/topo50/3857/18/257866/162011.jpeg 200 https://bar.com/map/ Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/85.0.4183.102%20Safari/537.36 api=${DevApiKey} - Miss a5nrTCsdsP5EDQ9EXkUQQJMCJTlbRUz5JIxowZ-1kRriRDUmLPxvVQ== basemaps.linz.govt.nz https 76 0.222 - TLSv1.3 TLS_AES_128_GCM_SHA256 Miss HTTP/2.0 - - 57799 0.222 Miss image/jpeg 20797 - -
2020-07-28 01:13:33 SYD4-C2 2588 255.255.255.128 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/topo50/EPSG:3857/WMTSCapabilities.xml 200 - Mozilla/5.0%20QGIS/31006 api=${ClientApiKey} - RefreshHit oflBr-vO5caoVpi2S23hGh9YWMUca-McU_Fl5oN9fqW_H9ea_iS-Kg== basemaps.linz.govt.nz https 243 0.051 - TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 RefreshHit HTTP/1.1 - - 55515 0.050 RefreshHit text/xml -
2020-07-28 01:13:33 SYD4-C2 2588 255.255.255.128 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/topo50/EPSG:3857/18/257866/162011.pbf 200 - Mozilla/5.0%20QGIS/31006 api=${ClientApiKey} - RefreshHit oflBr-vO5caoVpi2S23hGh9YWMUca-McU_Fl5oN9fqW_H9ea_iS-Kg== basemaps.linz.govt.nz https 243 0.051 - TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 RefreshHit HTTP/1.1 - - 55515 0.050 RefreshHit text/xml -
2020-07-28 01:13:33 SYD4-C2 2588 255.255.255.128 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/topo50/EPSG:2193/18/257866/162011.pbf 200 - Mozilla/5.0%20QGIS/31006 api=${ClientApiKey} - RefreshHit oflBr-vO5caoVpi2S23hGh9YWMUca-McU_Fl5oN9fqW_H9ea_iS-Kg== basemaps.linz.govt.nz https 243 0.051 - TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 RefreshHit HTTP/1.1 - - 55515 0.050 RefreshHit text/xml -
2020-07-28 01:13:33 SYD4-C2 2588 255.255.255.128 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/antipodes-islands-satellite-2019-2020-0.5m/NZTM2000Quad/18/257866/162011.webp 200 - Mozilla/5.0%20QGIS/31006 api=${ClientApiKey} - RefreshHit oflBr-vO5caoVpi2S23hGh9YWMUca-McU_Fl5oN9fqW_H9ea_iS-Kg== basemaps.linz.govt.nz https 243 0.051 - TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 RefreshHit HTTP/1.1 - - 55515 0.050 RefreshHit text/xml -

`
.trim()
.split('\n');
Expand Down Expand Up @@ -72,15 +74,15 @@ o.spec('FileProcess', () => {
o(devStats?.total).equals(3);
o(devStats?.apiType).equals('d');
o(devStats?.cache).deepEquals({ hit: 2, miss: 1 });
o(devStats?.tileMatrix).deepEquals({ WebMercatorQuad: 3 });
o(devStats?.tileMatrix).deepEquals({ WebMercatorQuad: 2, NZTM2000Quad: 1 });
o(devStats?.extension).deepEquals({ webp: 1, jpeg: 1, png: 1, wmts: 0, other: 0, pbf: 0 });
o(devStats?.tileSet).deepEquals({ aerial: 2, topo50: 1 });

o(clientStats?.total).equals(2);
o(clientStats?.total).equals(3);
o(clientStats?.apiType).equals('c');
o(clientStats?.cache).deepEquals({ hit: 2, miss: 0 });
o(clientStats?.tileMatrix).deepEquals({ WebMercatorQuad: 2 });
o(clientStats?.extension).deepEquals({ webp: 0, jpeg: 0, png: 0, wmts: 1, other: 0, pbf: 1 });
o(clientStats?.tileSet).deepEquals({ topo50: 2 });
o(clientStats?.cache).deepEquals({ hit: 3, miss: 0 });
o(clientStats?.tileMatrix).deepEquals({ WebMercatorQuad: 1, NZTM2000: 1, NZTM2000Quad: 1 });
o(clientStats?.extension).deepEquals({ webp: 1, jpeg: 0, png: 0, wmts: 1, other: 0, pbf: 1 });
o(clientStats?.tileSet).deepEquals({ topo50: 2, 'antipodes-islands-satellite-2019-2020-0.5m': 1 });
});
});
2 changes: 1 addition & 1 deletion packages/lambda-analytics/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function track(stat: TileRequestStats, userAgent: string, uri: string, status: n
// no projection means this url is weirdly formatted
if (projectionStr == null) return;

const tileMatrix = TileMatrixSets.find(projectionStr);
const tileMatrix = TileMatrixSets.find(projectionStr, false);
if (tileMatrix == null) return;

// Projection
Expand Down