Skip to content

fix(blocks): collapse CMS content slugs in normalizePath - #447

Merged
hugo-ccabral merged 1 commit into
mainfrom
fix/http-route-cms-slug-cardinality
Aug 13, 2026
Merged

hugo-ccabral merged 1 commit into
mainfrom
fix/http-route-cms-slug-cardinality

Conversation

@nicacioliveira

@nicacioliveira nicacioliveira commented Aug 6, 2026 •

Copy link
Copy Markdown

Closes #428.

Problem

normalizePath already states the rule it exists to enforce — "a raw path is unbounded cardinality (one histogram series per URL) and must never reach a metric attribute" — and collapses hex ids, numeric ids and /:slug/p product pages.

It does not catch CMS content slugs. They carry no digits, no hex id and no /p suffix, so nothing matches and each CMS page passes through as its own literal path:

/mochila-de-couro
/moveis/quarto-infantil
/granado/eau-de-toilette-spritz-100ml
/moveis/quarto-adulto/cabeceiras-mesa-de-cabeceiras

Measured

http.route reached 20,714 distinct values across only 6 tenants — ~9,900 series per tenant, against ~390 for the legacy runtime's equivalent.

It sits on http.server.request.duration, the highest-volume metric in the pipeline (19,055,009 rows in 3h), and otel_metrics_histogram holds 149.65 GB.

Every other attribute on that metric is already well behaved:

attribute distinct values
url.path 1
deco.http.status_class 4
http.response.status_code 20
user_agent.original 1
http.route 20,714

So http.route carries essentially all of the cardinality on the biggest metric we have.

Fix

Collapse any hyphenated path segment to :slug.

A hyphen is the discriminator: CMS slugs are hyphenated by construction, while framework and API segments are single words (api, sessions, deco, invoke, loaders, render) and keep their meaning. Dotfile segments like .well-known are excluded.

Routes arriving with an explicit route_pattern are untouched — this only changes the fallback branch, which is exactly where the unbounded values came from.

/mochila-de-couro                                  -> /:slug
/moveis/quarto-infantil                            -> /moveis/:slug
/moveis/quarto-adulto/cabeceiras-mesa-de-cabeceiras -> /moveis/:slug/:slug
/api/sessions                                      -> unchanged
/deco/invoke/magento/loaders/features              -> unchanged
/.well-known/passkey-endpoints                     -> /.well-known/:slug

What is lost, and the judgement call

Per-page latency breakdown for CMS pages. That was never a real capability — it was 20,714 series impersonating a dimension — but "how slow is this specific product page" now has to come from spans or logs rather than this metric. The top-level section survives (/moveis/:slug), so "are furniture listings slow" still answers.

The hyphen heuristic is the one judgement call here. A single-word CMS slug with no hyphen still passes through. I picked it because it is simple, needs no route registry, and covers every path actually observed in production — but if you would rather key off something authoritative (the matched page id, or omitting http.route entirely when there is no template, per semconv), say so and I will reshape it.

Verification

  • tsc --noEmit clean
  • vitest run packages/blocks/ → 659 passed / 50 files (4 new tests covering the real production paths)

🤖 Generated with Claude Code


Summary by cubic

Collapses CMS slug segments in normalizePath to bound http.route and stop unbounded series on http.server.request.duration. Reduces metric cardinality and storage while keeping API/framework routes intact.

  • Bug Fixes
    • Collapse hyphenated path segments to :slug; keep .well-known readable and non-hyphenated segments unchanged.
    • Preserve existing id and product page rules; no change when a route_pattern is present.
    • Add tests for real production paths to prevent regressions.

Written for commit b9e45a9. Summary will update on new commits.

Review in cubic

`normalizePath` already states the rule it exists to enforce — "a raw path is
unbounded cardinality (one histogram series per URL) and must never reach a
metric attribute" — and collapses hex ids, numeric ids and `/:slug/p` product
pages to placeholders.

It does not catch CMS content slugs, which carry no digits, no hex id and no
`/p` suffix, so each CMS page passes through as its own literal path:

    /mochila-de-couro
    /moveis/quarto-infantil
    /granado/eau-de-toilette-spritz-100ml
    /moveis/quarto-adulto/cabeceiras-mesa-de-cabeceiras

Measured on the production ClickHouse, `http.route` reached 20,714 distinct
values across only 6 tenants — roughly 9,900 series per tenant, against ~390
for the legacy runtime's equivalent. It sits on
`http.server.request.duration`, the highest-volume metric in the pipeline
(19,055,009 rows in 3h), and `otel_metrics_histogram` holds 149.65 GB.

Every other attribute on that metric is already well behaved: `url.path` is 1
distinct value, `deco.http.status_class` 4, `http.response.status_code` 20,
`user_agent.original` 1. `http.route` carries essentially all of the
cardinality.

The fix collapses any hyphenated path segment to `:slug`. A hyphen is the
discriminator: CMS slugs are hyphenated by construction, while framework and
API segments are single words (`api`, `sessions`, `deco`, `invoke`, `loaders`,
`render`), so those keep their meaning and stay individually visible. Dotfile
segments such as `.well-known` are excluded.

Routes that arrive with an explicit `route_pattern` are untouched — this only
affects the fallback branch, which is exactly where the unbounded values were
coming from.

What is lost: per-page latency breakdown for CMS pages. That was never a real
capability — it was 20,714 series impersonating a dimension — but "how slow is
this specific product page" now has to come from spans or logs rather than
this metric. The top-level section is preserved (`/moveis/:slug`,
`/granado/:slug`), so "are furniture listings slow" still answers.

This is a heuristic, and it is the one judgement call in the change: a
single-word CMS slug with no hyphen would still pass through. Tests cover the
real paths measured in production.

Verified: tsc --noEmit clean, 659/659 tests pass across 50 files.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nicacioliveira
nicacioliveira requested a review from a team August 6, 2026 16:00
@hugo-ccabral
hugo-ccabral merged commit 13a707c into main Aug 13, 2026
1 check passed
@hugo-ccabral
hugo-ccabral deleted the fix/http-route-cms-slug-cardinality branch August 13, 2026 16:33
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 7.37.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

nicacioliveira pushed a commit that referenced this pull request Aug 13, 2026
Conflict was in observability.test.ts only: both sides appended a new
describe block at the end of the file (#447's normalizePath cardinality
cases and this PR's METRIC_METADATA bucket guards), so git overlapped the
two regions. Kept both, and merged the import list.

observability.ts auto-merged cleanly. Verified semantically, not just
textually: main added SWR cache instrumentation, so the guard in this PR
("every metric with unit 's' must declare boundaries") could have started
failing. All 4 second-scale metrics in the merged METRIC_METADATA carry
DURATION_BUCKET_BOUNDARIES_SECONDS.

Gates: 673 tests pass (51 files), blocks typecheck clean. biome lint
diagnostics on these two files are identical to main's baseline; the
resolution also fixes the import-sort error main currently carries.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http.route carries raw paths for CMS pages (20,714 distinct values on the highest-volume metric)

2 participants