Skip to content

Commit e7c5b97

Browse files
authored
[processor/deltatocumulativeprocessor]: fix incorrect bucket counts when downscaling exp histograms (#33831)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> The downscaling algorithm collapses bucket by pairing neighbors into new buckets. The simple case occurs when there is an even number of buckets and offset is zero or even. ``` 1 1 1 1 2 2 ``` When there is an odd number of buckets, the last bucket is accounted for by incrementing the `size` variable to ensure an extra loop iteration. ``` 1 1 1 2 1 ``` When offset is odd, the first bucket is accounted for by special handling in the loop. ``` ø 1 1 1 1 2 ``` However, when there is an even number of buckets, AND an odd offset, this happens: ``` ø 1 1 1 0 ``` The collapsed buckets are incorrect because the buckets sum up to 1 (1+0) instead of 2 (1+1). Handle this edge case by incrementing the `size` variable when offset is odd ``` ø 1 1 1 1 ``` **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> Added some test cases to showcase the bug. **Documentation:** <Describe the documentation added.>
1 parent 54af4bd commit e7c5b97

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
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: fix bucket counts when downscaling exp histograms with odd offsets
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: [33831]
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/expo/scale.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func Downscale(bs Buckets, from, to Scale) {
7272
func Collapse(bs Buckets) {
7373
counts := bs.BucketCounts()
7474
size := counts.Len() / 2
75-
if counts.Len()%2 != 0 {
75+
if counts.Len()%2 != 0 || bs.Offset()%2 != 0 {
7676
size++
7777
}
7878

processor/deltatocumulativeprocessor/internal/data/expo/scale_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ func TestDownscale(t *testing.T) {
4545
}, {
4646
{scale: 2, bkt: "1 1 1 1 1 1 1 1 1 1 1 1"},
4747
{scale: 0, bkt: " 4 4 4 "},
48+
}, {
49+
{scale: 1, bkt: "ø 1 1 0"},
50+
{scale: 0, bkt: " 1 1 "},
51+
}, {
52+
{scale: 1, bkt: "ø 1 1 "},
53+
{scale: 0, bkt: " 1 1"},
54+
}, {
55+
{scale: 1, bkt: " - 1 1 "},
56+
{scale: 0, bkt: "- 1 1"},
57+
}, {
58+
{scale: 5, bkt: "- 4 0 3 0 3 0 0 8 "},
59+
{scale: 4, bkt: "- 4 3 3 0 8 "},
4860
}}
4961

5062
type B = expo.Buckets
@@ -58,6 +70,10 @@ func TestDownscale(t *testing.T) {
5870
bkt.SetOffset(bkt.Offset() + 1)
5971
continue
6072
}
73+
if elem == "-" {
74+
bkt.SetOffset(bkt.Offset() - 1)
75+
continue
76+
}
6177
n, err := strconv.Atoi(elem)
6278
if err != nil {
6379
panic(err)

0 commit comments

Comments
 (0)