Skip to content

Commit

Permalink
use exemplar.AlwaysOffFilter instead of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 18, 2024
1 parent c9cb3b4 commit c968dc4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
4 changes: 2 additions & 2 deletions sdk/metric/internal/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func testBuilderFilter[N int64 | float64]() func(t *testing.T) {
}
}

t.Run("NoFilter", run(Builder[N]{}, attr, nil))
t.Run("Filter", run(Builder[N]{Filter: attrFltr}, fltrAlice, []attribute.KeyValue{adminTrue}))
t.Run("NoFilter", run(Builder[N]{ExemplarFilter: exemplar.AlwaysOffFilter}, attr, nil))
t.Run("Filter", run(Builder[N]{ExemplarFilter: exemplar.AlwaysOffFilter, Filter: attrFltr}, fltrAlice, []attribute.KeyValue{adminTrue}))
}
}

Expand Down
15 changes: 11 additions & 4 deletions sdk/metric/internal/aggregate/exponential_histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

Expand Down Expand Up @@ -682,22 +683,26 @@ func BenchmarkExponentialHistogram(b *testing.B) {

b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.CumulativeTemporality,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum)
}))
}
Expand Down Expand Up @@ -747,6 +752,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(4, 20, false, false)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -874,6 +880,7 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 2,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExponentialBucketHistogram(4, 20, false, false)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/internal/aggregate/filtered_reservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newFilteredExemplarReservoir[N int64 | float64](f exemplar.Filter, r exempl
}

func (f *filteredExemplarReservoir[N]) Offer(ctx context.Context, val N, attr []attribute.KeyValue) {
if f.filter != nil && f.filter(ctx) {
if f.filter(ctx) {
// only record the current time if we are sampling this measurement.
f.reservoir.Offer(ctx, time.Now(), exemplar.NewValue(val), attr)
}
Expand Down
15 changes: 11 additions & 4 deletions sdk/metric/internal/aggregate/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
)
Expand Down Expand Up @@ -54,6 +55,7 @@ func testDeltaHist[N int64 | float64](c conf[N]) func(t *testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, c.noSum)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -141,6 +143,7 @@ func testCumulativeHist[N int64 | float64](c conf[N]) func(t *testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, c.noSum)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -375,22 +378,26 @@ 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,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.ExplicitBucketHistogram(bounds, noMinMax, false)
}))
}
11 changes: 9 additions & 2 deletions sdk/metric/internal/aggregate/lastvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"testing"

"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

Expand Down Expand Up @@ -39,6 +40,7 @@ func testDeltaLastValue[N int64 | float64]() func(*testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.LastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -143,6 +145,7 @@ func testCumulativeLastValue[N int64 | float64]() func(*testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.LastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -265,6 +268,7 @@ func testDeltaPrecomputedLastValue[N int64 | float64]() func(*testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.PrecomputedLastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -369,6 +373,7 @@ func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.PrecomputedLastValue()
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -469,6 +474,8 @@ func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) {
}

func BenchmarkLastValue(b *testing.B) {
b.Run("Int64", benchmarkAggregate(Builder[int64]{}.PrecomputedLastValue))
b.Run("Float64", benchmarkAggregate(Builder[float64]{}.PrecomputedLastValue))
b.Run("Int64", benchmarkAggregate(Builder[int64]{
ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue))
b.Run("Float64", benchmarkAggregate(Builder[float64]{
ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue))
}
29 changes: 21 additions & 8 deletions sdk/metric/internal/aggregate/sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"testing"

"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

Expand Down Expand Up @@ -44,6 +45,7 @@ func testDeltaSum[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -172,6 +174,7 @@ func testCumulativeSum[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -286,6 +289,7 @@ func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -415,6 +419,7 @@ func testCumulativePrecomputedSum[N int64 | float64]() func(t *testing.T) {
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -544,43 +549,51 @@ 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,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(false)
}))
b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) {
return Builder[int64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(false)
}))
b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.CumulativeTemporality,
Temporality: metricdata.CumulativeTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(false)
}))
b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) {
return Builder[float64]{
Temporality: metricdata.DeltaTemporality,
Temporality: metricdata.DeltaTemporality,
ExemplarFilter: exemplar.AlwaysOffFilter,
}.Sum(false)
}))

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

0 comments on commit c968dc4

Please sign in to comment.