Skip to content

Commit e860c36

Browse files
craig[bot]shailendra-patel
andcommitted
Merge #153383
153383: roachtest: fix division by zero in metric aggregation functions r=shailendra-patel a=shailendra-patel Add safety checks to prevent division by zero and handle empty data in metric processing: - Skip summaries with TotalElapsed=0 in `DefaultProcessFunction`. - Return error for empty histogram summaries in `restoreAggregateFunction`. - Only calculate mean when totalMeanCount > 0 in `tpchbench` aggregation. These changes prevent runtime panics when processing metrics with missing or invalid data. The changes were initially introduced in #138617 Epic: none Release note: None Co-authored-by: Shailendra Patel <[email protected]>
2 parents 2b99f4e + 388ebf7 commit e860c36

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

pkg/cmd/roachtest/registry/test_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ var PrometheusNameSpace = "roachtest"
2929
var DefaultProcessFunction = func(test string, histograms *roachtestutil.HistogramMetric) (roachtestutil.AggregatedPerfMetrics, error) {
3030
totalOps := 0.0
3131
for _, summary := range histograms.Summaries {
32+
if summary.TotalElapsed == 0 {
33+
continue
34+
}
3235
totalOps += float64(summary.TotalCount*1000) / float64(summary.TotalElapsed)
3336
}
3437

pkg/cmd/roachtest/tests/restore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ import (
4242
)
4343

4444
var restoreAggregateFunction = func(test string, histogram *roachtestutil.HistogramMetric) (roachtestutil.AggregatedPerfMetrics, error) {
45+
if len(histogram.Summaries) == 0 {
46+
return roachtestutil.AggregatedPerfMetrics{}, errors.New("histogram has no summaries")
47+
}
48+
4549
metricValue := histogram.Summaries[0].HighestTrackableValue / 1e9
4650

4751
return roachtestutil.AggregatedPerfMetrics{

pkg/cmd/roachtest/tests/tpchbench.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func registerTPCHBenchSpec(r registry.Registry, b tpchBenchSpec) {
135135
totalMeanCount++
136136
}
137137

138+
if totalMeanCount == 0 {
139+
totalMeanCount = 1 // Avoid division by zero.
140+
}
138141
aggregatedMetrics := roachtestutil.AggregatedPerfMetrics{
139142
{
140143
Name: test + "_mean_latency",

0 commit comments

Comments
 (0)