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 @@ -3,6 +3,7 @@
* [FEATURE] New encoding vParquet3 with support for dedicated attribute columns (@mapno, @stoewer) [#2649](https://github.com/grafana/tempo/pull/2649)
* [ENHANCEMENT] Assert ingestion rate limits as early as possible [#2640](https://github.com/grafana/tempo/pull/2703) (@mghildiy)
* [ENHANCEMENT] Add several metrics-generator fields to user-configurable overrides [#2711](https://github.com/grafana/tempo/pull/2711) (@kvrhdn)
* [BUGFIX] Fix panic in metrics summary api [#2738](https://github.com/grafana/tempo/pull/2738) (@mdisibio)

## v2.2.0 / 2023-07-31

Expand Down
10 changes: 8 additions & 2 deletions pkg/traceqlmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"github.com/pkg/errors"
)

const maxBuckets = 64

type LatencyHistogram struct {
buckets [64]int // Exponential buckets, powers of 2
buckets [maxBuckets]int // Exponential buckets, powers of 2
}

func New(buckets [64]int) *LatencyHistogram {
func New(buckets [maxBuckets]int) *LatencyHistogram {
return &LatencyHistogram{buckets: buckets}
}

Expand All @@ -26,6 +28,10 @@ func (m *LatencyHistogram) Record(durationNanos uint64) {
if durationNanos >= 2 {
bucket = int(math.Ceil(math.Log2(float64(durationNanos))))
}
if bucket >= maxBuckets {
bucket = maxBuckets - 1
}

m.buckets[bucket]++
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/traceqlmetrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package traceqlmetrics

import (
"context"
"math"
"testing"

"github.com/grafana/tempo/pkg/traceql"
Expand Down Expand Up @@ -39,6 +40,12 @@ func TestPercentile(t *testing.T) {
p: 1.0,
value: uint64(1),
},
{
name: "edge case max bucket",
durations: []uint64{math.MaxUint64},
p: 1.0,
value: uint64(1 << (maxBuckets - 1)),
},
{
name: "edge case empty",
durations: []uint64{},
Expand Down