Skip to content

Commit 49ccc5d

Browse files
authored
fix(telemetrygen): fix histogram data points to comply with spec (#39025)
#### Description The HistogramDataPoint message has a couple of clear rules: the Count field must equal the total count of all buckets (if present), and the length of the bucket array must be one greater than the length of the boundary array. This fixes the telemetrygen histograms to conform to these rules. See https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto#L443
1 parent d36dbab commit 49ccc5d

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
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: telemetrygen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fixes invalid HistogramDataPoint messages generated by telemetrygen.
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: [39025]
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: The bucket count and total count are now correct.
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: [api]

cmd/telemetrygen/pkg/metrics/worker.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,52 @@ type worker struct {
3131
index int // worker index
3232
}
3333

34+
// We use a 15-element bounds slice for histograms below, so there must be 16 buckets here.
35+
// From metrics.proto:
36+
// The number of elements in bucket_counts array must be by one greater than
37+
// the number of elements in explicit_bounds array.
3438
var histogramBucketSamples = []struct {
3539
bucketCounts []uint64
3640
sum int64
3741
}{
3842
{
39-
[]uint64{0, 0, 1, 0, 0, 0, 3, 4, 1, 1, 0, 0, 0, 0, 0},
43+
[]uint64{0, 0, 1, 0, 0, 0, 3, 4, 1, 1, 0, 0, 0, 0, 0, 0},
4044
3940,
4145
},
4246
{
43-
[]uint64{0, 0, 0, 0, 0, 0, 2, 4, 4, 0, 0, 0, 0, 0, 0},
47+
[]uint64{0, 0, 0, 0, 0, 0, 2, 4, 4, 0, 0, 0, 0, 0, 0, 0},
4448
4455,
4549
},
4650
{
47-
[]uint64{0, 0, 0, 0, 0, 0, 1, 4, 3, 2, 0, 0, 0, 0, 0},
51+
[]uint64{0, 0, 0, 0, 0, 0, 1, 4, 3, 2, 0, 0, 0, 0, 0, 0},
4852
5337,
4953
},
5054
{
51-
[]uint64{0, 0, 1, 0, 1, 0, 2, 2, 1, 3, 0, 0, 0, 0, 0},
55+
[]uint64{0, 0, 1, 0, 1, 0, 2, 2, 1, 3, 0, 0, 0, 0, 0, 0},
5256
4477,
5357
},
5458
{
55-
[]uint64{0, 0, 0, 0, 0, 1, 3, 2, 2, 2, 0, 0, 0, 0, 0},
59+
[]uint64{0, 0, 0, 0, 0, 1, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0},
5660
4670,
5761
},
5862
{
59-
[]uint64{0, 0, 0, 1, 1, 0, 1, 1, 1, 5, 0, 0, 0, 0, 0},
63+
[]uint64{0, 0, 0, 1, 1, 0, 1, 1, 1, 5, 0, 0, 0, 0, 0, 0},
6064
5670,
6165
},
6266
{
63-
[]uint64{0, 0, 0, 0, 0, 2, 1, 1, 4, 2, 0, 0, 0, 0, 0},
67+
[]uint64{0, 0, 0, 0, 0, 2, 1, 1, 4, 2, 0, 0, 0, 0, 0, 0},
6468
5091,
6569
},
6670
{
67-
[]uint64{0, 0, 2, 0, 0, 0, 2, 4, 1, 1, 0, 0, 0, 0, 0},
71+
[]uint64{0, 0, 2, 0, 0, 0, 2, 4, 1, 1, 0, 0, 0, 0, 0, 0},
6872
3420,
6973
},
7074
{
71-
[]uint64{0, 0, 0, 0, 0, 0, 1, 3, 2, 4, 0, 0, 0, 0, 0},
75+
[]uint64{0, 0, 0, 0, 0, 0, 1, 3, 2, 4, 0, 0, 0, 0, 0, 0},
7276
5917,
7377
},
7478
{
75-
[]uint64{0, 0, 1, 0, 1, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0},
79+
[]uint64{0, 0, 1, 0, 1, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0},
7680
3988,
7781
},
7882
}
@@ -117,9 +121,13 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor
117121
},
118122
})
119123
case MetricTypeHistogram:
124+
var totalCount uint64
120125
iteration := uint64(i) % 10
121126
sum := histogramBucketSamples[iteration].sum
122127
bucketCounts := histogramBucketSamples[iteration].bucketCounts
128+
for _, count := range bucketCounts {
129+
totalCount += count
130+
}
123131
metrics = append(metrics, metricdata.Metrics{
124132
Name: w.metricName,
125133
Data: metricdata.Histogram[int64]{
@@ -130,7 +138,7 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor
130138
Time: time.Now(),
131139
Attributes: attribute.NewSet(signalAttrs...),
132140
Exemplars: w.exemplars,
133-
Count: iteration,
141+
Count: totalCount,
134142
Sum: sum,
135143
// Bounds from https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation
136144
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},

0 commit comments

Comments
 (0)