@@ -20,6 +20,9 @@ import (
20
20
// The subtract initial point adjuster sets the start time of all points in a series by:
21
21
// - Dropping the initial point, and recording its value and timestamp.
22
22
// - Subtracting the initial point from all subsequent points, and using the timestamp of the initial point as the start timestamp.
23
+ //
24
+ // Note that when a reset is detected (eg: value of a counter is decreasing) - the strategy will set the
25
+ // start time of the reset point as point timestamp - 1ms.
23
26
const Type = "subtract_initial_point"
24
27
25
28
type Adjuster struct {
@@ -155,29 +158,33 @@ func adjustMetricHistogram(referenceTsm, previousValueTsm *datapointstorage.Time
155
158
adjustedPoint .CopyTo (resHistogram .DataPoints ().AppendEmpty ())
156
159
continue
157
160
}
161
+ isReset := datapointstorage .IsResetHistogram (adjustedPoint , referenceTsi .Histogram )
158
162
subtractHistogramDataPoint (adjustedPoint , referenceTsi .Histogram )
159
163
160
164
previousTsi , found := previousValueTsm .Get (current , currentDist .Attributes ())
161
- if ! found {
162
- // First point after the reference. Not a reset.
163
- previousTsi .Histogram = pmetric .NewHistogramDataPoint ()
164
- } else if previousTsi .IsResetHistogram (adjustedPoint ) {
165
+ if isReset || (found && datapointstorage .IsResetHistogram (adjustedPoint , previousTsi .Histogram )) {
165
166
// reset re-initialize everything and use the non adjusted points start time.
166
167
resetStartTimeStamp := pcommon .NewTimestampFromTime (currentDist .StartTimestamp ().AsTime ().Add (- 1 * time .Millisecond ))
167
168
currentDist .SetStartTimestamp (resetStartTimeStamp )
168
169
170
+ // Update the reference value with the current point.
169
171
referenceTsi .Histogram = pmetric .NewHistogramDataPoint ()
172
+ previousTsi .Histogram = pmetric .NewHistogramDataPoint ()
170
173
referenceTsi .Histogram .SetStartTimestamp (currentDist .StartTimestamp ())
174
+ currentDist .ExplicitBounds ().CopyTo (referenceTsi .Histogram .ExplicitBounds ())
175
+ referenceTsi .Histogram .BucketCounts ().FromRaw (make ([]uint64 , currentDist .BucketCounts ().Len ()))
171
176
172
- tmp := resHistogram .DataPoints ().AppendEmpty ()
173
- currentDist .CopyTo (tmp )
177
+ currentDist . CopyTo ( resHistogram .DataPoints ().AppendEmpty () )
178
+ currentDist .CopyTo (previousTsi . Histogram )
174
179
continue
180
+ } else if ! found {
181
+ // First point after the reference. Not a reset.
182
+ previousTsi .Histogram = pmetric .NewHistogramDataPoint ()
175
183
}
176
184
177
185
// Update previous values with the current point.
178
186
adjustedPoint .CopyTo (previousTsi .Histogram )
179
- tmp := resHistogram .DataPoints ().AppendEmpty ()
180
- adjustedPoint .CopyTo (tmp )
187
+ adjustedPoint .CopyTo (resHistogram .DataPoints ().AppendEmpty ())
181
188
}
182
189
}
183
190
@@ -217,29 +224,34 @@ func adjustMetricExponentialHistogram(referenceTsm, previousValueTsm *datapoints
217
224
adjustedPoint .CopyTo (resExpHistogram .DataPoints ().AppendEmpty ())
218
225
continue
219
226
}
227
+
228
+ isReset := datapointstorage .IsResetExponentialHistogram (adjustedPoint , referenceTsi .ExponentialHistogram )
220
229
subtractExponentialHistogramDataPoint (adjustedPoint , referenceTsi .ExponentialHistogram )
221
230
222
231
previousTsi , found := previousValueTsm .Get (current , currentDist .Attributes ())
223
- if ! found {
224
- // First point after the reference. Not a reset.
225
- previousTsi .ExponentialHistogram = pmetric .NewExponentialHistogramDataPoint ()
226
- } else if previousTsi .IsResetExponentialHistogram (adjustedPoint ) {
232
+ if isReset || (found && datapointstorage .IsResetExponentialHistogram (adjustedPoint , previousTsi .ExponentialHistogram )) {
227
233
// reset re-initialize everything and use the non adjusted points start time.
228
234
resetStartTimeStamp := pcommon .NewTimestampFromTime (currentDist .StartTimestamp ().AsTime ().Add (- 1 * time .Millisecond ))
229
235
currentDist .SetStartTimestamp (resetStartTimeStamp )
230
236
231
237
referenceTsi .ExponentialHistogram = pmetric .NewExponentialHistogramDataPoint ()
238
+ previousTsi .ExponentialHistogram = pmetric .NewExponentialHistogramDataPoint ()
232
239
referenceTsi .ExponentialHistogram .SetStartTimestamp (currentDist .StartTimestamp ())
240
+ referenceTsi .ExponentialHistogram .SetScale (currentDist .Scale ())
241
+ referenceTsi .ExponentialHistogram .Positive ().BucketCounts ().FromRaw (make ([]uint64 , currentDist .Positive ().BucketCounts ().Len ()))
242
+ referenceTsi .ExponentialHistogram .Negative ().BucketCounts ().FromRaw (make ([]uint64 , currentDist .Negative ().BucketCounts ().Len ()))
233
243
234
- tmp := resExpHistogram .DataPoints ().AppendEmpty ()
235
- currentDist .CopyTo (tmp )
244
+ currentDist . CopyTo ( resExpHistogram .DataPoints ().AppendEmpty () )
245
+ currentDist .CopyTo (previousTsi . ExponentialHistogram )
236
246
continue
247
+ } else if ! found {
248
+ // First point after the reference. Not a reset.
249
+ previousTsi .ExponentialHistogram = pmetric .NewExponentialHistogramDataPoint ()
237
250
}
238
251
239
252
// Update previous values with the current point.
240
253
adjustedPoint .CopyTo (previousTsi .ExponentialHistogram )
241
- tmp := resExpHistogram .DataPoints ().AppendEmpty ()
242
- adjustedPoint .CopyTo (tmp )
254
+ adjustedPoint .CopyTo (resExpHistogram .DataPoints ().AppendEmpty ())
243
255
}
244
256
}
245
257
@@ -278,29 +290,30 @@ func adjustMetricSum(referenceTsm, previousValueTsm *datapointstorage.Timeseries
278
290
adjustedPoint .CopyTo (resSum .DataPoints ().AppendEmpty ())
279
291
continue
280
292
}
293
+ isReset := datapointstorage .IsResetSum (adjustedPoint , referenceTsi .Number )
281
294
adjustedPoint .SetDoubleValue (adjustedPoint .DoubleValue () - referenceTsi .Number .DoubleValue ())
282
295
283
296
previousTsi , found := previousValueTsm .Get (current , currentSum .Attributes ())
284
- if ! found {
285
- // First point after the reference. Not a reset.
286
- previousTsi .Number = pmetric .NewNumberDataPoint ()
287
- } else if previousTsi .IsResetSum (adjustedPoint ) {
297
+ if isReset || (found && datapointstorage .IsResetSum (adjustedPoint , previousTsi .Number )) {
288
298
// reset re-initialize everything and use the non adjusted points start time.
289
299
resetStartTimeStamp := pcommon .NewTimestampFromTime (currentSum .StartTimestamp ().AsTime ().Add (- 1 * time .Millisecond ))
290
300
currentSum .SetStartTimestamp (resetStartTimeStamp )
291
301
292
302
referenceTsi .Number = pmetric .NewNumberDataPoint ()
303
+ previousTsi .Number = pmetric .NewNumberDataPoint ()
293
304
referenceTsi .Number .SetStartTimestamp (currentSum .StartTimestamp ())
294
305
295
- tmp := resSum .DataPoints ().AppendEmpty ()
296
- currentSum .CopyTo (tmp )
306
+ currentSum . CopyTo ( resSum .DataPoints ().AppendEmpty () )
307
+ currentSum .CopyTo (previousTsi . Number )
297
308
continue
309
+ } else if ! found {
310
+ // First point after the reference. Not a reset.
311
+ previousTsi .Number = pmetric .NewNumberDataPoint ()
298
312
}
299
313
300
314
// Update previous values with the current point.
301
315
adjustedPoint .CopyTo (previousTsi .Number )
302
- tmp := resSum .DataPoints ().AppendEmpty ()
303
- adjustedPoint .CopyTo (tmp )
316
+ adjustedPoint .CopyTo (resSum .DataPoints ().AppendEmpty ())
304
317
}
305
318
}
306
319
@@ -331,30 +344,32 @@ func adjustMetricSummary(referenceTsm, previousValueTsm *datapointstorage.Timese
331
344
adjustedPoint .CopyTo (resSummary .DataPoints ().AppendEmpty ())
332
345
continue
333
346
}
347
+
348
+ isReset := datapointstorage .IsResetSummary (adjustedPoint , referenceTsi .Summary )
334
349
adjustedPoint .SetCount (adjustedPoint .Count () - referenceTsi .Summary .Count ())
335
350
adjustedPoint .SetSum (adjustedPoint .Sum () - referenceTsi .Summary .Sum ())
336
351
337
352
previousTsi , found := previousValueTsm .Get (current , currentSummary .Attributes ())
338
- if ! found {
339
- // First point after the reference. Not a reset.
340
- previousTsi .Summary = pmetric .NewSummaryDataPoint ()
341
- } else if previousTsi .IsResetSummary (adjustedPoint ) {
353
+ if isReset || (found && datapointstorage .IsResetSummary (adjustedPoint , previousTsi .Summary )) {
342
354
// reset re-initialize everything and use the non adjusted points start time.
343
355
resetStartTimeStamp := pcommon .NewTimestampFromTime (currentSummary .StartTimestamp ().AsTime ().Add (- 1 * time .Millisecond ))
344
356
currentSummary .SetStartTimestamp (resetStartTimeStamp )
345
357
346
358
referenceTsi .Summary = pmetric .NewSummaryDataPoint ()
359
+ previousTsi .Summary = pmetric .NewSummaryDataPoint ()
347
360
referenceTsi .Summary .SetStartTimestamp (currentSummary .StartTimestamp ())
348
361
349
- tmp := resSummary .DataPoints ().AppendEmpty ()
350
- currentSummary .CopyTo (tmp )
362
+ currentSummary . CopyTo ( resSummary .DataPoints ().AppendEmpty () )
363
+ currentSummary .CopyTo (previousTsi . Summary )
351
364
continue
365
+ } else if ! found {
366
+ // First point after the reference. Not a reset.
367
+ previousTsi .Summary = pmetric .NewSummaryDataPoint ()
352
368
}
353
369
354
370
// Update previous values with the current point.
355
371
adjustedPoint .CopyTo (previousTsi .Summary )
356
- tmp := resSummary .DataPoints ().AppendEmpty ()
357
- adjustedPoint .CopyTo (tmp )
372
+ adjustedPoint .CopyTo (resSummary .DataPoints ().AppendEmpty ())
358
373
}
359
374
}
360
375
0 commit comments