bucketize
此内容尚不支持你的语言。
bucketize<
T>(value,allowed):T|"other"
Defined in: src/metrics/Metrics.ts:459
Map a possibly-unbounded value onto a bounded label domain: value if
it is one of allowed, 'other' otherwise.
const ALLOWED_ROUTES = ['/orders', '/users/:id', '/health'] as const;metrics.counter('http_requests_total', { route: bucketize(routeTemplateOf(request), ALLOWED_ROUTES),}).inc();This is the fix for high-cardinality labels; the registry’s cap is only
the backstop for when nobody applied one. Keep allowed small — it is
scanned linearly, and its length is the family’s series count.
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”string
allowed
Section titled “allowed”readonly T[]
Returns
Section titled “Returns”T | "other"
