@@ -15,7 +15,7 @@ type Key string
15
15
16
16
type HistogramMetrics interface {
17
17
GetOrCreate (key Key , attributes pcommon.Map , startTimestamp pcommon.Timestamp ) Histogram
18
- BuildMetrics (pmetric.Metric , pcommon.Timestamp , pmetric.AggregationTemporality )
18
+ BuildMetrics (pmetric.Metric , pcommon.Timestamp , func ( Key , pcommon. Timestamp ) pcommon. Timestamp , pmetric.AggregationTemporality )
19
19
ClearExemplars ()
20
20
}
21
21
@@ -48,8 +48,7 @@ type explicitHistogram struct {
48
48
49
49
maxExemplarCount * int
50
50
51
- startTimestamp pcommon.Timestamp
52
- lastSeenTimestamp pcommon.Timestamp
51
+ startTimestamp pcommon.Timestamp
53
52
}
54
53
55
54
type exponentialHistogram struct {
@@ -60,8 +59,7 @@ type exponentialHistogram struct {
60
59
61
60
maxExemplarCount * int
62
61
63
- startTimestamp pcommon.Timestamp
64
- lastSeenTimestamp pcommon.Timestamp
62
+ startTimestamp pcommon.Timestamp
65
63
}
66
64
67
65
type generateStartTimestamp = func (Key ) pcommon.Timestamp
@@ -91,31 +89,26 @@ func (m *explicitHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Map,
91
89
bounds : m .bounds ,
92
90
bucketCounts : make ([]uint64 , len (m .bounds )+ 1 ),
93
91
maxExemplarCount : m .maxExemplarCount ,
92
+ startTimestamp : startTimestamp ,
94
93
}
95
94
m .metrics [key ] = h
96
95
}
97
-
98
- h .lastSeenTimestamp = startTimestamp
99
96
return h
100
97
}
101
98
102
99
func (m * explicitHistogramMetrics ) BuildMetrics (
103
100
metric pmetric.Metric ,
104
101
timestamp pcommon.Timestamp ,
102
+ startTimeStampGenerator func (Key , pcommon.Timestamp ) pcommon.Timestamp ,
105
103
temporality pmetric.AggregationTemporality ,
106
104
) {
107
105
metric .SetEmptyHistogram ().SetAggregationTemporality (temporality )
108
106
dps := metric .Histogram ().DataPoints ()
109
107
dps .EnsureCapacity (len (m .metrics ))
110
- for _ , h := range m .metrics {
108
+ for k , h := range m .metrics {
111
109
dp := dps .AppendEmpty ()
112
- var startTimeStamp pcommon.Timestamp
113
- if temporality == pmetric .AggregationTemporalityDelta {
114
- startTimeStamp = h .lastSeenTimestamp
115
- } else {
116
- startTimeStamp = h .startTimestamp
117
- }
118
- dp .SetStartTimestamp (startTimeStamp )
110
+ startTimestamp := startTimeStampGenerator (k , h .startTimestamp )
111
+ dp .SetStartTimestamp (startTimestamp )
119
112
dp .SetTimestamp (timestamp )
120
113
dp .ExplicitBounds ().FromRaw (h .bounds )
121
114
dp .BucketCounts ().FromRaw (h .bucketCounts )
@@ -149,31 +142,26 @@ func (m *exponentialHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Ma
149
142
attributes : attributes ,
150
143
exemplars : pmetric .NewExemplarSlice (),
151
144
maxExemplarCount : m .maxExemplarCount ,
145
+ startTimestamp : startTimeStamp ,
152
146
}
153
147
m .metrics [key ] = h
154
148
}
155
-
156
- h .lastSeenTimestamp = startTimeStamp
157
149
return h
158
150
}
159
151
160
152
func (m * exponentialHistogramMetrics ) BuildMetrics (
161
153
metric pmetric.Metric ,
162
154
timestamp pcommon.Timestamp ,
155
+ startTimeStampGenerator func (Key , pcommon.Timestamp ) pcommon.Timestamp ,
163
156
temporality pmetric.AggregationTemporality ,
164
157
) {
165
158
metric .SetEmptyExponentialHistogram ().SetAggregationTemporality (temporality )
166
159
dps := metric .ExponentialHistogram ().DataPoints ()
167
160
dps .EnsureCapacity (len (m .metrics ))
168
- for _ , e := range m .metrics {
161
+ for k , e := range m .metrics {
169
162
dp := dps .AppendEmpty ()
170
- var startTimeStamp pcommon.Timestamp
171
- if temporality == pmetric .AggregationTemporalityDelta {
172
- startTimeStamp = e .lastSeenTimestamp
173
- } else {
174
- startTimeStamp = e .startTimestamp
175
- }
176
- dp .SetStartTimestamp (startTimeStamp )
163
+ startTimestamp := startTimeStampGenerator (k , e .startTimestamp )
164
+ dp .SetStartTimestamp (startTimestamp )
177
165
dp .SetTimestamp (timestamp )
178
166
expoHistToExponentialDataPoint (e .histogram , dp )
179
167
for i := 0 ; i < e .exemplars .Len (); i ++ {
@@ -261,8 +249,7 @@ type Sum struct {
261
249
exemplars pmetric.ExemplarSlice
262
250
maxExemplarCount * int
263
251
264
- startTimestamp pcommon.Timestamp
265
- lastSeenTimestamp pcommon.Timestamp
252
+ startTimestamp pcommon.Timestamp
266
253
}
267
254
268
255
func (s * Sum ) Add (value uint64 ) {
@@ -292,7 +279,6 @@ func (m *SumMetrics) GetOrCreate(key Key, attributes pcommon.Map, startTimestamp
292
279
}
293
280
m .metrics [key ] = s
294
281
}
295
- s .lastSeenTimestamp = startTimestamp
296
282
return s
297
283
}
298
284
@@ -309,21 +295,17 @@ func (s *Sum) AddExemplar(traceID pcommon.TraceID, spanID pcommon.SpanID, value
309
295
func (m * SumMetrics ) BuildMetrics (
310
296
metric pmetric.Metric ,
311
297
timestamp pcommon.Timestamp ,
298
+ startTimeStampGenerator func (Key , pcommon.Timestamp ) pcommon.Timestamp ,
312
299
temporality pmetric.AggregationTemporality ,
313
300
) {
314
301
metric .SetEmptySum ().SetIsMonotonic (true )
315
302
metric .Sum ().SetAggregationTemporality (temporality )
316
303
317
304
dps := metric .Sum ().DataPoints ()
318
305
dps .EnsureCapacity (len (m .metrics ))
319
- for _ , s := range m .metrics {
306
+ for k , s := range m .metrics {
320
307
dp := dps .AppendEmpty ()
321
- var startTimeStamp pcommon.Timestamp
322
- if temporality == pmetric .AggregationTemporalityDelta {
323
- startTimeStamp = s .lastSeenTimestamp
324
- } else {
325
- startTimeStamp = s .startTimestamp
326
- }
308
+ startTimeStamp := startTimeStampGenerator (k , s .startTimestamp )
327
309
dp .SetStartTimestamp (startTimeStamp )
328
310
dp .SetTimestamp (timestamp )
329
311
dp .SetIntValue (int64 (s .count ))
0 commit comments