A failed request emits three lifecycle events. request:end is the terminal and universal one, so it is the request counter; request:failed is additional and gets its own series. Counting both as requests is the double count issue #64 was filed for. Labels come from route, which the route table bounds, never from name, which carries the arriving path and is bounded by nothing — issue #65. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
138 lines
4.9 KiB
TypeScript
138 lines
4.9 KiB
TypeScript
import type { EventPayload } from '@green-tea/core';
|
|
|
|
import type { MetricsSnapshot, Series } from './types.ts';
|
|
|
|
/**
|
|
* The route reported when an event carries none.
|
|
*
|
|
* Bounded and distinct from core's own `<unmatched>`, which means "no route matched". This one means
|
|
* "the event did not say", which is a different fact and worth being able to tell apart.
|
|
*/
|
|
const UNKNOWN_ROUTE = '<unknown>';
|
|
|
|
interface Bucket {
|
|
route: string;
|
|
method: string;
|
|
status?: number;
|
|
value: number;
|
|
}
|
|
|
|
/** A stable key for one labelled series. */
|
|
function keyOf(route: string, method: string, status?: number): string {
|
|
return `${route} |