Skip to content

Commit 388ebf7

Browse files
roachtest: fix division by zero in metric aggregation functions
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
1 parent e582e3c commit 388ebf7

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
@@ -134,6 +134,9 @@ func registerTPCHBenchSpec(r registry.Registry, b tpchBenchSpec) {
134134
totalMeanCount++
135135
}
136136

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

0 commit comments

Comments
 (0)