@@ -50,6 +50,21 @@ func (m *mockExporter) Shutdown(_ context.Context) error {
50
50
return nil
51
51
}
52
52
53
+ func checkMetricTemporality (t * testing.T , ms metricdata.Metrics , metricType MetricType , expectedAggregationTemporality metricdata.Temporality ) {
54
+ switch metricType {
55
+ case MetricTypeSum :
56
+ sumData , ok := ms .Data .(metricdata.Sum [int64 ])
57
+ require .True (t , ok , "expected Sum data type" )
58
+ assert .Equal (t , expectedAggregationTemporality , sumData .Temporality )
59
+ case MetricTypeHistogram :
60
+ histogramData , ok := ms .Data .(metricdata.Histogram [int64 ])
61
+ require .True (t , ok , "expected Histogram data type" )
62
+ assert .Equal (t , expectedAggregationTemporality , histogramData .Temporality )
63
+ default :
64
+ t .Fatalf ("unsupported metric type: %v" , metricType )
65
+ }
66
+ }
67
+
53
68
func TestFixedNumberOfMetrics (t * testing.T ) {
54
69
// arrange
55
70
cfg := & Config {
@@ -98,6 +113,72 @@ func TestRateOfMetrics(t *testing.T) {
98
113
assert .LessOrEqual (t , len (m .rms ), 20 , "there should have been less than 20 metrics, had %d" , len (m .rms ))
99
114
}
100
115
116
+ func TestMetricsWithTemporality (t * testing.T ) {
117
+ tests := []struct {
118
+ name string
119
+ metricType MetricType
120
+ aggregationTemporality AggregationTemporality
121
+ expectedAggregationTemporality metricdata.Temporality
122
+ }{
123
+ {
124
+ name : "Sum: delta temporality" ,
125
+ metricType : MetricTypeSum ,
126
+ aggregationTemporality : AggregationTemporality (metricdata .DeltaTemporality ),
127
+ expectedAggregationTemporality : metricdata .DeltaTemporality ,
128
+ },
129
+ {
130
+ name : "Sum: cumulative temporality" ,
131
+ metricType : MetricTypeSum ,
132
+ aggregationTemporality : AggregationTemporality (metricdata .CumulativeTemporality ),
133
+ expectedAggregationTemporality : metricdata .CumulativeTemporality ,
134
+ },
135
+ {
136
+ name : "Histogram: delta temporality" ,
137
+ metricType : MetricTypeHistogram ,
138
+ aggregationTemporality : AggregationTemporality (metricdata .DeltaTemporality ),
139
+ expectedAggregationTemporality : metricdata .DeltaTemporality ,
140
+ },
141
+ {
142
+ name : "Histogram: cumulative temporality" ,
143
+ metricType : MetricTypeHistogram ,
144
+ aggregationTemporality : AggregationTemporality (metricdata .CumulativeTemporality ),
145
+ expectedAggregationTemporality : metricdata .CumulativeTemporality ,
146
+ },
147
+ }
148
+
149
+ for _ , tt := range tests {
150
+ t .Run (tt .name , func (t * testing.T ) {
151
+ // arrange
152
+ cfg := & Config {
153
+ Config : common.Config {
154
+ WorkerCount : 1 ,
155
+ },
156
+ NumMetrics : 1 ,
157
+ MetricName : "test" ,
158
+ MetricType : tt .metricType ,
159
+ AggregationTemporality : tt .aggregationTemporality ,
160
+ }
161
+ m := & mockExporter {}
162
+ expFunc := func () (sdkmetric.Exporter , error ) {
163
+ return m , nil
164
+ }
165
+
166
+ // act
167
+ logger , _ := zap .NewDevelopment ()
168
+ require .NoError (t , run (cfg , expFunc , logger ))
169
+
170
+ time .Sleep (1 * time .Second )
171
+
172
+ // assert
173
+ require .Len (t , m .rms , 1 )
174
+ ms := m .rms [0 ].ScopeMetrics [0 ].Metrics [0 ]
175
+ assert .Equal (t , "test" , ms .Name )
176
+
177
+ checkMetricTemporality (t , ms , tt .metricType , tt .expectedAggregationTemporality )
178
+ })
179
+ }
180
+ }
181
+
101
182
func TestUnthrottled (t * testing.T ) {
102
183
// arrange
103
184
cfg := & Config {
0 commit comments