Zum Inhalt springen
Deutsch

bucketize

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.

T extends string

string

readonly T[]

T | "other"