Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a97a4e4

Browse files
authoredMar 22, 2024
feat(lambda-analytics): track pipeline usage BM-964 (#3203)
#### Motivation Tracking what is being rendered is quite helpful to know what is useful to people, we are not currently tracking if a tile is a terrain-rgb or color-ramp #### Modification Add extra stats about terrain-rgb vs color-ramp vs rgba outputs. #### Checklist _If not applicable, provide explanation of why._ - [ ] Tests updated - [ ] Docs updated - [ ] Issue linked in Title
1 parent d8e7459 commit a97a4e4

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed
 

‎packages/lambda-analytics/src/__tests__/file.process.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const ExampleLogs = `#Version: 1.0
1818
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 -
1919
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
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 -
21-
21+
2020-07-28 01:13:33 SYD4-C2 2588 255.255.255.128 GET d1mez8rta20vo0.cloudfront.net /v1/tiles/elevation/WebMercatorQuad/18/257866/162011.png 200 - Mozilla/5.0%20QGIS/31006 api=${ClientApiKey}&pipeline=terrain-rgb - 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 -
2222
`
2323
.trim()
2424
.split('\n');
@@ -81,11 +81,19 @@ describe('FileProcess', () => {
8181
assert.deepEqual(devStats?.extension, { webp: 1, jpeg: 1, png: 1, wmts: 0, other: 0, pbf: 0 });
8282
assert.deepEqual(devStats?.tileSet, { aerial: 2, topo50: 1 });
8383

84-
assert.equal(clientStats?.total, 3);
84+
assert.equal(clientStats?.total, 4);
8585
assert.equal(clientStats?.apiType, 'c');
86-
assert.deepEqual(clientStats?.cache, { hit: 3, miss: 0 });
87-
assert.deepEqual(clientStats?.tileMatrix, { WebMercatorQuad: 1, NZTM2000: 1, NZTM2000Quad: 1 });
88-
assert.deepEqual(clientStats?.extension, { webp: 1, jpeg: 0, png: 0, wmts: 1, other: 0, pbf: 1 });
89-
assert.deepEqual(clientStats?.tileSet, { topo50: 2, 'antipodes-islands-satellite-2019-2020-0.5m': 1 });
86+
assert.deepEqual(clientStats?.cache, { hit: 4, miss: 0 });
87+
assert.deepEqual(clientStats?.tileMatrix, { WebMercatorQuad: 2, NZTM2000: 1, NZTM2000Quad: 1 });
88+
assert.deepEqual(clientStats?.extension, { webp: 1, jpeg: 0, png: 1, wmts: 1, other: 0, pbf: 1 });
89+
assert.deepEqual(clientStats?.tileSet, {
90+
topo50: 2,
91+
'antipodes-islands-satellite-2019-2020-0.5m': 1,
92+
elevation: 1,
93+
});
94+
95+
assert.deepEqual(clientStats?.pipeline, {
96+
'terrain-rgb': 1,
97+
});
9098
});
9199
});

‎packages/lambda-analytics/src/file.process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const FileProcess = {
3838
const apiKey = search.get('api');
3939
const apiValid = isValidApiKey(apiKey);
4040
if (apiValid.valid || apiValid.message === 'expired') {
41-
stats.track(apiKey as string, referer ?? '', userAgent, uri.toLowerCase(), parseInt(status), hit);
41+
stats.track(apiKey as string, referer ?? '', userAgent, uri.toLowerCase(), parseInt(status), hit, search);
4242
}
4343
}
4444
},

‎packages/lambda-analytics/src/stats.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface TileRequestStats {
3131
tileMatrix: Record<string, number>;
3232
/** Tilesets accessed */
3333
tileSet: Record<string, number>;
34+
/** Pipelines used */
35+
pipeline: Record<string, number>;
3436
/** Rough approximation of useragent user */
3537
userAgent: Record<string, number>;
3638
/** How was this rollup generated */
@@ -49,6 +51,7 @@ function newStat(timestamp: string, api: string, referer: string): TileRequestSt
4951
cache: { hit: 0, miss: 0 },
5052
extension: { webp: 0, jpeg: 0, png: 0, wmts: 0, pbf: 0, other: 0 },
5153
tileSet: {},
54+
pipeline: {},
5255
userAgent: {},
5356
tileMatrix: {},
5457
generated: {
@@ -59,7 +62,14 @@ function newStat(timestamp: string, api: string, referer: string): TileRequestSt
5962
};
6063
}
6164

62-
function track(stat: TileRequestStats, userAgent: string, uri: string, status: number, isHit: boolean): void {
65+
function track(
66+
stat: TileRequestStats,
67+
userAgent: string,
68+
uri: string,
69+
status: number,
70+
isHit: boolean,
71+
search: URLSearchParams,
72+
): void {
6373
stat.total++;
6474

6575
if (isHit) stat.cache.hit++;
@@ -92,6 +102,9 @@ function track(stat: TileRequestStats, userAgent: string, uri: string, status: n
92102
if (tileSet.startsWith('01')) stat.tileSet['byId'] = (stat.tileSet['byId'] ?? 0) + 1;
93103
else stat.tileSet[tileSet] = (stat.tileSet[tileSet] ?? 0) + 1;
94104

105+
const pipeline = search.get('pipeline');
106+
if (pipeline) stat.pipeline[pipeline] = (stat.pipeline[tileSet] ?? 0) + 1;
107+
95108
stat.userAgent[userAgent] = (stat.userAgent[userAgent] ?? 0) + 1;
96109
}
97110

@@ -130,7 +143,15 @@ export class LogStats {
130143
return existing;
131144
}
132145

133-
track(apiKey: string, referer: string, userAgent: string, uri: string, status: number, isHit: boolean): void {
134-
track(this.getStats(apiKey, referer), userAgent, uri, status, isHit);
146+
track(
147+
apiKey: string,
148+
referer: string,
149+
userAgent: string,
150+
uri: string,
151+
status: number,
152+
isHit: boolean,
153+
search: URLSearchParams,
154+
): void {
155+
track(this.getStats(apiKey, referer), userAgent, uri, status, isHit, search);
135156
}
136157
}

0 commit comments

Comments
 (0)
Please sign in to comment.