Skip to content

Commit

Permalink
use newNoopReservoir instead of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 18, 2024
1 parent c968dc4 commit 361d48d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 86 deletions.
3 changes: 0 additions & 3 deletions sdk/metric/internal/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ type Builder[N int64 | float64] struct {

func (b Builder[N]) resFunc() func(attribute.Set) *filteredExemplarReservoir[N] {
return func(attrs attribute.Set) *filteredExemplarReservoir[N] {
if b.ExemplarReservoirProvider == nil {
return newFilteredExemplarReservoir[N](b.ExemplarFilter, exemplar.NewFixedSizeReservoir(0))
}
return newFilteredExemplarReservoir[N](b.ExemplarFilter, b.ExemplarReservoirProvider(attrs))
}
}
Expand Down
6 changes: 5 additions & 1 deletion sdk/metric/internal/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ func (c *clock) Register() (unregister func()) {
return func() { now = orig }
}

func newNoopReservoir(attribute.Set) exemplar.Reservoir {
return exemplar.NewFixedSizeReservoir(0)
}

func dropExemplars[N int64 | float64](attr attribute.Set) *filteredExemplarReservoir[N] {
return newFilteredExemplarReservoir[N](exemplar.AlwaysOffFilter, exemplar.NewFixedSizeReservoir(0))
return newFilteredExemplarReservoir[N](exemplar.AlwaysOffFilter, newNoopReservoir(attr))
}

func TestBuilderFilter(t *testing.T) {
Expand Down
38 changes: 22 additions & 16 deletions sdk/metric/internal/aggregate/exponential_histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,26 +683,30 @@ func BenchmarkExponentialHistogram(b *testing.B) {

b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
}
Expand Down Expand Up @@ -749,10 +753,11 @@ func TestExponentialHistogramAggregation(t *testing.T) {

func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(4, 20, false, false)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -877,10 +882,11 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {

func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExponentialBucketHistogram(4, 20, false, false)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down
38 changes: 22 additions & 16 deletions sdk/metric/internal/aggregate/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ type conf[N int64 | float64] struct {

func testDeltaHist[N int64 | float64](c conf[N]) func(t *testing.T) {
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, c.noSum)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -140,10 +141,11 @@ func testDeltaHist[N int64 | float64](c conf[N]) func(t *testing.T) {

func testCumulativeHist[N int64 | float64](c conf[N]) func(t *testing.T) {
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, c.noSum)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -378,26 +380,30 @@ func TestDeltaHistogramReset(t *testing.T) {
func BenchmarkHistogram(b *testing.B) {
b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
}
44 changes: 26 additions & 18 deletions sdk/metric/internal/aggregate/lastvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ func TestLastValue(t *testing.T) {

func testDeltaLastValue[N int64 | float64]() func(*testing.T) {
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.LastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -142,10 +143,11 @@ func testDeltaLastValue[N int64 | float64]() func(*testing.T) {

func testCumulativeLastValue[N int64 | float64]() func(*testing.T) {
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.LastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -265,10 +267,11 @@ func testCumulativeLastValue[N int64 | float64]() func(*testing.T) {

func testDeltaPrecomputedLastValue[N int64 | float64]() func(*testing.T) {
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedLastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -370,10 +373,11 @@ func testDeltaPrecomputedLastValue[N int64 | float64]() func(*testing.T) {

func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) {
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedLastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -475,7 +479,11 @@ func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) {

func BenchmarkLastValue(b *testing.B) {
b.Run("Int64", benchmarkAggregate(Builder[int64]{
ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue))
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedLastValue))
b.Run("Float64", benchmarkAggregate(Builder[float64]{
ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue))
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedLastValue))
}
76 changes: 44 additions & 32 deletions sdk/metric/internal/aggregate/sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ func TestSum(t *testing.T) {
func testDeltaSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -171,10 +172,11 @@ func testDeltaSum[N int64 | float64]() func(t *testing.T) {
func testCumulativeSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -286,10 +288,11 @@ func testCumulativeSum[N int64 | float64]() func(t *testing.T) {
func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -416,10 +419,11 @@ func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) {
func testCumulativePrecomputedSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -549,51 +553,59 @@ func BenchmarkSum(b *testing.B) {
// performance, therefore, only monotonic=false is benchmarked here.
b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(false)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(false)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(false)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.Sum(false)
}))

b.Run("Precomputed/Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(false)
}))
b.Run("Precomputed/Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(false)
}))
b.Run("Precomputed/Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(false)
}))
b.Run("Precomputed/Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
ExemplarReservoirProvider: newNoopReservoir,
}.PrecomputedSum(false)
}))
}

0 comments on commit 361d48d

Please sign in to comment.