Skip to content

Commit

Permalink
Make the collector exporter mutate data, and remove unnecessary CopyTo (
Browse files Browse the repository at this point in the history
#892)

* make the collector exporter mutate data, and remove unnecessary CopyTo

* update comments

* rebase on benchmark
  • Loading branch information
dashpole committed Sep 19, 2024
1 parent 1c2070c commit ac83b74
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 166 deletions.
16 changes: 8 additions & 8 deletions exporter/collector/internal/normalization/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func BenchmarkNormalizeNumberDataPoint(b *testing.B) {
b.StopTimer()
newPoint := testNumberDataPoint()
b.StartTimer()
_, ok = normalizer.NormalizeNumberDataPoint(newPoint, id)
ok = normalizer.NormalizeNumberDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -61,7 +61,7 @@ func BenchmarkNormalizeHistogramDataPoint(b *testing.B) {
b.StopTimer()
newPoint := testHistogramDataPoint()
b.StartTimer()
_, ok = normalizer.NormalizeHistogramDataPoint(newPoint, id)
ok = normalizer.NormalizeHistogramDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -82,7 +82,7 @@ func BenchmarkNormalizeExopnentialHistogramDataPoint(b *testing.B) {
b.StopTimer()
newPoint := testExponentialHistogramDataPoint()
b.StartTimer()
_, ok = normalizer.NormalizeExponentialHistogramDataPoint(newPoint, id)
ok = normalizer.NormalizeExponentialHistogramDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -103,7 +103,7 @@ func BenchmarkNormalizeSummaryDataPoint(b *testing.B) {
b.StopTimer()
newPoint := testSummaryDataPoint()
b.StartTimer()
_, ok = normalizer.NormalizeSummaryDataPoint(newPoint, id)
ok = normalizer.NormalizeSummaryDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -127,7 +127,7 @@ func BenchmarkResetNormalizeNumberDataPoint(b *testing.B) {
newPoint := testNumberDataPoint()
newPoint.SetIntValue(int64(b.N - i))
b.StartTimer()
_, ok = normalizer.NormalizeNumberDataPoint(newPoint, id)
ok = normalizer.NormalizeNumberDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -151,7 +151,7 @@ func BenchmarkResetNormalizeHistogramDataPoint(b *testing.B) {
newPoint := testHistogramDataPoint()
newPoint.SetSum(float64(b.N - i))
b.StartTimer()
_, ok = normalizer.NormalizeHistogramDataPoint(newPoint, id)
ok = normalizer.NormalizeHistogramDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -175,7 +175,7 @@ func BenchmarkResetNormalizeExponentialHistogramDataPoint(b *testing.B) {
newPoint := testExponentialHistogramDataPoint()
newPoint.SetSum(float64(b.N - i))
b.StartTimer()
_, ok = normalizer.NormalizeExponentialHistogramDataPoint(newPoint, id)
ok = normalizer.NormalizeExponentialHistogramDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand All @@ -199,7 +199,7 @@ func BenchmarkResetNormalizeSummaryDataPoint(b *testing.B) {
newPoint := testSummaryDataPoint()
newPoint.SetSum(float64(b.N - i))
b.StartTimer()
_, ok = normalizer.NormalizeSummaryDataPoint(newPoint, id)
ok = normalizer.NormalizeSummaryDataPoint(newPoint, id)
assert.True(b, ok)
}
}
Expand Down
52 changes: 20 additions & 32 deletions exporter/collector/internal/normalization/disabled_normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,46 @@ func NewDisabledNormalizer() Normalizer {

type disabledNormalizer struct{}

// NormalizeExponentialHistogramDataPoint returns the point without normalizing.
func (d *disabledNormalizer) NormalizeExponentialHistogramDataPoint(point pmetric.ExponentialHistogramDataPoint, _ uint64) (pmetric.ExponentialHistogramDataPoint, bool) {
// NormalizeExponentialHistogramDataPoint ensures the start time is before the
// end time, but does not normalize points.
func (d *disabledNormalizer) NormalizeExponentialHistogramDataPoint(point pmetric.ExponentialHistogramDataPoint, _ uint64) bool {
if !point.StartTimestamp().AsTime().Before(point.Timestamp().AsTime()) {
// Handle explicit reset points.
// Make a copy so we don't mutate underlying data.
newPoint := pmetric.NewExponentialHistogramDataPoint()
point.CopyTo(newPoint)
// StartTime = Timestamp - 1 ms
newPoint.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
return newPoint, true
point.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
}
return point, true
return true
}

// NormalizeHistogramDataPoint returns the point without normalizing.
func (d *disabledNormalizer) NormalizeHistogramDataPoint(point pmetric.HistogramDataPoint, _ uint64) (pmetric.HistogramDataPoint, bool) {
// NormalizeHistogramDataPoint ensures the start time is before the
// end time, but does not normalize points.
func (d *disabledNormalizer) NormalizeHistogramDataPoint(point pmetric.HistogramDataPoint, _ uint64) bool {
if !point.StartTimestamp().AsTime().Before(point.Timestamp().AsTime()) {
// Handle explicit reset points.
// Make a copy so we don't mutate underlying data.
newPoint := pmetric.NewHistogramDataPoint()
point.CopyTo(newPoint)
// StartTime = Timestamp - 1 ms
newPoint.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
return newPoint, true
point.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
}
return point, true
return true
}

// NormalizeNumberDataPoint returns the point without normalizing.
func (d *disabledNormalizer) NormalizeNumberDataPoint(point pmetric.NumberDataPoint, _ uint64) (pmetric.NumberDataPoint, bool) {
// NormalizeNumberDataPoint ensures the start time is before the
// end time, but does not normalize points.
func (d *disabledNormalizer) NormalizeNumberDataPoint(point pmetric.NumberDataPoint, _ uint64) bool {
if !point.StartTimestamp().AsTime().Before(point.Timestamp().AsTime()) {
// Handle explicit reset points.
// Make a copy so we don't mutate underlying data.
newPoint := pmetric.NewNumberDataPoint()
point.CopyTo(newPoint)
// StartTime = Timestamp - 1 ms
newPoint.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
return newPoint, true
point.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
}
return point, true
return true
}

// NormalizeSummaryDataPoint returns the point without normalizing.
func (d *disabledNormalizer) NormalizeSummaryDataPoint(point pmetric.SummaryDataPoint, _ uint64) (pmetric.SummaryDataPoint, bool) {
// NormalizeSummaryDataPoint ensures the start time is before the
// end time, but does not normalize points.
func (d *disabledNormalizer) NormalizeSummaryDataPoint(point pmetric.SummaryDataPoint, _ uint64) bool {
if !point.StartTimestamp().AsTime().Before(point.Timestamp().AsTime()) {
// Handle explicit reset points.
// Make a copy so we don't mutate underlying data.
newPoint := pmetric.NewSummaryDataPoint()
point.CopyTo(newPoint)
// StartTime = Timestamp - 1 ms
newPoint.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
return newPoint, true
point.SetStartTimestamp(pcommon.Timestamp(uint64(point.Timestamp()) - uint64(time.Millisecond)))
}
return point, true
return true
}
Loading

0 comments on commit ac83b74

Please sign in to comment.