Skip to content

Commit

Permalink
Test sum limits
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Dec 6, 2023
1 parent c2d5246 commit 426b29d
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 8 deletions.
4 changes: 4 additions & 0 deletions sdk/metric/internal/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ var (
keyUser = "user"
userAlice = attribute.String(keyUser, "Alice")
userBob = attribute.String(keyUser, "Bob")
userCarol = attribute.String(keyUser, "Carol")
userDave = attribute.String(keyUser, "Dave")
adminTrue = attribute.Bool("admin", true)
adminFalse = attribute.Bool("admin", false)

alice = attribute.NewSet(userAlice, adminTrue)
bob = attribute.NewSet(userBob, adminFalse)
carol = attribute.NewSet(userCarol, adminFalse)
dave = attribute.NewSet(userDave, adminFalse)

// Filtered.
attrFltr = func(kv attribute.KeyValue) bool {
Expand Down
162 changes: 154 additions & 8 deletions sdk/metric/internal/aggregate/sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ 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,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -125,14 +126,51 @@ func testDeltaSum[N int64 | float64]() func(t *testing.T) {
},
},
},
{
input: []arg[N]{
{ctx, 1, alice},
{ctx, 1, bob},
// These will exceed cardinality limit.
{ctx, 1, carol},
{ctx, 1, dave},
},
expect: output{
n: 3,
agg: metricdata.Sum[N]{
IsMonotonic: mono,
Temporality: metricdata.DeltaTemporality,
DataPoints: []metricdata.DataPoint[N]{
{
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: fltrBob,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: overflowSet,
StartTime: staticTime,
Time: staticTime,
Value: 2,
},
},
},
},
},
})
}

func testCumulativeSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
}.Sum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -204,14 +242,49 @@ func testCumulativeSum[N int64 | float64]() func(t *testing.T) {
},
},
},
{
input: []arg[N]{
// These will exceed cardinality limit.
{ctx, 1, carol},
{ctx, 1, dave},
},
expect: output{
n: 3,
agg: metricdata.Sum[N]{
IsMonotonic: mono,
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.DataPoint[N]{
{
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Value: 14,
},
{
Attributes: fltrBob,
StartTime: staticTime,
Time: staticTime,
Value: -8,
},
{
Attributes: overflowSet,
StartTime: staticTime,
Time: staticTime,
Value: 2,
},
},
},
},
},
})
}

func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
Temporality: metricdata.DeltaTemporality,
Filter: attrFltr,
AggregationLimit: 3,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -296,14 +369,51 @@ func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) {
},
},
},
{
input: []arg[N]{
{ctx, 1, alice},
{ctx, 1, bob},
// These will exceed cardinality limit.
{ctx, 1, carol},
{ctx, 1, dave},
},
expect: output{
n: 3,
agg: metricdata.Sum[N]{
IsMonotonic: mono,
Temporality: metricdata.DeltaTemporality,
DataPoints: []metricdata.DataPoint[N]{
{
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: fltrBob,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: overflowSet,
StartTime: staticTime,
Time: staticTime,
Value: 2,
},
},
},
},
},
})
}

func testCumulativePrecomputedSum[N int64 | float64]() func(t *testing.T) {
mono := false
in, out := Builder[N]{
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
Temporality: metricdata.CumulativeTemporality,
Filter: attrFltr,
AggregationLimit: 3,
}.PrecomputedSum(mono)
ctx := context.Background()
return test[N](in, out, []teststep[N]{
Expand Down Expand Up @@ -388,6 +498,42 @@ func testCumulativePrecomputedSum[N int64 | float64]() func(t *testing.T) {
},
},
},
{
input: []arg[N]{
{ctx, 1, alice},
{ctx, 1, bob},
// These will exceed cardinality limit.
{ctx, 1, carol},
{ctx, 1, dave},
},
expect: output{
n: 3,
agg: metricdata.Sum[N]{
IsMonotonic: mono,
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.DataPoint[N]{
{
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: fltrBob,
StartTime: staticTime,
Time: staticTime,
Value: 1,
},
{
Attributes: overflowSet,
StartTime: staticTime,
Time: staticTime,
Value: 2,
},
},
},
},
},
})
}

Expand Down

0 comments on commit 426b29d

Please sign in to comment.