Skip to content

Commit 5d0a771

Browse files
authored
deltatocumulative: Fix selection of the target scale for exponential histograms (#37432)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description While addressing comments a bug was added to the logic of calculating of the desired scale and it slipped through tests. Fix the bug (use `min` instead of `max`) and update tests to avoid regressions in the future. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #37416 <!--Describe what testing was performed and which tests were added.--> #### Testing Update tests to separately cover positive and negative buckets. <!--Describe the documentation added.--> #### Documentation n/a <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 9982d2c commit 5d0a771

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: deltatocumulativeprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: In order to cap number of histogram buckets take the min of desired scale across negative and positive buckets instead of the max
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37416]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/deltatocumulativeprocessor/internal/data/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (dp ExpHistogram) Add(in ExpHistogram) ExpHistogram {
8080

8181
// Downscale if an expected number of buckets after the merge is too large.
8282
from := expo.Scale(dp.Scale())
83-
to := max(
83+
to := min(
8484
expo.Limit(maxBuckets, from, dp.Positive(), in.Positive()),
8585
expo.Limit(maxBuckets, from, dp.Negative(), in.Negative()),
8686
)

processor/deltatocumulativeprocessor/internal/data/expo_test.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ func TestExpoAdd(t *testing.T) {
2727
defer func() { maxBuckets = prevMaxBuckets }()
2828

2929
cases := []struct {
30-
name string
31-
dp, in expdp
32-
want expdp
33-
flip bool
30+
name string
31+
dp, in expdp
32+
want expdp
33+
flip bool
34+
alsoTryEachSign bool
3435
}{{
3536
name: "noop",
3637
dp: expdp{PosNeg: bins{0, 0, 0, 0, 0, 0, 0, 0}.Into(), Count: 0},
@@ -108,6 +109,7 @@ func TestExpoAdd(t *testing.T) {
108109
PosNeg: bins{3, 3, 3, 3, 3, 3, 3, 3}.Into(),
109110
Count: 24,
110111
},
112+
alsoTryEachSign: true,
111113
}, {
112114
name: "scale/downscale_once_exceeds_limit",
113115
dp: expdp{
@@ -125,6 +127,7 @@ func TestExpoAdd(t *testing.T) {
125127
PosNeg: rawbs([]uint64{2, 2, 2, 6, 4, 4, 4}, 0),
126128
Count: 24,
127129
},
130+
alsoTryEachSign: true,
128131
}, {
129132
name: "scale/downscale_multiple_times_until_within_limit",
130133
dp: expdp{
@@ -142,6 +145,7 @@ func TestExpoAdd(t *testing.T) {
142145
PosNeg: rawbs([]uint64{2, 4, 2, 4, 8, 4}, -2),
143146
Count: 24,
144147
},
148+
alsoTryEachSign: true,
145149
}, {
146150
name: "scale/ignore_leading_trailing_zeros_in_bucket_count",
147151
dp: expdp{
@@ -159,6 +163,7 @@ func TestExpoAdd(t *testing.T) {
159163
PosNeg: rawbs([]uint64{1, 7, 7, 4, 3, 2, 2}, 0),
160164
Count: 26,
161165
},
166+
alsoTryEachSign: true,
162167
}, {
163168
name: "scale/downscale_with_leading_trailing_zeros",
164169
dp: expdp{
@@ -176,17 +181,18 @@ func TestExpoAdd(t *testing.T) {
176181
PosNeg: rawbs([]uint64{11, 11, 0, 0, 12, 12}, -1),
177182
Count: 46,
178183
},
184+
alsoTryEachSign: true,
179185
}}
180186

181187
for _, cs := range cases {
182-
run := func(dp, in expdp) func(t *testing.T) {
188+
run := func(dp, in, want expdp) func(t *testing.T) {
183189
return func(t *testing.T) {
184190
is := datatest.New(t)
185191

186192
var (
187193
dp = ExpHistogram{dp.Into()}
188194
in = ExpHistogram{in.Into()}
189-
want = ExpHistogram{cs.want.Into()}
195+
want = ExpHistogram{want.Into()}
190196
)
191197

192198
dp.SetTimestamp(0)
@@ -199,14 +205,32 @@ func TestExpoAdd(t *testing.T) {
199205
}
200206

201207
if cs.flip {
202-
t.Run(cs.name+"-dp", run(cs.dp, cs.in))
203-
t.Run(cs.name+"-in", run(cs.in, cs.dp))
208+
t.Run(cs.name+"-dp", run(cs.dp, cs.in, cs.want))
209+
t.Run(cs.name+"-in", run(cs.in, cs.dp, cs.want))
204210
continue
205211
}
206-
t.Run(cs.name, run(cs.dp, cs.in))
212+
if cs.alsoTryEachSign {
213+
t.Run(cs.name+"-pos", run(clonePosExpdp(cs.dp), clonePosExpdp(cs.in), clonePosExpdp(cs.want)))
214+
t.Run(cs.name+"-neg", run(cloneNegExpdp(cs.dp), cloneNegExpdp(cs.in), cloneNegExpdp(cs.want)))
215+
}
216+
t.Run(cs.name, run(cs.dp, cs.in, cs.want))
207217
}
208218
}
209219

220+
func cloneNegExpdp(dp expotest.Histogram) expotest.Histogram {
221+
dp.Neg = pmetric.NewExponentialHistogramDataPointBuckets()
222+
dp.PosNeg.CopyTo(dp.Neg)
223+
dp.PosNeg = expo.Buckets{}
224+
return dp
225+
}
226+
227+
func clonePosExpdp(dp expotest.Histogram) expotest.Histogram {
228+
dp.Pos = pmetric.NewExponentialHistogramDataPointBuckets()
229+
dp.PosNeg.CopyTo(dp.Pos)
230+
dp.PosNeg = expo.Buckets{}
231+
return dp
232+
}
233+
210234
func rawbs(data []uint64, offset int32) expo.Buckets {
211235
bs := pmetric.NewExponentialHistogramDataPointBuckets()
212236
bs.BucketCounts().FromRaw(data)

0 commit comments

Comments
 (0)