-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
122 lines (106 loc) · 3.21 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {
FastifyPluginCallback,
FastifyPluginAsync,
FastifyRequest,
FastifyReply,
FastifyInstance,
RouteOptions,
} from 'fastify';
import Client, { Options as ClientOptions } from '@immobiliarelabs/dats';
import { Sampler } from '@dnlup/doc';
type CustomClient = Pick<
Client,
'gauge' | 'counter' | 'timing' | 'set' | 'close' | 'connect'
>;
type GetDynamicRouteLabel = (
this: FastifyInstance,
request: FastifyRequest,
reply: FastifyReply
) => string;
type GetStaticRouteLabel = (
options: RouteOptions & {
routePath: string;
path: string;
prefix: string;
config: {
metrics: {
routeId: string;
fastifyPrefix?: string;
routesPrefix?: string;
};
};
}
) => string;
type CommonRouteOptions = {
prefix?: string;
hits?: boolean;
requestSize?: boolean;
responseTime?: boolean;
responseSize?: boolean;
errors?: boolean;
};
type DynamicMode = {
mode?: 'dynamic';
getLabel?: GetDynamicRouteLabel;
} & CommonRouteOptions;
type StaticMode = {
mode?: 'static';
getLabel?: GetStaticRouteLabel;
} & CommonRouteOptions;
type SamplerOptions = {
sampleInterval?: number;
eventLoopOptions?: {
resolution: number;
};
};
type MetricsInstanceDecorator = {
namespace: string;
/** Normalized fastify prefix */
fastifyPrefix: string;
/** Normalized routes prefix */
routesPrefix: string;
client: Client;
sampler?: Sampler;
hrtime2us: (time: [number, number]) => number;
hrtime2ns: (time: [number, number]) => number;
hrtime2ms: (time: [number, number]) => number;
hrtime2s: (time: [number, number]) => number;
};
export interface MetricsPluginOptions {
client?: ClientOptions | CustomClient;
routes?: boolean | StaticMode | DynamicMode;
health?: boolean | SamplerOptions;
}
export { ClientOptions, CustomClient, StaticMode, DynamicMode, SamplerOptions };
export const MetricsPluginCallback: FastifyPluginCallback<MetricsPluginOptions>;
export const MetricsPluginAsync: FastifyPluginAsync<MetricsPluginOptions>;
export default MetricsPluginCallback;
declare module 'fastify' {
interface FastifyInstance {
metrics: MetricsInstanceDecorator;
}
interface FastifyRequest {
sendTimingMetric: typeof Client.prototype.timing;
sendCounterMetric: typeof Client.prototype.counter;
sendGaugeMetric: typeof Client.prototype.gauge;
sendSetMetric: typeof Client.prototype.set;
getMetricLabel: () => string;
}
interface FastifyReply {
sendTimingMetric: typeof Client.prototype.timing;
sendCounterMetric: typeof Client.prototype.counter;
sendGaugeMetric: typeof Client.prototype.gauge;
sendSetMetric: typeof Client.prototype.set;
getMetricLabel: () => string;
}
interface FastifyContextConfig {
metrics: {
/** The id for this route that will be used for the label */
routeId: string;
/** Normalized fastify prefix for this route */
fastifyPrefix?: string;
/** Normalized prefix of the routes */
routesPrefix?: string;
};
}
}