@@ -20,6 +20,10 @@ function extractBucket (instance, key) {
2020 }
2121}
2222
23+ function getMetricCount ( s ) {
24+ return s . replace ( / ^ # .* $ \n | ^ $ \n / gm, '' ) . trim ( ) . split ( '\n' ) . length ;
25+ }
26+
2327describe ( 'index' , ( ) => {
2428 beforeEach ( ( ) => {
2529 promClient . register . clear ( ) ;
@@ -342,7 +346,7 @@ describe('index', () => {
342346
343347 describe ( 'usage of normalizePath()' , ( ) => {
344348
345- it ( 'normalizePath can be replaced gloablly ' , done => {
349+ it ( 'normalizePath can be replaced globally ' , done => {
346350 const app = express ( ) ;
347351 const original = bundle . normalizePath ;
348352 bundle . normalizePath = ( ) => 'dummy' ;
@@ -366,6 +370,40 @@ describe('index', () => {
366370 } ) ;
367371 } ) ;
368372
373+ it ( 'respects pruneAgedBuckets' , done => {
374+ const app = express ( ) ;
375+ const metricsApp = express ( ) ;
376+ const bundled = bundle ( {
377+ metricsApp,
378+ metricType : 'summary' ,
379+ includePath : true ,
380+ maxAgeSeconds : 1 ,
381+ percentiles : [ 0.5 ] ,
382+ ageBuckets : 1 ,
383+ pruneAgedBuckets : true ,
384+ } ) ;
385+
386+ app . use ( bundled ) ;
387+
388+ const agent = supertest ( app ) ;
389+ const metricsAgent = supertest ( metricsApp ) ;
390+ agent . get ( '/foo' )
391+ . then ( ( ) => metricsAgent . get ( '/metrics' ) )
392+ . then ( response => {
393+ expect ( response . status ) . toBe ( 200 ) ;
394+ // up + bucket, sum, count
395+ expect ( getMetricCount ( response . text ) ) . toBe ( 4 ) ;
396+ } )
397+ . then ( ( ) => new Promise ( r => setTimeout ( r , 1010 ) ) )
398+ . then ( ( ) => metricsAgent . get ( '/metrics' ) )
399+ . then ( response => {
400+ expect ( response . status ) . toBe ( 200 ) ;
401+ // only up
402+ expect ( getMetricCount ( response . text ) ) . toBe ( 1 ) ;
403+ } )
404+ . finally ( done ) ;
405+ } ) ;
406+
369407 it ( 'normalizePath function can be overridden' , done => {
370408 const app = express ( ) ;
371409 const instance = bundle ( {
0 commit comments