Skip to content

Commit 3bfa7a3

Browse files
fix(web): clear stale HTTP metrics route table
1 parent 2a94465 commit 3bfa7a3

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/web/src/httpMetrics.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { buildRouteTable, normalizeRoute } from './httpMetrics';
2+
import { buildRouteTable, initRouteTable, normalizeRoute } from './httpMetrics';
33

44
// Mirrors the shape and ordering of the real .next/routes-manifest.json:
55
// dynamic routes are listed in Next's resolution priority, with catch-alls
@@ -40,6 +40,20 @@ const maxLabels = table.staticPages.size
4040
+ 2; // + '/_next', 'other'
4141

4242
describe('normalizeRoute', () => {
43+
it('discards a previously loaded table when initialization fails', () => {
44+
expect(initRouteTable({
45+
staticRoutes: [{ page: '/api/health' }],
46+
dynamicRoutes: [],
47+
})).toBe(true);
48+
expect(normalizeRoute('/api/health')).toBe('/api/health');
49+
50+
expect(initRouteTable({
51+
staticRoutes: [],
52+
dynamicRoutes: [{ page: '/broken', regex: '[' }],
53+
})).toBe(false);
54+
expect(normalizeRoute('/api/health')).toBe('other');
55+
});
56+
4357
it('maps the root path', () => {
4458
expect(normalizeRoute('/', table)).toBe('/');
4559
expect(normalizeRoute('', table)).toBe('/');

packages/web/src/httpMetrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const initRouteTable = (manifest?: RoutesManifest): boolean => {
9191
} catch (error) {
9292
// Fail closed: without a table every request is labelled `other`, which
9393
// loses granularity but can never grow the label set.
94+
routeTable = undefined;
9495
logger.error(`Failed to load routes-manifest; all routes will be reported as '${OTHER_ROUTE}': ${error}`);
9596
return false;
9697
}

0 commit comments

Comments
 (0)