@@ -47,7 +47,7 @@ func TestConvertMetrics(t *testing.T) {
47
47
expected : []metricdata.Metrics {},
48
48
},
49
49
{
50
- desc : "normal Histogram, gauges, and sums" ,
50
+ desc : "normal Histogram, summary, gauges, and sums" ,
51
51
input : []* ocmetricdata.Metric {
52
52
{
53
53
Descriptor : ocmetricdata.Descriptor {
@@ -285,6 +285,54 @@ func TestConvertMetrics(t *testing.T) {
285
285
},
286
286
},
287
287
},
288
+ }, {
289
+ Descriptor : ocmetricdata.Descriptor {
290
+ Name : "foo.com/summary-a" ,
291
+ Description : "a testing summary" ,
292
+ Unit : ocmetricdata .UnitMilliseconds ,
293
+ Type : ocmetricdata .TypeSummary ,
294
+ LabelKeys : []ocmetricdata.LabelKey {
295
+ {Key : "g" },
296
+ {Key : "h" },
297
+ },
298
+ },
299
+ TimeSeries : []* ocmetricdata.TimeSeries {
300
+ {
301
+ LabelValues : []ocmetricdata.LabelValue {
302
+ {
303
+ Value : "ding" ,
304
+ Present : true ,
305
+ }, {
306
+ Value : "dong" ,
307
+ Present : true ,
308
+ },
309
+ },
310
+ Points : []ocmetricdata.Point {
311
+ ocmetricdata .NewSummaryPoint (endTime1 , & ocmetricdata.Summary {
312
+ Count : 10 ,
313
+ Sum : 13.2 ,
314
+ HasCountAndSum : true ,
315
+ Snapshot : ocmetricdata.Snapshot {
316
+ Percentiles : map [float64 ]float64 {
317
+ 50.0 : 1.0 ,
318
+ 0.0 : 0.1 ,
319
+ 100.0 : 10.4 ,
320
+ },
321
+ },
322
+ }),
323
+ ocmetricdata .NewSummaryPoint (endTime2 , & ocmetricdata.Summary {
324
+ Count : 12 ,
325
+ Snapshot : ocmetricdata.Snapshot {
326
+ Percentiles : map [float64 ]float64 {
327
+ 0.0 : 0.2 ,
328
+ 50.0 : 1.1 ,
329
+ 100.0 : 10.5 ,
330
+ },
331
+ },
332
+ }),
333
+ },
334
+ },
335
+ },
288
336
},
289
337
},
290
338
expected : []metricdata.Metrics {
@@ -489,6 +537,64 @@ func TestConvertMetrics(t *testing.T) {
489
537
},
490
538
},
491
539
},
540
+ }, {
541
+ Name : "foo.com/summary-a" ,
542
+ Description : "a testing summary" ,
543
+ Unit : "ms" ,
544
+ Data : metricdata.Summary {
545
+ DataPoints : []metricdata.SummaryDataPoint {
546
+ {
547
+ Attributes : attribute .NewSet (attribute.KeyValue {
548
+ Key : attribute .Key ("g" ),
549
+ Value : attribute .StringValue ("ding" ),
550
+ }, attribute.KeyValue {
551
+ Key : attribute .Key ("h" ),
552
+ Value : attribute .StringValue ("dong" ),
553
+ }),
554
+ Time : endTime1 ,
555
+ Count : 10 ,
556
+ Sum : 13.2 ,
557
+ QuantileValues : []metricdata.QuantileValue {
558
+ {
559
+ Quantile : 0.0 ,
560
+ Value : 0.1 ,
561
+ },
562
+ {
563
+ Quantile : 0.5 ,
564
+ Value : 1.0 ,
565
+ },
566
+ {
567
+ Quantile : 1.0 ,
568
+ Value : 10.4 ,
569
+ },
570
+ },
571
+ }, {
572
+ Attributes : attribute .NewSet (attribute.KeyValue {
573
+ Key : attribute .Key ("g" ),
574
+ Value : attribute .StringValue ("ding" ),
575
+ }, attribute.KeyValue {
576
+ Key : attribute .Key ("h" ),
577
+ Value : attribute .StringValue ("dong" ),
578
+ }),
579
+ Time : endTime2 ,
580
+ Count : 12 ,
581
+ QuantileValues : []metricdata.QuantileValue {
582
+ {
583
+ Quantile : 0.0 ,
584
+ Value : 0.2 ,
585
+ },
586
+ {
587
+ Quantile : 0.5 ,
588
+ Value : 1.1 ,
589
+ },
590
+ {
591
+ Quantile : 1.0 ,
592
+ Value : 10.5 ,
593
+ },
594
+ },
595
+ },
596
+ },
597
+ },
492
598
},
493
599
},
494
600
},
@@ -586,7 +692,7 @@ func TestConvertMetrics(t *testing.T) {
586
692
},
587
693
},
588
694
},
589
- expectedErr : errNegativeDistributionCount ,
695
+ expectedErr : errNegativeCount ,
590
696
},
591
697
{
592
698
desc : "histogram with negative bucket count" ,
@@ -638,6 +744,82 @@ func TestConvertMetrics(t *testing.T) {
638
744
},
639
745
expectedErr : errMismatchedValueTypes ,
640
746
},
747
+ {
748
+ desc : "summary with mismatched attributes" ,
749
+ input : []* ocmetricdata.Metric {
750
+ {
751
+ Descriptor : ocmetricdata.Descriptor {
752
+ Name : "foo.com/summary-mismatched" ,
753
+ Description : "a mismatched summary" ,
754
+ Unit : ocmetricdata .UnitMilliseconds ,
755
+ Type : ocmetricdata .TypeSummary ,
756
+ LabelKeys : []ocmetricdata.LabelKey {
757
+ {Key : "g" },
758
+ },
759
+ },
760
+ TimeSeries : []* ocmetricdata.TimeSeries {
761
+ {
762
+ LabelValues : []ocmetricdata.LabelValue {
763
+ {
764
+ Value : "ding" ,
765
+ Present : true ,
766
+ }, {
767
+ Value : "dong" ,
768
+ Present : true ,
769
+ },
770
+ },
771
+ Points : []ocmetricdata.Point {
772
+ ocmetricdata .NewSummaryPoint (endTime1 , & ocmetricdata.Summary {
773
+ Count : 10 ,
774
+ Sum : 13.2 ,
775
+ HasCountAndSum : true ,
776
+ Snapshot : ocmetricdata.Snapshot {
777
+ Percentiles : map [float64 ]float64 {
778
+ 0.0 : 0.1 ,
779
+ 0.5 : 1.0 ,
780
+ 1.0 : 10.4 ,
781
+ },
782
+ },
783
+ }),
784
+ },
785
+ },
786
+ },
787
+ },
788
+ },
789
+ expectedErr : errMismatchedAttributeKeyValues ,
790
+ },
791
+ {
792
+ desc : "summary with negative count" ,
793
+ input : []* ocmetricdata.Metric {
794
+ {
795
+ Descriptor : ocmetricdata.Descriptor {
796
+ Name : "foo.com/summary-negative" ,
797
+ Description : "a negative count summary" ,
798
+ Unit : ocmetricdata .UnitMilliseconds ,
799
+ Type : ocmetricdata .TypeSummary ,
800
+ },
801
+ TimeSeries : []* ocmetricdata.TimeSeries {
802
+ {
803
+ Points : []ocmetricdata.Point {
804
+ ocmetricdata .NewSummaryPoint (endTime1 , & ocmetricdata.Summary {
805
+ Count : - 10 ,
806
+ Sum : 13.2 ,
807
+ HasCountAndSum : true ,
808
+ Snapshot : ocmetricdata.Snapshot {
809
+ Percentiles : map [float64 ]float64 {
810
+ 0.0 : 0.1 ,
811
+ 0.5 : 1.0 ,
812
+ 1.0 : 10.4 ,
813
+ },
814
+ },
815
+ }),
816
+ },
817
+ },
818
+ },
819
+ },
820
+ },
821
+ expectedErr : errNegativeCount ,
822
+ },
641
823
{
642
824
desc : "histogram with invalid span context exemplar" ,
643
825
input : []* ocmetricdata.Metric {
@@ -722,6 +904,28 @@ func TestConvertMetrics(t *testing.T) {
722
904
},
723
905
expectedErr : errMismatchedValueTypes ,
724
906
},
907
+ {
908
+ desc : "summary with non-summary datapoint type" ,
909
+ input : []* ocmetricdata.Metric {
910
+ {
911
+ Descriptor : ocmetricdata.Descriptor {
912
+ Name : "foo.com/bad-point" ,
913
+ Description : "a bad type" ,
914
+ Unit : ocmetricdata .UnitDimensionless ,
915
+ Type : ocmetricdata .TypeSummary ,
916
+ },
917
+ TimeSeries : []* ocmetricdata.TimeSeries {
918
+ {
919
+ Points : []ocmetricdata.Point {
920
+ ocmetricdata .NewDistributionPoint (endTime1 , & ocmetricdata.Distribution {}),
921
+ },
922
+ StartTime : startTime ,
923
+ },
924
+ },
925
+ },
926
+ },
927
+ expectedErr : errMismatchedValueTypes ,
928
+ },
725
929
{
726
930
desc : "unsupported Gauge Distribution type" ,
727
931
input : []* ocmetricdata.Metric {
@@ -740,7 +944,7 @@ func TestConvertMetrics(t *testing.T) {
740
944
t .Run (tc .desc , func (t * testing.T ) {
741
945
output , err := ConvertMetrics (tc .input )
742
946
if ! errors .Is (err , tc .expectedErr ) {
743
- t .Errorf ("convertAggregation (%+v) = err(%v), want err(%v)" , tc .input , err , tc .expectedErr )
947
+ t .Errorf ("ConvertMetrics (%+v) = err(%v), want err(%v)" , tc .input , err , tc .expectedErr )
744
948
}
745
949
metricdatatest .AssertEqual [metricdata.ScopeMetrics ](t ,
746
950
metricdata.ScopeMetrics {Metrics : tc .expected },
0 commit comments