@@ -14,8 +14,8 @@ import (
14
14
type Key string
15
15
16
16
type HistogramMetrics interface {
17
- GetOrCreate (key Key , attributes pcommon.Map ) Histogram
18
- BuildMetrics (pmetric.Metric , generateStartTimestamp , pcommon.Timestamp , pmetric.AggregationTemporality )
17
+ GetOrCreate (key Key , attributes pcommon.Map , startTimestamp pcommon. Timestamp ) Histogram
18
+ BuildMetrics (pmetric.Metric , pcommon.Timestamp , pmetric.AggregationTemporality )
19
19
ClearExemplars ()
20
20
}
21
21
@@ -47,6 +47,7 @@ type explicitHistogram struct {
47
47
bounds []float64
48
48
49
49
maxExemplarCount * int
50
+ startTimestamp pcommon.Timestamp
50
51
}
51
52
52
53
type exponentialHistogram struct {
@@ -56,6 +57,7 @@ type exponentialHistogram struct {
56
57
histogram * structure.Histogram [float64 ]
57
58
58
59
maxExemplarCount * int
60
+ startTimestamp pcommon.Timestamp
59
61
}
60
62
61
63
type generateStartTimestamp = func (Key ) pcommon.Timestamp
@@ -76,7 +78,7 @@ func NewExplicitHistogramMetrics(bounds []float64, maxExemplarCount *int) Histog
76
78
}
77
79
}
78
80
79
- func (m * explicitHistogramMetrics ) GetOrCreate (key Key , attributes pcommon.Map ) Histogram {
81
+ func (m * explicitHistogramMetrics ) GetOrCreate (key Key , attributes pcommon.Map , startTimestamp pcommon. Timestamp ) Histogram {
80
82
h , ok := m .metrics [key ]
81
83
if ! ok {
82
84
h = & explicitHistogram {
@@ -94,17 +96,16 @@ func (m *explicitHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Map)
94
96
95
97
func (m * explicitHistogramMetrics ) BuildMetrics (
96
98
metric pmetric.Metric ,
97
- startTimestamp generateStartTimestamp ,
98
99
timestamp pcommon.Timestamp ,
99
100
temporality pmetric.AggregationTemporality ,
100
101
) {
101
102
metric .SetEmptyHistogram ().SetAggregationTemporality (temporality )
102
103
dps := metric .Histogram ().DataPoints ()
103
104
dps .EnsureCapacity (len (m .metrics ))
104
- for k , h := range m .metrics {
105
+ for _ , h := range m .metrics {
105
106
dp := dps .AppendEmpty ()
106
- dp .SetStartTimestamp (startTimestamp (k ))
107
107
dp .SetTimestamp (timestamp )
108
+ dp .SetStartTimestamp (h .startTimestamp )
108
109
dp .ExplicitBounds ().FromRaw (h .bounds )
109
110
dp .BucketCounts ().FromRaw (h .bucketCounts )
110
111
dp .SetCount (h .count )
@@ -114,6 +115,7 @@ func (m *explicitHistogramMetrics) BuildMetrics(
114
115
}
115
116
h .exemplars .CopyTo (dp .Exemplars ())
116
117
h .attributes .CopyTo (dp .Attributes ())
118
+ dp .Attributes ().PutInt ("startTimestamp" , int64 (h .startTimestamp ))
117
119
}
118
120
}
119
121
@@ -123,7 +125,7 @@ func (m *explicitHistogramMetrics) ClearExemplars() {
123
125
}
124
126
}
125
127
126
- func (m * exponentialHistogramMetrics ) GetOrCreate (key Key , attributes pcommon.Map ) Histogram {
128
+ func (m * exponentialHistogramMetrics ) GetOrCreate (key Key , attributes pcommon.Map , startTimeStamp pcommon. Timestamp ) Histogram {
127
129
h , ok := m .metrics [key ]
128
130
if ! ok {
129
131
histogram := new (structure.Histogram [float64 ])
@@ -147,23 +149,23 @@ func (m *exponentialHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Ma
147
149
148
150
func (m * exponentialHistogramMetrics ) BuildMetrics (
149
151
metric pmetric.Metric ,
150
- startTimestamp generateStartTimestamp ,
151
152
timestamp pcommon.Timestamp ,
152
153
temporality pmetric.AggregationTemporality ,
153
154
) {
154
155
metric .SetEmptyExponentialHistogram ().SetAggregationTemporality (temporality )
155
156
dps := metric .ExponentialHistogram ().DataPoints ()
156
157
dps .EnsureCapacity (len (m .metrics ))
157
- for k , m := range m .metrics {
158
+ for _ , e := range m .metrics {
158
159
dp := dps .AppendEmpty ()
159
- dp .SetStartTimestamp (startTimestamp ( k ) )
160
+ dp .SetStartTimestamp (e . startTimestamp )
160
161
dp .SetTimestamp (timestamp )
161
- expoHistToExponentialDataPoint (m .histogram , dp )
162
- for i := 0 ; i < m .exemplars .Len (); i ++ {
163
- m .exemplars .At (i ).SetTimestamp (timestamp )
162
+ expoHistToExponentialDataPoint (e .histogram , dp )
163
+ for i := 0 ; i < e .exemplars .Len (); i ++ {
164
+ e .exemplars .At (i ).SetTimestamp (timestamp )
164
165
}
165
- m .exemplars .CopyTo (dp .Exemplars ())
166
- m .attributes .CopyTo (dp .Attributes ())
166
+ e .exemplars .CopyTo (dp .Exemplars ())
167
+ e .attributes .CopyTo (dp .Attributes ())
168
+ dp .Attributes ().PutInt ("startTimestamp" , int64 (e .startTimestamp ))
167
169
}
168
170
}
169
171
@@ -242,13 +244,14 @@ type Sum struct {
242
244
count uint64
243
245
exemplars pmetric.ExemplarSlice
244
246
maxExemplarCount * int
247
+ startTimestamp pcommon.Timestamp
245
248
}
246
249
247
250
func (s * Sum ) Add (value uint64 ) {
248
251
s .count += value
249
252
}
250
253
251
- func NewSumMetrics (maxExemplarCount * int ) SumMetrics {
254
+ func NewSumMetrics (maxExemplarCount * int , startTimeStamp pcommon. Timestamp ) SumMetrics {
252
255
return SumMetrics {
253
256
metrics : make (map [Key ]* Sum ),
254
257
maxExemplarCount : maxExemplarCount ,
@@ -260,13 +263,14 @@ type SumMetrics struct {
260
263
maxExemplarCount * int
261
264
}
262
265
263
- func (m * SumMetrics ) GetOrCreate (key Key , attributes pcommon.Map ) * Sum {
266
+ func (m * SumMetrics ) GetOrCreate (key Key , attributes pcommon.Map , startTimestamp pcommon. Timestamp ) * Sum {
264
267
s , ok := m .metrics [key ]
265
268
if ! ok {
266
269
s = & Sum {
267
270
attributes : attributes ,
268
271
exemplars : pmetric .NewExemplarSlice (),
269
272
maxExemplarCount : m .maxExemplarCount ,
273
+ startTimestamp : startTimestamp ,
270
274
}
271
275
m .metrics [key ] = s
272
276
}
@@ -285,7 +289,6 @@ func (s *Sum) AddExemplar(traceID pcommon.TraceID, spanID pcommon.SpanID, value
285
289
286
290
func (m * SumMetrics ) BuildMetrics (
287
291
metric pmetric.Metric ,
288
- startTimestamp generateStartTimestamp ,
289
292
timestamp pcommon.Timestamp ,
290
293
temporality pmetric.AggregationTemporality ,
291
294
) {
@@ -294,9 +297,9 @@ func (m *SumMetrics) BuildMetrics(
294
297
295
298
dps := metric .Sum ().DataPoints ()
296
299
dps .EnsureCapacity (len (m .metrics ))
297
- for k , s := range m .metrics {
300
+ for _ , s := range m .metrics {
298
301
dp := dps .AppendEmpty ()
299
- dp .SetStartTimestamp (startTimestamp ( k ) )
302
+ dp .SetStartTimestamp (s . startTimestamp )
300
303
dp .SetTimestamp (timestamp )
301
304
dp .SetIntValue (int64 (s .count ))
302
305
for i := 0 ; i < s .exemplars .Len (); i ++ {
0 commit comments