Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add experimental observability metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric`. (#7492)
- Improve the concurrent performance of `HistogramReservoir` in `go.opentelemetry.io/otel/sdk/metric/exemplar` by 4x. (#7443)
- Improve performance of concurrent synchronous gauge measurements in `go.opentelemetry.io/otel/sdk/metric`. (#7478)
- Improve performance of concurrent exponential histogram measurements in `go.opentelemetry.io/otel/sdk/metric`. (#7702)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
25 changes: 17 additions & 8 deletions sdk/metric/internal/aggregate/exponential_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ type expoHistogramDataPoint[N int64 | float64] struct {
attrs attribute.Set
res FilteredExemplarReservoir[N]

count uint64
min N
max N
sum N
min N
max N
sum N

maxSize int
noMinMax bool
Expand Down Expand Up @@ -74,8 +73,6 @@ func newExpoHistogramDataPoint[N int64 | float64](

// record adds a new measurement to the histogram. It will rescale the buckets if needed.
func (p *expoHistogramDataPoint[N]) record(v N) {
p.count++

if !p.noMinMax {
if v < p.min {
p.min = v
Expand Down Expand Up @@ -193,6 +190,10 @@ func (p *expoHistogramDataPoint[N]) scaleChange(bin, startBin int32, length int)
return count
}

func (p *expoHistogramDataPoint[N]) count() uint64 {
return p.posBuckets.count() + p.negBuckets.count() + p.zeroCount
}

// expoBuckets is a set of buckets in an exponential histogram.
type expoBuckets struct {
startBin int32
Expand Down Expand Up @@ -285,6 +286,14 @@ func (b *expoBuckets) downscale(delta int32) {
b.startBin >>= delta
}

func (b *expoBuckets) count() uint64 {
var total uint64
for _, count := range b.counts {
total += count
}
return total
}

// newExponentialHistogram returns an Aggregator that summarizes a set of
// measurements as an exponential histogram. Each histogram is scoped by attributes
// and the aggregation cycle the measurements were made in.
Expand Down Expand Up @@ -376,7 +385,7 @@ func (e *expoHistogram[N]) delta(
hDPts[i].Attributes = val.attrs
hDPts[i].StartTime = e.start
hDPts[i].Time = t
hDPts[i].Count = val.count
hDPts[i].Count = val.count()
hDPts[i].Scale = val.scale
hDPts[i].ZeroCount = val.zeroCount
hDPts[i].ZeroThreshold = 0.0
Expand Down Expand Up @@ -439,7 +448,7 @@ func (e *expoHistogram[N]) cumulative(
hDPts[i].Attributes = val.attrs
hDPts[i].StartTime = e.start
hDPts[i].Time = t
hDPts[i].Count = val.count
hDPts[i].Count = val.count()
hDPts[i].Scale = val.scale
hDPts[i].ZeroCount = val.zeroCount
hDPts[i].ZeroThreshold = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ func TestSubNormal(t *testing.T) {
want := &expoHistogramDataPoint[float64]{
attrs: alice,
maxSize: 4,
count: 3,
min: math.SmallestNonzeroFloat64,
max: math.SmallestNonzeroFloat64,
sum: 3 * math.SmallestNonzeroFloat64,
Expand Down