Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation of Sum aggregators #3000

Merged
merged 42 commits into from
Aug 4, 2022
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
405c377
Implement the sum aggregators
MrAlias Jul 7, 2022
a138c5f
Add unit tests for delta/cumulative sums
MrAlias Jul 7, 2022
4ba0c4c
Add benchmarks
MrAlias Jul 7, 2022
f4237c1
Merge sum tests into one
MrAlias Jul 7, 2022
1397f4c
Remove unused start time from cumulative sum
MrAlias Jul 7, 2022
31adb7f
Refactor benchmark tests
MrAlias Jul 7, 2022
3ad3c89
goimports
MrAlias Jul 8, 2022
4b78904
Move timestamp out of lock
MrAlias Jul 8, 2022
090fb3b
Refactor testing
MrAlias Jul 8, 2022
1166395
Fix spelling mistake
MrAlias Jul 8, 2022
0a01d06
Name param of expectFunc
MrAlias Jul 8, 2022
9e9a0ad
Reset delta sum to zero instead of delete
MrAlias Jul 8, 2022
2b1741b
Revert to deleting unused attr sets
MrAlias Jul 11, 2022
2399af3
Refactor testing to allow use across other aggs
MrAlias Jul 11, 2022
45b07ed
Add TODO to bound cumulative sum mem usage
MrAlias Jul 11, 2022
ee4ce7b
Fix misspelling
MrAlias Jul 11, 2022
f125d53
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 11, 2022
4311369
Unify aggregator benchmark code in aggregator_test
MrAlias Jul 11, 2022
02cdb3a
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 21, 2022
d483c2a
Use generic DataPoint value
MrAlias Jul 21, 2022
5f72d60
Fix assertion_fail_test.go
MrAlias Jul 22, 2022
b5732c0
Merge branch 'generic-metricdata' into sum-agg-impl
MrAlias Jul 22, 2022
17b4e8f
Use generic metricdata types
MrAlias Jul 22, 2022
e48ad68
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 25, 2022
dcbfd9a
Fix tests
MrAlias Jul 25, 2022
292898c
Fix benchmarks
MrAlias Jul 25, 2022
b911e60
Fix lint
MrAlias Jul 26, 2022
86971db
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 26, 2022
840ca2e
Update sum documentation
MrAlias Jul 26, 2022
bcf2fc5
Remove leftover encapsulating test run
MrAlias Jul 26, 2022
1fe3558
Use t.Cleanup to mock time
MrAlias Jul 26, 2022
16359dd
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 27, 2022
3c7a389
Consolidate expecter logic into funcs
MrAlias Jul 27, 2022
2745e1c
Move errNegVal closer to use
MrAlias Jul 27, 2022
c4ad8ac
Run the agg test
MrAlias Jul 27, 2022
e7b779f
Add tests for monotonic sum Aggregate err
MrAlias Jul 27, 2022
cfd7d87
Run make lint
MrAlias Jul 27, 2022
4db6b90
Make monotonic an arg of creation funcs
MrAlias Jul 27, 2022
f01d942
Remove Aggregate monotonic validation
MrAlias Jul 27, 2022
6fed240
Rename sum to valueMap
MrAlias Jul 27, 2022
b2486fa
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Jul 28, 2022
672e8b2
Merge branch 'new_sdk/main' into sum-agg-impl
MrAlias Aug 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reset delta sum to zero instead of delete
MrAlias committed Jul 8, 2022

Verified

This commit was signed with the committer’s verified signature.
MrAlias Tyler Yahn
commit 9e9a0ad72dfd69c7ef15cf1060a3436db9a8e424
3 changes: 2 additions & 1 deletion sdk/metric/internal/sum.go
Original file line number Diff line number Diff line change
@@ -64,13 +64,14 @@ func (s *deltaSum[N]) Aggregations() []Aggregation {
defer s.Unlock()

aggs := make([]Aggregation, 0, len(s.values))
var zero N
for attr, value := range s.values {
aggs = append(aggs, Aggregation{
Timestamp: now,
Attributes: attr,
Value: SingleValue[N]{Value: value},
})
delete(s.values, attr)
s.values[attr] = zero
}

return aggs
25 changes: 25 additions & 0 deletions sdk/metric/internal/sum_test.go
Original file line number Diff line number Diff line change
@@ -133,6 +133,31 @@ func cumulativeExpecter[N int64 | float64](incr map[attribute.Set]N) func() map[
}
}

func testDeltaSumReset[N int64 | float64](a Aggregator[N]) func(*testing.T) {
return func(t *testing.T) {
expect := make(map[attribute.Set]N)
assertMap(t, expect, aggregationsToMap[N](a.Aggregations()))

a.Aggregate(1, alice)
expect[alice] = 1
assertMap(t, expect, aggregationsToMap[N](a.Aggregations()))

// The sum should be reset to zero once Aggregations is called.
expect[alice] = 0
assertMap(t, expect, aggregationsToMap[N](a.Aggregations()))

// Aggregating another set should not affect the original (alice).
a.Aggregate(1, bob)
expect[bob] = 1
assertMap(t, expect, aggregationsToMap[N](a.Aggregations()))
}
}

func TestDeltaSumReset(t *testing.T) {
t.Run("Int64", testDeltaSumReset(NewDeltaSum[int64]()))
t.Run("Float64", testDeltaSumReset(NewDeltaSum[float64]()))
}

var result []Aggregation

func benchmarkAggregatorN[N int64 | float64](b *testing.B, factory func() Aggregator[N], count int) {