Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x](backport #41822) [xpack][metricbeats][gcp] don't skip first value in histogram calculations #41870

Merged
merged 2 commits into from
Dec 23, 2024
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: 0 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Don't skip first bucket value in GCP metrics metricset for distribution type metrics {pull}41822[41822]
- Fixed `creation_date` scientific notation output in the `elasticsearch.index` metricset. {pull}42053[42053]


*Osquerybeat*


Expand Down
14 changes: 6 additions & 8 deletions x-pack/metricbeat/module/gcp/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func calcLinearUpperBound(bucket *distribution.Distribution_BucketOptions_Linear
return bucket.Offset + (bucket.Width * float64(i))
}

func createHistogram(values []float64, counts []uint64) mapstr.M {
func createHistogram(values []float64, counts []int64) mapstr.M {
return mapstr.M{
"values": values,
"counts": counts,
Expand All @@ -62,11 +62,11 @@ func createHistogram(values []float64, counts []uint64) mapstr.M {

func DistributionHistogramToES(d *distribution.Distribution) mapstr.M {
if !containsHistogram(d) {
return createHistogram([]float64{}, []uint64{})
return createHistogram([]float64{}, []int64{})
}

values := make([]float64, 0, len(d.BucketCounts))
counts := make([]uint64, 0, len(d.BucketCounts))
counts := make([]int64, 0, len(d.BucketCounts))

switch {
case d.BucketOptions.GetExplicitBuckets() != nil:
Expand All @@ -79,19 +79,17 @@ func DistributionHistogramToES(d *distribution.Distribution) mapstr.M {
bucket := d.BucketOptions.GetExponentialBuckets()

for i := range d.BucketCounts {
values = append(values, calcExponentialUpperBound(bucket, i+1))
values = append(values, calcExponentialUpperBound(bucket, i))
}
case d.BucketOptions.GetLinearBuckets() != nil:
bucket := d.BucketOptions.GetLinearBuckets()

for i := range d.BucketCounts {
values = append(values, calcLinearUpperBound(bucket, i+1))
values = append(values, calcLinearUpperBound(bucket, i))
}
}

for i := range d.BucketCounts {
counts = append(counts, uint64(d.BucketCounts[i]))
}
counts = append(counts, d.BucketCounts...)

return createHistogram(values, counts)
}
12 changes: 6 additions & 6 deletions x-pack/metricbeat/module/gcp/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDistributionHistogramToES(t *testing.T) {
},
},
expected: mapstr.M{
"counts": []uint64{0, 0, 0, 6, 1, 1},
"counts": []int64{0, 0, 0, 6, 1, 1},
"values": []float64{0, 1, 2, 5, 10, 20},
},
},
Expand All @@ -63,8 +63,8 @@ func TestDistributionHistogramToES(t *testing.T) {
},
},
expected: mapstr.M{
"counts": []uint64{0, 0, 3, 1},
"values": []float64{6, 12, 24, 48},
"counts": []int64{0, 0, 3, 1},
"values": []float64{3, 6, 12, 24},
},
},
},
Expand All @@ -86,8 +86,8 @@ func TestDistributionHistogramToES(t *testing.T) {
},
},
expected: mapstr.M{
"counts": []uint64{0, 1, 2, 0},
"values": []float64{20, 35, 50, 65},
"counts": []int64{0, 1, 2, 0},
"values": []float64{5, 20, 35, 50},
},
},
},
Expand All @@ -107,7 +107,7 @@ func TestDistributionHistogramToES(t *testing.T) {
},
},
expected: mapstr.M{
"counts": []uint64{},
"counts": []int64{},
"values": []float64{},
},
},
Expand Down
111 changes: 99 additions & 12 deletions x-pack/metricbeat/module/gcp/pubsub/_meta/data_topic.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,112 @@
"module": "gcp"
},
"gcp": {
"labels": {
"resource": {
"topic_id": "test-ks"
}
},
"pubsub": {
"topic": {
"message_sizes": {
"bucket_options": {
"Options": {
"ExponentialBuckets": {
"num_finite_buckets": 16,
"growth_factor": 4,
"scale": 1
}
"bytes": {
"histogram": {
"values": [
1,
1.2,
1.44,
1.728,
2.0736,
2.48832,
2.9859839999999997,
3.5831807999999996,
4.299816959999999,
5.159780351999999,
6.191736422399999,
7.430083706879999,
8.916100448255998,
10.699320537907198,
12.839184645488636,
15.407021574586365,
18.488425889503635,
22.18611106740436,
26.623333280885234,
31.94799993706228,
38.33759992447474,
46.00511990936968,
55.20614389124361,
66.24737266949234,
79.4968472033908,
95.39621664406897,
114.47545997288276,
137.3705519674593,
164.84466236095116,
197.8135948331414,
237.37631379976966,
284.8515765597236,
341.82189187166824,
410.18627024600187,
492.22352429520225,
590.6682291542427,
708.8018749850912,
850.5622499821095,
1020.6746999785313,
1224.8096399742376,
1469.771567969085,
1763.725881562902,
2116.4710578754825,
2539.7652694505787
],
"counts": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
10,
3,
2
]
}
}
}
}
},
"labels": {
"resource": {
"topic_id": "test-topic"
}
}
},
"metricset": {
Expand Down
Loading