1414 * limitations under the License.
1515 */
1616
17- import { ObserverResult } from '@opentelemetry/api' ;
17+ import { HrTime , ObserverResult } from '@opentelemetry/api' ;
1818import {
1919 CounterMetric ,
20+ CounterSumAggregator ,
2021 Meter ,
2122 MeterProvider ,
2223 ObserverMetric ,
24+ Point ,
2325} from '@opentelemetry/metrics' ;
2426import * as assert from 'assert' ;
2527import * as http from 'http' ;
2628import { PrometheusExporter } from '../src' ;
2729
30+ const mockedHrTime : HrTime = [ 1586347902211 , 0 ] ;
31+ const mockedTimeMS = 1586347902211000 ;
32+
2833describe ( 'PrometheusExporter' , ( ) => {
34+ let toPoint : ( ) => Point ;
35+ before ( ( ) => {
36+ toPoint = CounterSumAggregator . prototype . toPoint ;
37+ CounterSumAggregator . prototype . toPoint = function ( ) : Point {
38+ const point = toPoint . apply ( this ) ;
39+ point . timestamp = mockedHrTime ;
40+ return point ;
41+ } ;
42+ } ) ;
43+ after ( ( ) => {
44+ CounterSumAggregator . prototype . toPoint = toPoint ;
45+ } ) ;
2946 describe ( 'constructor' , ( ) => {
3047 it ( 'should construct an exporter' , ( ) => {
3148 const exporter = new PrometheusExporter ( ) ;
@@ -209,7 +226,7 @@ describe('PrometheusExporter', () => {
209226 assert . deepStrictEqual ( lines , [
210227 '# HELP counter a test description' ,
211228 '# TYPE counter counter' ,
212- ' counter{key1="labelValue1"} 20' ,
229+ ` counter{key1="labelValue1"} 20 ${ mockedTimeMS } ` ,
213230 '' ,
214231 ] ) ;
215232
@@ -266,7 +283,7 @@ describe('PrometheusExporter', () => {
266283 } ) ;
267284 } ) ;
268285
269- it ( 'should export multiple labelsets ' , done => {
286+ it ( 'should export multiple labels ' , done => {
270287 const counter = meter . createCounter ( 'counter' , {
271288 description : 'a test description' ,
272289 labelKeys : [ 'counterKey1' ] ,
@@ -285,8 +302,8 @@ describe('PrometheusExporter', () => {
285302 assert . deepStrictEqual ( lines , [
286303 '# HELP counter a test description' ,
287304 '# TYPE counter counter' ,
288- ' counter{counterKey1="labelValue1"} 10' ,
289- ' counter{counterKey1="labelValue2"} 20' ,
305+ ` counter{counterKey1="labelValue1"} 10 ${ mockedTimeMS } ` ,
306+ ` counter{counterKey1="labelValue2"} 20 ${ mockedTimeMS } ` ,
290307 '' ,
291308 ] ) ;
292309
@@ -330,7 +347,7 @@ describe('PrometheusExporter', () => {
330347 assert . deepStrictEqual ( lines , [
331348 '# HELP counter description missing' ,
332349 '# TYPE counter counter' ,
333- ' counter 10' ,
350+ ` counter 10 ${ mockedTimeMS } ` ,
334351 '' ,
335352 ] ) ;
336353
@@ -356,7 +373,7 @@ describe('PrometheusExporter', () => {
356373 assert . deepStrictEqual ( lines , [
357374 '# HELP counter_bad_name description missing' ,
358375 '# TYPE counter_bad_name counter' ,
359- ' counter_bad_name 10' ,
376+ ` counter_bad_name 10 ${ mockedTimeMS } ` ,
360377 '' ,
361378 ] ) ;
362379
@@ -432,7 +449,7 @@ describe('PrometheusExporter', () => {
432449 assert . deepStrictEqual ( lines , [
433450 '# HELP test_prefix_counter description missing' ,
434451 '# TYPE test_prefix_counter counter' ,
435- ' test_prefix_counter 10' ,
452+ ` test_prefix_counter 10 ${ mockedTimeMS } ` ,
436453 '' ,
437454 ] ) ;
438455
@@ -461,7 +478,7 @@ describe('PrometheusExporter', () => {
461478 assert . deepStrictEqual ( lines , [
462479 '# HELP counter description missing' ,
463480 '# TYPE counter counter' ,
464- ' counter 10' ,
481+ ` counter 10 ${ mockedTimeMS } ` ,
465482 '' ,
466483 ] ) ;
467484
@@ -490,7 +507,7 @@ describe('PrometheusExporter', () => {
490507 assert . deepStrictEqual ( lines , [
491508 '# HELP counter description missing' ,
492509 '# TYPE counter counter' ,
493- ' counter 10' ,
510+ ` counter 10 ${ mockedTimeMS } ` ,
494511 '' ,
495512 ] ) ;
496513
0 commit comments