in infra/utils/fbf/cmd/flaky.go [77:117]
func computeFlakesFromBuilds(builds []*build) map[string]flake {
flakes := make(map[string]flake)
for _, b1 := range builds {
// commit may have multiple builds so the key for flake lookup is
// computed from commitSHA and job name
flakeKey := fmt.Sprintf("%s-%s", b1.commitSHA, b1.jobName)
// skip if flakes with same flakeKey were previously computed
//todo(bharathkkb): optimize, we can probably remove elems in a flake from build slice
_, exists := flakes[flakeKey]
if exists {
continue
}
// store individual build info
passedBuildsWithCommit := make(map[string]*build)
failedBuildsWithCommit := make(map[string]*build)
storeBuildInfo := func(b *build) {
switch b.status {
case successStatus:
passedBuildsWithCommit[b.id] = b
case failedStatus:
failedBuildsWithCommit[b.id] = b
}
}
storeBuildInfo(b1)
for _, b2 := range builds {
// match other builds with same commit,repo and job
if b1.commitSHA == b2.commitSHA &&
b1.repoName == b2.repoName &&
b1.jobName == b2.jobName {
storeBuildInfo(b2)
}
}
// At least one pass and one fail for a given commit is necessary to become a flake
if len(passedBuildsWithCommit) > 0 && len(failedBuildsWithCommit) > 0 {
flakes[flakeKey] = flake{repo: b1.repoName, commitSHA: b1.commitSHA, passes: passedBuildsWithCommit, fails: failedBuildsWithCommit}
}
}
return flakes
}