@@ -27,8 +27,9 @@ import {
27
27
MetricRecord ,
28
28
Aggregator ,
29
29
MetricDescriptor ,
30
- LastValueAggregator ,
31
30
UpDownCounterMetric ,
31
+ Distribution ,
32
+ MinMaxLastSumCountAggregator ,
32
33
} from '../src' ;
33
34
import * as api from '@opentelemetry/api' ;
34
35
import { NoopLogger , hrTime , hrTimeToNanoseconds } from '@opentelemetry/core' ;
@@ -562,7 +563,16 @@ describe('Meter', () => {
562
563
563
564
await meter . collect ( ) ;
564
565
const [ record1 ] = meter . getBatcher ( ) . checkPointSet ( ) ;
565
- assert . deepStrictEqual ( record1 . aggregator . toPoint ( ) . value as number , 0 ) ;
566
+ assert . deepStrictEqual (
567
+ record1 . aggregator . toPoint ( ) . value as Distribution ,
568
+ {
569
+ count : 0 ,
570
+ last : 0 ,
571
+ max : - Infinity ,
572
+ min : Infinity ,
573
+ sum : 0 ,
574
+ }
575
+ ) ;
566
576
} ) ;
567
577
568
578
it ( 'should not set the instrument data when disabled' , async ( ) => {
@@ -574,7 +584,16 @@ describe('Meter', () => {
574
584
575
585
await meter . collect ( ) ;
576
586
const [ record1 ] = meter . getBatcher ( ) . checkPointSet ( ) ;
577
- assert . deepStrictEqual ( record1 . aggregator . toPoint ( ) . value as number , 0 ) ;
587
+ assert . deepStrictEqual (
588
+ record1 . aggregator . toPoint ( ) . value as Distribution ,
589
+ {
590
+ count : 0 ,
591
+ last : 0 ,
592
+ max : - Infinity ,
593
+ min : Infinity ,
594
+ sum : 0 ,
595
+ }
596
+ ) ;
578
597
} ) ;
579
598
580
599
it (
@@ -591,8 +610,14 @@ describe('Meter', () => {
591
610
await meter . collect ( ) ;
592
611
const [ record1 ] = meter . getBatcher ( ) . checkPointSet ( ) ;
593
612
assert . deepStrictEqual (
594
- record1 . aggregator . toPoint ( ) . value as number ,
595
- 50
613
+ record1 . aggregator . toPoint ( ) . value as Distribution ,
614
+ {
615
+ count : 2 ,
616
+ last : 50 ,
617
+ max : 50 ,
618
+ min : - 10 ,
619
+ sum : 40 ,
620
+ }
596
621
) ;
597
622
assert . ok (
598
623
hrTimeToNanoseconds ( record1 . aggregator . toPoint ( ) . timestamp ) >
@@ -612,8 +637,14 @@ describe('Meter', () => {
612
637
await meter . collect ( ) ;
613
638
const [ record1 ] = meter . getBatcher ( ) . checkPointSet ( ) ;
614
639
assert . deepStrictEqual (
615
- record1 . aggregator . toPoint ( ) . value as number ,
616
- 100
640
+ record1 . aggregator . toPoint ( ) . value as Distribution ,
641
+ {
642
+ count : 2 ,
643
+ last : 100 ,
644
+ max : 100 ,
645
+ min : 10 ,
646
+ sum : 110 ,
647
+ }
617
648
) ;
618
649
assert . strictEqual ( boundValueRecorder1 , boundValueRecorder2 ) ;
619
650
} ) ;
@@ -809,10 +840,34 @@ describe('Meter', () => {
809
840
assert . strictEqual ( hashLabels ( metric3 . labels ) , '|#app:app2,core:1' ) ;
810
841
assert . strictEqual ( hashLabels ( metric4 . labels ) , '|#app:app2,core:2' ) ;
811
842
812
- ensureMetric ( metric1 , 'cpu_temp_per_app' , 67 ) ;
813
- ensureMetric ( metric2 , 'cpu_temp_per_app' , 69 ) ;
814
- ensureMetric ( metric3 , 'cpu_temp_per_app' , 67 ) ;
815
- ensureMetric ( metric4 , 'cpu_temp_per_app' , 69 ) ;
843
+ ensureMetric ( metric1 , 'cpu_temp_per_app' , {
844
+ count : 1 ,
845
+ last : 67 ,
846
+ max : 67 ,
847
+ min : 67 ,
848
+ sum : 67 ,
849
+ } ) ;
850
+ ensureMetric ( metric2 , 'cpu_temp_per_app' , {
851
+ count : 1 ,
852
+ last : 69 ,
853
+ max : 69 ,
854
+ min : 69 ,
855
+ sum : 69 ,
856
+ } ) ;
857
+ ensureMetric ( metric3 , 'cpu_temp_per_app' , {
858
+ count : 1 ,
859
+ last : 67 ,
860
+ max : 67 ,
861
+ min : 67 ,
862
+ sum : 67 ,
863
+ } ) ;
864
+ ensureMetric ( metric4 , 'cpu_temp_per_app' , {
865
+ count : 1 ,
866
+ last : 69 ,
867
+ max : 69 ,
868
+ min : 69 ,
869
+ sum : 69 ,
870
+ } ) ;
816
871
817
872
const metric5 = cpuUsageMetricRecords [ 0 ] ;
818
873
const metric6 = cpuUsageMetricRecords [ 1 ] ;
@@ -823,10 +878,34 @@ describe('Meter', () => {
823
878
assert . strictEqual ( hashLabels ( metric3 . labels ) , '|#app:app2,core:1' ) ;
824
879
assert . strictEqual ( hashLabels ( metric4 . labels ) , '|#app:app2,core:2' ) ;
825
880
826
- ensureMetric ( metric5 , 'cpu_usage_per_app' , 2.1 ) ;
827
- ensureMetric ( metric6 , 'cpu_usage_per_app' , 3.1 ) ;
828
- ensureMetric ( metric7 , 'cpu_usage_per_app' , 1.2 ) ;
829
- ensureMetric ( metric8 , 'cpu_usage_per_app' , 4.5 ) ;
881
+ ensureMetric ( metric5 , 'cpu_usage_per_app' , {
882
+ count : 1 ,
883
+ last : 2.1 ,
884
+ max : 2.1 ,
885
+ min : 2.1 ,
886
+ sum : 2.1 ,
887
+ } ) ;
888
+ ensureMetric ( metric6 , 'cpu_usage_per_app' , {
889
+ count : 1 ,
890
+ last : 3.1 ,
891
+ max : 3.1 ,
892
+ min : 3.1 ,
893
+ sum : 3.1 ,
894
+ } ) ;
895
+ ensureMetric ( metric7 , 'cpu_usage_per_app' , {
896
+ count : 1 ,
897
+ last : 1.2 ,
898
+ max : 1.2 ,
899
+ min : 1.2 ,
900
+ sum : 1.2 ,
901
+ } ) ;
902
+ ensureMetric ( metric8 , 'cpu_usage_per_app' , {
903
+ count : 1 ,
904
+ last : 4.5 ,
905
+ max : 4.5 ,
906
+ min : 4.5 ,
907
+ sum : 4.5 ,
908
+ } ) ;
830
909
} ) ;
831
910
832
911
it ( 'should not observe values when timeout' , done => {
@@ -856,9 +935,15 @@ describe('Meter', () => {
856
935
const value = cpuUsageMetric
857
936
. bind ( { foo : 'bar' } )
858
937
. getAggregator ( )
859
- . toPoint ( ) . value as number ;
860
-
861
- assert . strictEqual ( value , 0 ) ;
938
+ . toPoint ( ) . value as Distribution ;
939
+
940
+ assert . deepStrictEqual ( value , {
941
+ count : 0 ,
942
+ last : 0 ,
943
+ max : - Infinity ,
944
+ min : Infinity ,
945
+ sum : 0 ,
946
+ } ) ;
862
947
assert . strictEqual ( cpuUsageMetricRecords . length , 0 ) ;
863
948
done ( ) ;
864
949
} ) ;
@@ -961,13 +1046,17 @@ class CustomBatcher extends Batcher {
961
1046
}
962
1047
}
963
1048
964
- function ensureMetric ( metric : MetricRecord , name ?: string , value ?: number ) {
965
- assert . ok ( metric . aggregator instanceof LastValueAggregator ) ;
966
- const lastValue = metric . aggregator . toPoint ( ) . value ;
967
- if ( typeof value === 'number' ) {
968
- assert . strictEqual ( lastValue , value ) ;
1049
+ function ensureMetric (
1050
+ metric : MetricRecord ,
1051
+ name ?: string ,
1052
+ value ?: Distribution
1053
+ ) {
1054
+ assert . ok ( metric . aggregator instanceof MinMaxLastSumCountAggregator ) ;
1055
+ const distribution = metric . aggregator . toPoint ( ) . value as Distribution ;
1056
+ if ( value ) {
1057
+ assert . deepStrictEqual ( distribution , value ) ;
969
1058
} else {
970
- assert . ok ( lastValue >= 0 && lastValue <= 1 ) ;
1059
+ assert . ok ( distribution . last >= 0 && distribution . last <= 1 ) ;
971
1060
}
972
1061
const descriptor = metric . descriptor ;
973
1062
assert . strictEqual ( descriptor . name , name || 'name' ) ;
0 commit comments