Skip to content

Commit

Permalink
walk: sort slices for reproducibility
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
MichaHoffmann committed Dec 6, 2023
1 parent 0d99c83 commit 3ae2233
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
"sort"
"strings"
"time"

"github.com/prometheus/prometheus/model/labels"
Expand Down Expand Up @@ -244,6 +245,7 @@ func (s *PromQLSmith) walkCall(valueTypes ...parser.ValueType) parser.Expr {
}
}
}
sort.Slice(funcs, func(i, j int) bool { return strings.Compare(funcs[i].Name, funcs[j].Name) < 0 })
expr.Func = funcs[s.rnd.Intn(len(funcs))]
s.walkFuncArgs(expr)
return expr
Expand Down Expand Up @@ -383,6 +385,7 @@ func exprsFromValueTypes(valueTypes []parser.ValueType) []ExprType {
for expr := range set {
res = append(res, expr)
}
sort.Slice(res, func(i, j int) bool { return res[i] < res[j] })
return res
}

Expand All @@ -407,6 +410,7 @@ func keepValueTypes(input []parser.ValueType, keep []parser.ValueType) []parser.
out = append(out, vt)
}
}
sort.Slice(out, func(i, j int) bool { return out[i] < out[j] })
return out
}

Expand Down

0 comments on commit 3ae2233

Please sign in to comment.