@@ -31,6 +31,7 @@ type AggregationData interface {
3131 clone () AggregationData
3232 equal (other AggregationData ) bool
3333 toPoint (t metricdata.Type , time time.Time ) metricdata.Point
34+ StartTime () time.Time
3435}
3536
3637const epsilon = 1e-9
@@ -40,6 +41,7 @@ const epsilon = 1e-9
4041//
4142// Most users won't directly access count data.
4243type CountData struct {
44+ Start time.Time
4345 Value int64
4446}
4547
@@ -50,7 +52,7 @@ func (a *CountData) addSample(_ float64, _ map[string]interface{}, _ time.Time)
5052}
5153
5254func (a * CountData ) clone () AggregationData {
53- return & CountData {Value : a .Value }
55+ return & CountData {Value : a .Value , Start : a . Start }
5456}
5557
5658func (a * CountData ) equal (other AggregationData ) bool {
@@ -59,7 +61,7 @@ func (a *CountData) equal(other AggregationData) bool {
5961 return false
6062 }
6163
62- return a .Value == a2 .Value
64+ return a .Start . Equal ( a2 . Start ) && a . Value == a2 .Value
6365}
6466
6567func (a * CountData ) toPoint (metricType metricdata.Type , t time.Time ) metricdata.Point {
@@ -71,11 +73,17 @@ func (a *CountData) toPoint(metricType metricdata.Type, t time.Time) metricdata.
7173 }
7274}
7375
76+ // StartTime returns the start time of the data being aggregated by CountData.
77+ func (a * CountData ) StartTime () time.Time {
78+ return a .Start
79+ }
80+
7481// SumData is the aggregated data for the Sum aggregation.
7582// A sum aggregation processes data and sums up the recordings.
7683//
7784// Most users won't directly access sum data.
7885type SumData struct {
86+ Start time.Time
7987 Value float64
8088}
8189
@@ -86,15 +94,15 @@ func (a *SumData) addSample(v float64, _ map[string]interface{}, _ time.Time) {
8694}
8795
8896func (a * SumData ) clone () AggregationData {
89- return & SumData {Value : a .Value }
97+ return & SumData {Value : a .Value , Start : a . Start }
9098}
9199
92100func (a * SumData ) equal (other AggregationData ) bool {
93101 a2 , ok := other .(* SumData )
94102 if ! ok {
95103 return false
96104 }
97- return math .Pow (a .Value - a2 .Value , 2 ) < epsilon
105+ return a . Start . Equal ( a2 . Start ) && math .Pow (a .Value - a2 .Value , 2 ) < epsilon
98106}
99107
100108func (a * SumData ) toPoint (metricType metricdata.Type , t time.Time ) metricdata.Point {
@@ -108,6 +116,11 @@ func (a *SumData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Po
108116 }
109117}
110118
119+ // StartTime returns the start time of the data being aggregated by SumData.
120+ func (a * SumData ) StartTime () time.Time {
121+ return a .Start
122+ }
123+
111124// DistributionData is the aggregated data for the
112125// Distribution aggregation.
113126//
@@ -126,16 +139,18 @@ type DistributionData struct {
126139 // an exemplar for the associated bucket, or nil.
127140 ExemplarsPerBucket []* metricdata.Exemplar
128141 bounds []float64 // histogram distribution of the values
142+ Start time.Time
129143}
130144
131- func newDistributionData (agg * Aggregation ) * DistributionData {
145+ func newDistributionData (agg * Aggregation , t time. Time ) * DistributionData {
132146 bucketCount := len (agg .Buckets ) + 1
133147 return & DistributionData {
134148 CountPerBucket : make ([]int64 , bucketCount ),
135149 ExemplarsPerBucket : make ([]* metricdata.Exemplar , bucketCount ),
136150 bounds : agg .Buckets ,
137151 Min : math .MaxFloat64 ,
138152 Max : math .SmallestNonzeroFloat64 ,
153+ Start : t ,
139154 }
140155}
141156
@@ -226,7 +241,11 @@ func (a *DistributionData) equal(other AggregationData) bool {
226241 return false
227242 }
228243 }
229- return a .Count == a2 .Count && a .Min == a2 .Min && a .Max == a2 .Max && math .Pow (a .Mean - a2 .Mean , 2 ) < epsilon && math .Pow (a .variance ()- a2 .variance (), 2 ) < epsilon
244+ return a .Start .Equal (a2 .Start ) &&
245+ a .Count == a2 .Count &&
246+ a .Min == a2 .Min &&
247+ a .Max == a2 .Max &&
248+ math .Pow (a .Mean - a2 .Mean , 2 ) < epsilon && math .Pow (a .variance ()- a2 .variance (), 2 ) < epsilon
230249}
231250
232251func (a * DistributionData ) toPoint (metricType metricdata.Type , t time.Time ) metricdata.Point {
@@ -256,6 +275,11 @@ func (a *DistributionData) toPoint(metricType metricdata.Type, t time.Time) metr
256275 }
257276}
258277
278+ // StartTime returns the start time of the data being aggregated by DistributionData.
279+ func (a * DistributionData ) StartTime () time.Time {
280+ return a .Start
281+ }
282+
259283// LastValueData returns the last value recorded for LastValue aggregation.
260284type LastValueData struct {
261285 Value float64
@@ -291,3 +315,22 @@ func (l *LastValueData) toPoint(metricType metricdata.Type, t time.Time) metricd
291315 panic ("unsupported metricdata.Type" )
292316 }
293317}
318+
319+ // StartTime returns an empty time value as start time is not recorded when using last value
320+ // aggregation.
321+ func (l * LastValueData ) StartTime () time.Time {
322+ return time.Time {}
323+ }
324+
325+ // ClearStart clears the Start field from data if present. Useful for testing in cases where the
326+ // start time will be nondeterministic.
327+ func ClearStart (data AggregationData ) {
328+ switch data := data .(type ) {
329+ case * CountData :
330+ data .Start = time.Time {}
331+ case * SumData :
332+ data .Start = time.Time {}
333+ case * DistributionData :
334+ data .Start = time.Time {}
335+ }
336+ }
0 commit comments