Skip to content

Commit f7f02fe

Browse files
committed
Minor cleanup work from PR review
1 parent dffa311 commit f7f02fe

File tree

7 files changed

+134
-243
lines changed

7 files changed

+134
-243
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ replace github.com/influxdata/telegraf => github.com/aws/telegraf v0.10.2-0.2025
66

77
replace collectd.org v0.4.0 => github.com/collectd/go-collectd v0.4.0
88

9-
replace code.cloudfoundry.org/clock => github.com/cloudfoundry/clock v1.0.0
10-
119
// Replace with https://github.com/amazon-contributing/opentelemetry-collector-contrib, there are no requirements for all receivers/processors/exporters
1210
// to be all replaced since there are some changes that will always be from upstream
1311
replace (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
4646
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
4747
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
4848
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
49+
code.cloudfoundry.org/clock v1.0.0 h1:kFXWQM4bxYvdBw2X8BbBeXwQNgfoWv1vqAk2ZZyBN2o=
50+
code.cloudfoundry.org/clock v1.0.0/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
4951
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
5052
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
5153
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
@@ -398,8 +400,6 @@ github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5P
398400
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
399401
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg=
400402
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
401-
github.com/cloudfoundry/clock v1.0.0 h1:eKdoEckIniCXbwfL4u5BV+8TTiv/zkWLr8OdEfdkfJY=
402-
github.com/cloudfoundry/clock v1.0.0/go.mod h1:JXXHhAXLubRvUw6+f17a/0eNz6cQ85bkgYaiQA0Cm6M=
403403
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
404404
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
405405
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=

metric/distribution/exph/exph.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (d *ExpHistogramDistribution) ValuesAndCounts() ([]float64, []float64) {
9393
counts = append(counts, float64(d.zeroCount))
9494
}
9595

96-
// iterate through negative buckets in ascending order
96+
// iterate through negative buckets in ascending order so that the values array is entirely descending
9797
negOffsetIndicies := slices.Sorted(maps.Keys(d.negativeBuckets))
9898
for _, offsetIndex := range negOffsetIndicies {
9999
counter := d.negativeBuckets[offsetIndex]
@@ -107,13 +107,9 @@ func (d *ExpHistogramDistribution) ValuesAndCounts() ([]float64, []float64) {
107107
return values, counts
108108
}
109109

110-
func (d *ExpHistogramDistribution) AddDistribution(other *ExpHistogramDistribution) {
111-
d.AddDistributionWithWeight(other, 1)
112-
}
113-
114-
func (d *ExpHistogramDistribution) AddDistributionWithWeight(from *ExpHistogramDistribution, weight float64) {
115-
if from.SampleCount()*weight <= 0 {
116-
log.Printf("D! SampleCount * Weight should be larger than 0: %v, %v", from.SampleCount(), weight)
110+
func (d *ExpHistogramDistribution) AddDistribution(from *ExpHistogramDistribution) {
111+
if from.SampleCount() <= 0 {
112+
log.Printf("D! SampleCount should be larger than 0: %v", from.SampleCount())
117113
return
118114
}
119115

@@ -131,8 +127,8 @@ func (d *ExpHistogramDistribution) AddDistributionWithWeight(from *ExpHistogramD
131127

132128
d.max = max(d.max, from.Maximum())
133129
d.min = min(d.min, from.Minimum())
134-
d.sampleCount += from.SampleCount() * weight
135-
d.sum += from.Sum() * weight
130+
d.sampleCount += from.SampleCount()
131+
d.sum += from.Sum()
136132

137133
for i := range from.positiveBuckets {
138134
d.positiveBuckets[i] += from.positiveBuckets[i]

metric/distribution/exph/mapping.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@ package exph
77

88
import "math"
99

10-
// MapToIndexScale0 computes a bucket index at scale 0.
11-
func MapToIndexScale0(value float64) int {
12-
// Note: Frexp() rounds submnormal values to the smallest normal
13-
// value and returns an exponent corresponding to fractions in the
14-
// range [0.5, 1), whereas an exponent for the range [1, 2), so
15-
// subtract 1 from the exponent immediately.
16-
frac, exp := math.Frexp(value)
17-
exp--
18-
19-
if frac == 0.5 && value > 0 {
20-
// Special case for positive powers of two: they fall into the bucket
21-
// numbered one less.
22-
exp--
23-
}
24-
return exp
25-
}
26-
27-
// MapToIndexNegativeScale computes a bucket index for scales <= 0.
28-
func MapToIndexNegativeScale(value float64, scale int) int {
29-
return MapToIndexScale0(value) >> -scale
30-
}
31-
3210
// MapToIndex for any scale
3311
//
3412
// Values near a boundary could be mapped into the incorrect bucket due to float point calculation inaccuracy.

metric/distribution/exph/mapping_test.go

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -54,87 +54,6 @@ func TestMapToIndexPositiveScale(t *testing.T) {
5454

5555
}
5656

57-
func TestMapToIndexScale0(t *testing.T) {
58-
tests := []struct {
59-
name string
60-
values []float64
61-
expected []int
62-
}{
63-
{
64-
name: "positive value inside bucket",
65-
values: []float64{1.5, 3.0, 6, 12, 18},
66-
expected: []int{0, 1, 2, 3, 4},
67-
},
68-
{
69-
// for negative values, histogram buckets use lower-inclusive boundaries
70-
name: "positive value is on boundary",
71-
values: []float64{2, 4, 8, 16.0, 32},
72-
expected: []int{0, 1, 2, 3, 4},
73-
},
74-
{
75-
name: "negative value inside bucket",
76-
values: []float64{-1.5, -3.0, -6, -12, -18},
77-
expected: []int{0, 1, 2, 3, 4},
78-
},
79-
{
80-
// for negative values, histogram buckets use lower-inclusive boundaries
81-
name: "negative value is on boundary",
82-
values: []float64{-2, -4, -8, -16, -32},
83-
expected: []int{1, 2, 3, 4, 5},
84-
},
85-
}
86-
for _, tt := range tests {
87-
t.Run(tt.name, func(t *testing.T) {
88-
for i, value := range tt.values {
89-
assert.Equal(t, tt.expected[i], MapToIndexNegativeScale(value, 0), "expected value %f to map to index %d with scale 0", value, tt.expected[i])
90-
}
91-
})
92-
}
93-
}
94-
95-
func TestMapToIndexNegativeScale(t *testing.T) {
96-
tests := []struct {
97-
name string
98-
scale int
99-
values []float64
100-
expected []int
101-
}{
102-
{
103-
name: "positive value inside bucket",
104-
scale: -1,
105-
values: []float64{1.5, 5.0, 32, 80, 500, 2000},
106-
expected: []int{0, 1, 2, 3, 4, 5},
107-
},
108-
{
109-
// for positive values, histogram buckets use upper-inclusive boundaries
110-
name: "positive value is on boundary",
111-
scale: -1,
112-
values: []float64{4, 16, 64, 256, 1024},
113-
expected: []int{0, 1, 2, 3, 4, 5},
114-
},
115-
{
116-
name: "negative value inside bucket",
117-
scale: -1,
118-
values: []float64{-1.5, -5.0, -32, -80, -500, -2000},
119-
expected: []int{0, 1, 2, 3, 4, 5},
120-
},
121-
{
122-
// for negative values, histogram buckets use lower-inclusive boundaries
123-
name: "negative value is on boundary",
124-
scale: -1,
125-
values: []float64{-1, -4, -16, -64, -256, -1024},
126-
expected: []int{0, 1, 2, 3, 4, 5, 6},
127-
},
128-
}
129-
for _, tt := range tests {
130-
t.Run(tt.name, func(t *testing.T) {
131-
for i, value := range tt.values {
132-
assert.Equal(t, tt.expected[i], MapToIndexNegativeScale(value, tt.scale), "expected value %f to map to index %d with scale %d", value, tt.expected[i], tt.scale)
133-
}
134-
})
135-
}
136-
}
137-
13857
func TestLowerBoundary(t *testing.T) {
13958
// scale = 1, base = 2^(1/2) or sqrt(2) = 1.41421
14059
assert.InDelta(t, 1.41421, LowerBoundary(1, 1), 0.01) // 2^(1/2)

0 commit comments

Comments
 (0)