@@ -25,27 +25,42 @@ describe('Metrics middleware', () => {
2525 const mockEndTimer = jest . fn ( ) ;
2626 summary . startTimer . mockReturnValue ( mockEndTimer ) ;
2727
28- api . use ( metricsMiddleware ( { api : { version : 1 } as any , settings, summary : summary as any } ) ) . get (
29- '/test' ,
30- {
31- response : {
32- 200 : ajv . compile ( {
33- type : 'object' ,
34- properties : {
35- message : { type : 'string' } ,
28+ const histogram = { startTimer : jest . fn ( ) . mockReturnValue ( jest . fn ( ) ) } ;
29+ const responseSizeHistogram = { observe : jest . fn ( ) } ;
30+ const activeRequestsGauge = { inc : jest . fn ( ) , dec : jest . fn ( ) } ;
31+
32+ api
33+ . use (
34+ metricsMiddleware ( {
35+ api : { version : 1 } as any ,
36+ settings,
37+ summary : summary as any ,
38+ histogram : histogram as any ,
39+ responseSizeHistogram : responseSizeHistogram as any ,
40+ activeRequestsGauge : activeRequestsGauge as any ,
41+ } ) ,
42+ )
43+ . get (
44+ '/test' ,
45+ {
46+ response : {
47+ 200 : ajv . compile ( {
48+ type : 'object' ,
49+ properties : {
50+ message : { type : 'string' } ,
51+ } ,
52+ } ) ,
53+ } ,
54+ } ,
55+ async ( ) => {
56+ return {
57+ statusCode : 200 ,
58+ body : {
59+ message : 'Metrics test successful' ,
3660 } ,
37- } ) ,
61+ } ;
3862 } ,
39- } ,
40- async ( ) => {
41- return {
42- statusCode : 200 ,
43- body : {
44- message : 'Metrics test successful' ,
45- } ,
46- } ;
47- } ,
48- ) ;
63+ ) ;
4964 app . use ( api . router ) ;
5065 const response = await request ( app ) . get ( '/api/test' ) . set ( 'user-agent' , 'test' ) ;
5166 expect ( response . statusCode ) . toBe ( 200 ) ;
@@ -73,8 +88,22 @@ describe('Metrics middleware', () => {
7388 const mockEndTimer = jest . fn ( ) ;
7489 summary . startTimer . mockReturnValue ( mockEndTimer ) ;
7590
91+ const histogram = { startTimer : jest . fn ( ) . mockReturnValue ( jest . fn ( ) ) } ;
92+ const responseSizeHistogram = { observe : jest . fn ( ) } ;
93+ const activeRequestsGauge = { inc : jest . fn ( ) , dec : jest . fn ( ) } ;
94+
7695 api
77- . use ( metricsMiddleware ( { basePathRegex : new RegExp ( / ^ \/ a p i \/ / ) , api : { version : 1 } as any , settings, summary : summary as any } ) )
96+ . use (
97+ metricsMiddleware ( {
98+ basePathRegex : new RegExp ( / ^ \/ a p i \/ / ) ,
99+ api : { version : 1 } as any ,
100+ settings,
101+ summary : summary as any ,
102+ histogram : histogram as any ,
103+ responseSizeHistogram : responseSizeHistogram as any ,
104+ activeRequestsGauge : activeRequestsGauge as any ,
105+ } ) ,
106+ )
78107 . get (
79108 '/test' ,
80109 {
@@ -120,8 +149,22 @@ describe('Metrics middleware', () => {
120149 const mockEndTimer = jest . fn ( ) ;
121150 summary . startTimer . mockReturnValue ( mockEndTimer ) ;
122151
152+ const histogram = { startTimer : jest . fn ( ) . mockReturnValue ( jest . fn ( ) ) } ;
153+ const responseSizeHistogram = { observe : jest . fn ( ) } ;
154+ const activeRequestsGauge = { inc : jest . fn ( ) , dec : jest . fn ( ) } ;
155+
123156 api
124- . use ( metricsMiddleware ( { basePathRegex : new RegExp ( / ^ \/ a p i \/ / ) , api : { version : 1 } as any , settings, summary : summary as any } ) )
157+ . use (
158+ metricsMiddleware ( {
159+ basePathRegex : new RegExp ( / ^ \/ a p i \/ / ) ,
160+ api : { version : 1 } as any ,
161+ settings,
162+ summary : summary as any ,
163+ histogram : histogram as any ,
164+ responseSizeHistogram : responseSizeHistogram as any ,
165+ activeRequestsGauge : activeRequestsGauge as any ,
166+ } ) ,
167+ )
125168 . get (
126169 '/method.call/:id' ,
127170 {
0 commit comments