Skip to content

Commit a9f53d6

Browse files
ridwanmsharifdashpolesongy23
authored
metricstarttimeprocessor: cache both int and double value for the sum datapoint (open-telemetry#42203)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Update the timeseries info structs so we also store the int values for sums. And make sure we update and use this appropriately in the strategies. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#42202 <!--Describe what testing was performed and which tests were added.--> #### Testing Added unit tests to the datapointstorage module, as well as to each strategy. <!--Describe the documentation added.--> #### Documentation N/A <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Ridwan Sharif <[email protected]> Co-authored-by: David Ashpole <[email protected]> Co-authored-by: Yang Song <[email protected]>
1 parent ba8196c commit a9f53d6

File tree

10 files changed

+174
-17
lines changed

10 files changed

+174
-17
lines changed

.chloggen/fix-adjust-int-sums.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: processor/metricstarttime
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fixes bug where adjustment only relied on the DoubleValue and ignored the IntValue
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [42202]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/metricstarttimeprocessor/internal/datapointstorage/timeseries_map.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ type TimeseriesInfo struct {
2626
}
2727

2828
type NumberInfo struct {
29-
StartTime pcommon.Timestamp
30-
PreviousValue float64
29+
StartTime pcommon.Timestamp
30+
PreviousDoubleValue float64
31+
PreviousIntValue int64
3132

3233
// These are the optional reference values for strategies that need to cache
3334
// additional data from the initial points.
3435
// For example - storing the initial point for the subtract_initial_point strategy.
35-
RefValue float64
36+
RefDoubleValue float64
37+
RefIntValue int64
3638
}
3739

3840
type HistogramInfo struct {
@@ -246,7 +248,7 @@ func (ref *TimeseriesInfo) IsResetSummary(s pmetric.SummaryDataPoint) bool {
246248
// whether the metric has been reset based on the values. It is a reset if the
247249
// value has decreased.
248250
func (ref *TimeseriesInfo) IsResetSum(s pmetric.NumberDataPoint) bool {
249-
return s.DoubleValue() < ref.Number.PreviousValue
251+
return s.DoubleValue() < ref.Number.PreviousDoubleValue || s.IntValue() < ref.Number.PreviousIntValue
250252
}
251253

252254
func newTimeseriesMap() *TimeseriesMap {

processor/metricstarttimeprocessor/internal/datapointstorage/timeseries_map_test.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func TestTimeseriesInfo_IsResetSum(t *testing.T) {
550550
name: "Double Value decreased",
551551
setupTsi: func() *TimeseriesInfo {
552552
tsi := &TimeseriesInfo{}
553-
tsi.Number = NumberInfo{PreviousValue: 10}
553+
tsi.Number = NumberInfo{PreviousDoubleValue: 10}
554554
return tsi
555555
},
556556
setupS: func() pmetric.NumberDataPoint {
@@ -564,7 +564,7 @@ func TestTimeseriesInfo_IsResetSum(t *testing.T) {
564564
name: "No Reset",
565565
setupTsi: func() *TimeseriesInfo {
566566
tsi := &TimeseriesInfo{}
567-
tsi.Number = NumberInfo{PreviousValue: 10}
567+
tsi.Number = NumberInfo{PreviousDoubleValue: 10}
568568
return tsi
569569
},
570570
setupS: func() pmetric.NumberDataPoint {
@@ -574,6 +574,34 @@ func TestTimeseriesInfo_IsResetSum(t *testing.T) {
574574
},
575575
expectedReset: false,
576576
},
577+
{
578+
name: "Double Value decreased - INT",
579+
setupTsi: func() *TimeseriesInfo {
580+
tsi := &TimeseriesInfo{}
581+
tsi.Number = NumberInfo{PreviousIntValue: 10}
582+
return tsi
583+
},
584+
setupS: func() pmetric.NumberDataPoint {
585+
s := pmetric.NewNumberDataPoint()
586+
s.SetIntValue(5)
587+
return s
588+
},
589+
expectedReset: true,
590+
},
591+
{
592+
name: "No Reset - INT",
593+
setupTsi: func() *TimeseriesInfo {
594+
tsi := &TimeseriesInfo{}
595+
tsi.Number = NumberInfo{PreviousIntValue: 10}
596+
return tsi
597+
},
598+
setupS: func() pmetric.NumberDataPoint {
599+
s := pmetric.NewNumberDataPoint()
600+
s.SetIntValue(15)
601+
return s
602+
},
603+
expectedReset: false,
604+
},
577605
}
578606

579607
for _, tt := range tests {

processor/metricstarttimeprocessor/internal/starttimemetric/adjuster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func (a *Adjuster) AdjustMetrics(_ context.Context, metrics pmetric.Metrics) (pm
8888
} else if refTsi.IsResetSum(dp) {
8989
refTsi.Number.StartTime = pcommon.NewTimestampFromTime(dp.Timestamp().AsTime().Add(-1 * time.Millisecond))
9090
}
91-
refTsi.Number.PreviousValue = dp.DoubleValue()
91+
refTsi.Number.PreviousDoubleValue = dp.DoubleValue()
92+
refTsi.Number.PreviousIntValue = dp.IntValue()
9293
dp.SetStartTimestamp(refTsi.Number.StartTime)
9394
}
9495

processor/metricstarttimeprocessor/internal/starttimemetric/adjuster_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
percent0 = []float64{10, 50, 90}
2929

3030
sum1 = "sum1"
31+
sum2 = "sum2"
3132
gauge1 = "gauge1"
3233
histogram1 = "histogram1"
3334
summary1 = "summary1"
@@ -291,6 +292,7 @@ func TestMultiMetrics(t *testing.T) {
291292
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, startTime, currentTime, matchBuilderStartTime)),
292293
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t1, t1, 44)),
293294
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t1, t1, 44)),
295+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t1, t1, 44)),
294296
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t1, t1, bounds0, []uint64{4, 2, 3, 7})),
295297
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t1, t1, 3, 1, 0, []uint64{}, -2, []uint64{4, 2, 3, 7})),
296298
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t1, t1, 10, 40, percent0, []float64{1, 5, 8})),
@@ -299,6 +301,7 @@ func TestMultiMetrics(t *testing.T) {
299301
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, matchedStartTimeStamp, currentTime, matchBuilderStartTime)),
300302
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t1, t1, 44)),
301303
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, matchedStartTimeStamp, t1, 44)),
304+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, matchedStartTimeStamp, t1, 44)),
302305
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, matchedStartTimeStamp, t1, bounds0, []uint64{4, 2, 3, 7})),
303306
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, matchedStartTimeStamp, t1, 3, 1, 0, []uint64{}, -2, []uint64{4, 2, 3, 7})),
304307
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, matchedStartTimeStamp, t1, 10, 40, percent0, []float64{1, 5, 8})),
@@ -310,6 +313,7 @@ func TestMultiMetrics(t *testing.T) {
310313
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, startTime, currentTime, matchBuilderStartTime)),
311314
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t2, t2, 66)),
312315
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t2, t2, 66)),
316+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t2, t2, 66)),
313317
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t2, t2, bounds0, []uint64{6, 3, 4, 8})),
314318
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t2, t2, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 7})),
315319
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t2, t2, 15, 70, percent0, []float64{7, 44, 9})),
@@ -318,6 +322,7 @@ func TestMultiMetrics(t *testing.T) {
318322
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, matchedStartTimeStamp, currentTime, matchBuilderStartTime)),
319323
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t2, t2, 66)),
320324
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, matchedStartTimeStamp, t2, 66)),
325+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, matchedStartTimeStamp, t2, 66)),
321326
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, matchedStartTimeStamp, t2, bounds0, []uint64{6, 3, 4, 8})),
322327
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, matchedStartTimeStamp, t2, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 7})),
323328
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, matchedStartTimeStamp, t2, 15, 70, percent0, []float64{7, 44, 9})),
@@ -329,6 +334,7 @@ func TestMultiMetrics(t *testing.T) {
329334
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, startTime, currentTime, matchBuilderStartTime)),
330335
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t3, t3, 55)),
331336
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t3, t3, 55)),
337+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t3, t3, 55)),
332338
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t3, t3, bounds0, []uint64{5, 3, 2, 7})),
333339
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t3, t3, 3, 1, 0, []uint64{}, -2, []uint64{5, 1, 2, 6})),
334340
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t3, t3, 12, 66, percent0, []float64{3, 22, 5})),
@@ -337,6 +343,7 @@ func TestMultiMetrics(t *testing.T) {
337343
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, matchedStartTimeStamp, currentTime, matchBuilderStartTime)),
338344
testhelper.GaugeMetric(gauge1, testhelper.DoublePoint(k1v1k2v2, t3, t3, 55)),
339345
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t2, t3, 55)),
346+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t2, t3, 55)),
340347
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t2, t3, bounds0, []uint64{5, 3, 2, 7})),
341348
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t2, t3, 3, 1, 0, []uint64{}, -2, []uint64{5, 1, 2, 6})),
342349
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t2, t3, 12, 66, percent0, []float64{3, 22, 5})),
@@ -347,13 +354,15 @@ func TestMultiMetrics(t *testing.T) {
347354
Metrics: testhelper.Metrics(
348355
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, startTime, currentTime, matchBuilderStartTime)),
349356
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t4, t4, 72)),
357+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t4, t4, 72)),
350358
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t4, t4, bounds0, []uint64{7, 4, 2, 12})),
351359
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t4, t4, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 7})),
352360
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t4, t4, 14, 96, percent0, []float64{9, 47, 8})),
353361
),
354362
Adjusted: testhelper.Metrics(
355363
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, matchedStartTimeStamp, currentTime, matchBuilderStartTime)),
356364
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t2, t4, 72)),
365+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t2, t4, 72)),
357366
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t2, t4, bounds0, []uint64{7, 4, 2, 12})),
358367
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t2, t4, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 7})),
359368
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t2, t4, 14, 96, percent0, []float64{9, 47, 8})),
@@ -364,13 +373,15 @@ func TestMultiMetrics(t *testing.T) {
364373
Metrics: testhelper.Metrics(
365374
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, startTime, currentTime, matchBuilderStartTime)),
366375
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t5, t5, 71)),
376+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t5, t5, 71)),
367377
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t5, t5, bounds0, []uint64{7, 4, 20, 11})),
368378
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t5, t5, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 6})),
369379
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t5, t5, 14, 95, percent0, []float64{9, 47, 8})),
370380
),
371381
Adjusted: testhelper.Metrics(
372382
testhelper.SumMetric("example_process_start_time_seconds", testhelper.DoublePoint(nil, matchedStartTimeStamp, currentTime, matchBuilderStartTime)),
373383
testhelper.SumMetric(sum1, testhelper.DoublePoint(k1v1k2v2, t4, t5, 71)),
384+
testhelper.SumMetric(sum2, testhelper.IntPoint(k1v1k2v2, t4, t5, 71)),
374385
testhelper.HistogramMetric(histogram1, testhelper.HistogramPoint(k1v1k2v2, t4, t5, bounds0, []uint64{7, 4, 20, 11})),
375386
testhelper.ExponentialHistogramMetric(exponentialHistogram1, testhelper.ExponentialHistogramPoint(k1v1k2v2, t4, t5, 3, 1, 0, []uint64{}, -2, []uint64{6, 2, 3, 6})),
376387
testhelper.SummaryMetric(summary1, testhelper.SummaryPoint(k1v1k2v2, t4, t5, 14, 95, percent0, []float64{9, 47, 8})),

processor/metricstarttimeprocessor/internal/subtractinitial/adjuster.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ func adjustMetricSum(referenceValueTsm *datapointstorage.TimeseriesMap, metric p
216216
refTsi, found := referenceValueTsm.Get(metric, currentSum.Attributes())
217217
if !found {
218218
// First time we see this point. Skip it and use as a reference point for the next points.
219-
refTsi.Number = datapointstorage.NumberInfo{PreviousValue: currentSum.DoubleValue(), RefValue: currentSum.DoubleValue(), StartTime: currentSum.Timestamp()}
219+
refTsi.Number = datapointstorage.NumberInfo{
220+
PreviousDoubleValue: currentSum.DoubleValue(),
221+
PreviousIntValue: currentSum.IntValue(),
222+
RefDoubleValue: currentSum.DoubleValue(),
223+
RefIntValue: currentSum.IntValue(),
224+
StartTime: currentSum.Timestamp(),
225+
}
220226
return true
221227
}
222228

@@ -232,11 +238,20 @@ func adjustMetricSum(referenceValueTsm *datapointstorage.TimeseriesMap, metric p
232238
currentSum.SetStartTimestamp(resetStartTimeStamp)
233239

234240
refTsi.Number.StartTime = resetStartTimeStamp
235-
refTsi.Number.RefValue = 0
236-
refTsi.Number.PreviousValue = currentSum.DoubleValue()
241+
refTsi.Number.RefDoubleValue = 0
242+
refTsi.Number.RefIntValue = 0
243+
refTsi.Number.PreviousDoubleValue = currentSum.DoubleValue()
244+
refTsi.Number.PreviousIntValue = currentSum.IntValue()
237245
} else {
238-
refTsi.Number.PreviousValue = currentSum.DoubleValue()
239-
currentSum.SetDoubleValue(currentSum.DoubleValue() - refTsi.Number.RefValue)
246+
refTsi.Number.PreviousDoubleValue = currentSum.DoubleValue()
247+
refTsi.Number.PreviousIntValue = currentSum.IntValue()
248+
249+
// Update the currentSum appropriately based on the original value type.
250+
if currentSum.ValueType() == pmetric.NumberDataPointValueTypeDouble {
251+
currentSum.SetDoubleValue(currentSum.DoubleValue() - refTsi.Number.RefDoubleValue)
252+
} else {
253+
currentSum.SetIntValue(currentSum.IntValue() - refTsi.Number.RefIntValue)
254+
}
240255
}
241256
return false
242257
})

processor/metricstarttimeprocessor/internal/subtractinitial/adjuster_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,37 @@ func TestSum(t *testing.T) {
101101
testhelper.RunScript(t, NewAdjuster(componenttest.NewNopTelemetrySettings(), time.Minute), script)
102102
}
103103

104+
func TestSumInt(t *testing.T) {
105+
script := []*testhelper.MetricsAdjusterTest{
106+
{
107+
Description: "Sum: round 1 - initial instance, start time is established",
108+
Metrics: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t1, t1, 44))),
109+
Adjusted: testhelper.Metrics(testhelper.SumMetric(sum1)),
110+
},
111+
{
112+
Description: "Sum: round 2 - instance adjusted based on round 1",
113+
Metrics: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t2, t2, 66))),
114+
Adjusted: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t1, t2, 22))),
115+
},
116+
{
117+
Description: "Sum: round 3 - instance reset (value less than previous value), start time is reset",
118+
Metrics: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t3, t3, 55))),
119+
Adjusted: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t2, t3, 55))),
120+
},
121+
{
122+
Description: "Sum: round 4 - instance adjusted based on round 3",
123+
Metrics: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t4, t4, 72))),
124+
Adjusted: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t2, t4, 72))),
125+
},
126+
{
127+
Description: "Sum: round 5 - instance adjusted based on round 4 (value stayed the same))",
128+
Metrics: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t5, t5, 72))),
129+
Adjusted: testhelper.Metrics(testhelper.SumMetric(sum1, testhelper.IntPoint(k1v1k2v2, t2, t5, 72))),
130+
},
131+
}
132+
testhelper.RunScript(t, NewAdjuster(componenttest.NewNopTelemetrySettings(), time.Minute), script)
133+
}
134+
104135
func TestSumNoStartTimestamp(t *testing.T) {
105136
script := []*testhelper.MetricsAdjusterTest{
106137
{

processor/metricstarttimeprocessor/internal/testhelper/util.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func ExponentialHistogramPointSimplified(attributes []*KV, startTimestamp, times
207207
return hdp
208208
}
209209

210-
func DoublePointRaw(attributes []*KV, startTimestamp, timestamp pcommon.Timestamp) pmetric.NumberDataPoint {
210+
func NumberPointRaw(attributes []*KV, startTimestamp, timestamp pcommon.Timestamp) pmetric.NumberDataPoint {
211211
ndp := pmetric.NewNumberDataPoint()
212212
ndp.SetStartTimestamp(startTimestamp)
213213
ndp.SetTimestamp(timestamp)
@@ -220,13 +220,19 @@ func DoublePointRaw(attributes []*KV, startTimestamp, timestamp pcommon.Timestam
220220
}
221221

222222
func DoublePoint(attributes []*KV, startTimestamp, timestamp pcommon.Timestamp, value float64) pmetric.NumberDataPoint {
223-
ndp := DoublePointRaw(attributes, startTimestamp, timestamp)
223+
ndp := NumberPointRaw(attributes, startTimestamp, timestamp)
224224
ndp.SetDoubleValue(value)
225225
return ndp
226226
}
227227

228+
func IntPoint(attributes []*KV, startTimestamp, timestamp pcommon.Timestamp, value int64) pmetric.NumberDataPoint {
229+
ndp := NumberPointRaw(attributes, startTimestamp, timestamp)
230+
ndp.SetIntValue(value)
231+
return ndp
232+
}
233+
228234
func DoublePointNoValue(attributes []*KV, startTimestamp, timestamp pcommon.Timestamp) pmetric.NumberDataPoint {
229-
ndp := DoublePointRaw(attributes, startTimestamp, timestamp)
235+
ndp := NumberPointRaw(attributes, startTimestamp, timestamp)
230236
ndp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
231237
return ndp
232238
}

processor/metricstarttimeprocessor/internal/truereset/adjuster.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ func (*Adjuster) adjustMetricSum(tsm *datapointstorage.TimeseriesMap, current pm
186186
refTsi, found := tsm.Get(current, currentSum.Attributes())
187187
if !found {
188188
// initialize everything.
189-
refTsi.Number = datapointstorage.NumberInfo{PreviousValue: currentSum.DoubleValue(), StartTime: currentSum.Timestamp()}
189+
refTsi.Number = datapointstorage.NumberInfo{
190+
PreviousDoubleValue: currentSum.DoubleValue(),
191+
PreviousIntValue: currentSum.IntValue(),
192+
StartTime: currentSum.Timestamp(),
193+
}
190194

191195
// For the first point, set the start time as the point timestamp.
192196
currentSum.SetStartTimestamp(currentSum.Timestamp())
@@ -206,7 +210,8 @@ func (*Adjuster) adjustMetricSum(tsm *datapointstorage.TimeseriesMap, current pm
206210
}
207211

208212
// Update only previous values.
209-
refTsi.Number.PreviousValue = currentSum.DoubleValue()
213+
refTsi.Number.PreviousDoubleValue = currentSum.DoubleValue()
214+
refTsi.Number.PreviousIntValue = currentSum.IntValue()
210215
currentSum.SetStartTimestamp(refTsi.Number.StartTime)
211216
}
212217
}

0 commit comments

Comments
 (0)