Skip to content

Commit

Permalink
Merge branch 'main' into refine-context-cancelation
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Jul 27, 2023
2 parents 111b6cc + b4264c5 commit bc6be57
Show file tree
Hide file tree
Showing 4 changed files with 504 additions and 415 deletions.
28 changes: 6 additions & 22 deletions sdk/metric/internal/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,23 @@ func (b Builder[N]) LastValue() (Measure[N], ComputeAggregation) {
// PrecomputedSum returns a sum aggregate function input and output. The
// arguments passed to the input are expected to be the precomputed sum values.
func (b Builder[N]) PrecomputedSum(monotonic bool) (Measure[N], ComputeAggregation) {
var s aggregator[N]
s := newPrecomputedSum[N](monotonic)
switch b.Temporality {
case metricdata.DeltaTemporality:
s = newPrecomputedDeltaSum[N](monotonic)
return b.filter(s.measure), s.delta
default:
s = newPrecomputedCumulativeSum[N](monotonic)
}

return b.input(s), func(dest *metricdata.Aggregation) int {
// TODO (#4220): optimize memory reuse here.
*dest = s.Aggregation()

sData, _ := (*dest).(metricdata.Sum[N])
return len(sData.DataPoints)
return b.filter(s.measure), s.cumulative
}
}

// Sum returns a sum aggregate function input and output.
func (b Builder[N]) Sum(monotonic bool) (Measure[N], ComputeAggregation) {
var s aggregator[N]
s := newSum[N](monotonic)
switch b.Temporality {
case metricdata.DeltaTemporality:
s = newDeltaSum[N](monotonic)
return b.filter(s.measure), s.delta
default:
s = newCumulativeSum[N](monotonic)
}

return b.input(s), func(dest *metricdata.Aggregation) int {
// TODO (#4220): optimize memory reuse here.
*dest = s.Aggregation()

sData, _ := (*dest).(metricdata.Sum[N])
return len(sData.DataPoints)
return b.filter(s.measure), s.cumulative
}
}

Expand Down
4 changes: 0 additions & 4 deletions sdk/metric/internal/aggregate/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ func monoIncr[N int64 | float64]() setMap[N] {
return setMap[N]{alice: 1, bob: 10, carol: 2}
}

func nonMonoIncr[N int64 | float64]() setMap[N] {
return setMap[N]{alice: 1, bob: -1, carol: 2}
}

// setMap maps attribute sets to a number.
type setMap[N int64 | float64] map[attribute.Set]N

Expand Down
Loading

0 comments on commit bc6be57

Please sign in to comment.