github.com/abayer/test-infra@v0.0.5/mungegithub/mungers/old-test-getter.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mungers 18 19 import ( 20 "fmt" 21 "strconv" 22 23 "k8s.io/apimachinery/pkg/util/sets" 24 "k8s.io/test-infra/mungegithub/features" 25 "k8s.io/test-infra/mungegithub/github" 26 "k8s.io/test-infra/mungegithub/mungers/e2e" 27 "k8s.io/test-infra/mungegithub/options" 28 29 "github.com/golang/glog" 30 ) 31 32 // OldTestGetter files issues for flaky tests. 33 type OldTestGetter struct { 34 // Keep track of which jobs we've done this for. 35 numberOfOldTestsToGet int 36 ran map[string]bool 37 pullJobToLastRun map[string]int 38 sq *SubmitQueue 39 } 40 41 func init() { 42 RegisterMungerOrDie(&OldTestGetter{}) 43 } 44 45 // Name is the name usable in --pr-mungers 46 func (p *OldTestGetter) Name() string { return "old-test-getter" } 47 48 // RequiredFeatures is a slice of 'features' that must be provided 49 func (p *OldTestGetter) RequiredFeatures() []string { return nil } 50 51 // Initialize will initialize the munger 52 func (p *OldTestGetter) Initialize(config *github.Config, features *features.Features) error { 53 // TODO: don't get the mungers from the global list, they should be passed in... 54 for _, m := range GetAllMungers() { 55 if m.Name() == "submit-queue" { 56 p.sq = m.(*SubmitQueue) 57 break 58 } 59 } 60 if p.sq == nil { 61 return fmt.Errorf("submit-queue not found") 62 } 63 p.ran = map[string]bool{} 64 p.pullJobToLastRun = map[string]int{} 65 return nil 66 } 67 68 // EachLoop is called at the start of every munge loop 69 func (p *OldTestGetter) EachLoop() error { 70 if p.sq == nil { 71 return fmt.Errorf("submit-queue not found") 72 } 73 e2eTester, ok := p.sq.e2e.(*e2e.RealE2ETester) 74 if !ok { 75 return fmt.Errorf("Need real e2e tester, not fake") 76 } 77 78 p.getOldPostsubmitTests(e2eTester) 79 80 return nil 81 } 82 83 func (p *OldTestGetter) getOldPostsubmitTests(e2eTester *e2e.RealE2ETester) { 84 for job, status := range e2eTester.GetBuildStatus() { 85 if p.ran[job] { 86 continue 87 } 88 lastRunNumber, err := strconv.Atoi(status.ID) 89 if lastRunNumber == 0 || err != nil { 90 continue 91 } 92 for i := 1; i <= p.numberOfOldTestsToGet && i < lastRunNumber; i++ { 93 n := lastRunNumber - i 94 glog.Infof("Getting results for past test result: %v %v", job, n) 95 if _, err := e2eTester.GetBuildResult(job, n); err != nil { 96 glog.Errorf("Couldn't get result for %v %v: %v", job, n, err) 97 } 98 } 99 p.ran[job] = true 100 } 101 } 102 103 // RegisterOptions registers options for this munger; returns any that require a restart when changed. 104 func (p *OldTestGetter) RegisterOptions(opts *options.Options) sets.String { 105 opts.RegisterInt(&p.numberOfOldTestsToGet, "number-of-old-test-results", 0, "The number of old test results to get (and therefore file issues for). In case submit queue has some downtime, set this to a higher number and it will file issues for older test runs.") 106 return nil 107 } 108 109 // Munge is unused by this munger. 110 func (p *OldTestGetter) Munge(obj *github.MungeObject) {}