File tree 1 file changed +33
-0
lines changed 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,39 @@ describe('Exemplars', () => {
122
122
} ) . toThrowError ( 'Label set size must be smaller than 128 UTF-8 chars' ) ;
123
123
} ) ;
124
124
125
+ it ( 'should time request, with exemplar' , async ( ) => {
126
+ jest . useFakeTimers ( 'modern' ) ;
127
+ jest . setSystemTime ( 0 ) ;
128
+ const histogramInstance = new Histogram ( {
129
+ name : 'histogram_start_timer_exemplar_test' ,
130
+ help : 'test' ,
131
+ labelNames : [ 'method' , 'code' ] ,
132
+ enableExemplars : true ,
133
+ } ) ;
134
+ const end = histogramInstance . startTimer ( {
135
+ method : 'get' ,
136
+ code : '200' ,
137
+ } ) ;
138
+
139
+ jest . advanceTimersByTime ( 500 ) ;
140
+ end ( ) ;
141
+
142
+ const valuePair = getValueByLabel (
143
+ 0.5 ,
144
+ ( await histogramInstance . get ( ) ) . values ,
145
+ ) ;
146
+ expect ( valuePair . value ) . toEqual ( 1 ) ;
147
+ jest . useRealTimers ( ) ;
148
+ } ) ;
149
+
150
+ function getValueByLabel ( label , values , key ) {
151
+ return values . reduce ( ( acc , val ) => {
152
+ if ( val . labels && val . labels [ key || 'le' ] === label ) {
153
+ acc = val ;
154
+ }
155
+ return acc ;
156
+ } , { } ) ;
157
+ }
125
158
function getValuesByLabel ( label , values , key ) {
126
159
return values . reduce ( ( acc , val ) => {
127
160
if ( val . labels && val . labels [ key || 'le' ] === label ) {
You can’t perform that action at this time.
0 commit comments