-
Notifications
You must be signed in to change notification settings - Fork 61
/
main.go
1084 lines (959 loc) · 39.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"time"
"github.com/openshift/sippy/pkg/api"
sippyprocessingv1 "github.com/openshift/sippy/pkg/apis/sippyprocessing/v1"
testgridv1 "github.com/openshift/sippy/pkg/apis/testgrid/v1"
"github.com/openshift/sippy/pkg/buganalysis"
"github.com/openshift/sippy/pkg/html"
"github.com/openshift/sippy/pkg/testgridanalysis/testgridanalysisapi"
"github.com/openshift/sippy/pkg/util"
"github.com/openshift/sippy/pkg/util/sets"
"github.com/spf13/cobra"
"k8s.io/klog"
)
var (
dashboardTemplate = "redhat-openshift-ocp-release-%s-%s"
TagStripRegex = regexp.MustCompile(`\[Skipped:.*?\]|\[Suite:.*\]`)
)
type Analyzer struct {
// TestGridJobInfo contains the data consumed from testgrid
TestGridJobInfo []testgridv1.JobDetails
RawData testgridanalysisapi.RawData
Options *Options
Report sippyprocessingv1.TestReport
LastUpdateTime time.Time
Release string
BugCache buganalysis.BugCache
analysisWarnings []string
}
func loadJobSummaries(dashboard string, storagePath string) (map[string]testgridv1.JobSummary, time.Time, error) {
jobs := make(map[string]testgridv1.JobSummary)
url := fmt.Sprintf("https://testgrid.k8s.io/%s/summary", dashboard)
var buf *bytes.Buffer
filename := storagePath + "/" + "\"" + strings.ReplaceAll(url, "/", "-") + "\""
b, err := ioutil.ReadFile(filename)
if err != nil {
return jobs, time.Time{}, fmt.Errorf("Could not read local data file %s: %v", filename, err)
}
buf = bytes.NewBuffer(b)
f, _ := os.Stat(filename)
f.ModTime()
err = json.NewDecoder(buf).Decode(&jobs)
if err != nil {
return nil, time.Time{}, err
}
return jobs, f.ModTime(), nil
}
func downloadJobSummaries(dashboard string, storagePath string) error {
url := fmt.Sprintf("https://testgrid.k8s.io/%s/summary", dashboard)
resp, err := http.Get(url)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return fmt.Errorf("Non-200 response code fetching job summary: %v", resp)
}
filename := storagePath + "/" + "\"" + strings.ReplaceAll(url, "/", "-") + "\""
f, err := os.Create(filename)
if err != nil {
return err
}
buf := bytes.NewBuffer([]byte{})
io.Copy(buf, resp.Body)
_, err = f.Write(buf.Bytes())
return err
}
func loadJobDetails(dashboard, jobName, storagePath string) (testgridv1.JobDetails, error) {
details := testgridv1.JobDetails{
Name: jobName,
}
url := fmt.Sprintf("https://testgrid.k8s.io/%s/table?&show-stale-tests=&tab=%s", dashboard, jobName)
var buf *bytes.Buffer
filename := storagePath + "/" + "\"" + strings.ReplaceAll(url, "/", "-") + "\""
b, err := ioutil.ReadFile(filename)
if err != nil {
return details, fmt.Errorf("Could not read local data file %s: %v", filename, err)
}
buf = bytes.NewBuffer(b)
err = json.NewDecoder(buf).Decode(&details)
if err != nil {
return details, err
}
details.TestGridUrl = fmt.Sprintf("https://testgrid.k8s.io/%s#%s", dashboard, jobName)
return details, nil
}
// https://testgrid.k8s.io/redhat-openshift-ocp-release-4.4-informing/table?&show-stale-tests=&tab=release-openshift-origin-installer-e2e-azure-compact-4.4
// https://testgrid.k8s.io/redhat-openshift-ocp-release-4.4-informing#release-openshift-origin-installer-e2e-azure-compact-4.4&show-stale-tests=&sort-by-failures=
func downloadJobDetails(dashboard, jobName, storagePath string) error {
url := fmt.Sprintf("https://testgrid.k8s.io/%s/table?&show-stale-tests=&tab=%s", dashboard, jobName)
resp, err := http.Get(url)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return fmt.Errorf("Non-200 response code fetching job details: %v", resp)
}
filename := storagePath + "/" + "\"" + strings.ReplaceAll(url, "/", "-") + "\""
f, err := os.Create(filename)
if err != nil {
return err
}
buf := bytes.NewBuffer([]byte{})
io.Copy(buf, resp.Body)
_, err = f.Write(buf.Bytes())
return err
}
// ignoreTestRegex is used to strip o ut tests that don't have predictive or diagnostic value. We don't want to show these in our data.
var ignoreTestRegex = regexp.MustCompile(`Run multi-stage test|operator.Import the release payload|operator.Import a release payload|operator.Run template|operator.Build image|Monitor cluster while tests execute|Overall|job.initialize|\[sig-arch\]\[Feature:ClusterUpgrade\] Cluster should remain functional during upgrade`)
// processTestToJobRunResults adds the tests to the provided jobresult to the provided JobResult and returns the passed, failed, flaked for the test
func processTestToJobRunResults(jobResult testgridanalysisapi.RawJobResult, job testgridv1.JobDetails, test testgridv1.Test, startCol, endCol int) (passed int, failed int, flaked int) {
col := 0
for _, result := range test.Statuses {
if col > endCol {
break
}
// the test results are run length encoded(e.g. "6 passes, 5 failures, 7 passes"), but since we are searching for a test result
// from a specific time period, it's possible a particular run of results overlaps the start-point
// for the time period we care about. So we need to iterate each encoded run until we get to the column
// we care about(a column which falls within the timestamp range we care about, then start the analysis with the remaining
// columns in the run.
remaining := result.Count
if col < startCol {
for i := 0; i < result.Count && col < startCol; i++ {
col++
remaining--
}
}
// if after iterating above we still aren't within the column range we care about, don't do any analysis
// on this run of results.
if col < startCol {
continue
}
switch result.Value {
case 1, 13: // success, flake(failed one or more times but ultimately succeeded)
for i := col; i < col+remaining && i < endCol; i++ {
passed++
if result.Value == 13 {
flaked++
}
joburl := fmt.Sprintf("https://prow.svc.ci.openshift.org/view/gcs/%s/%s", job.Query, job.ChangeLists[i])
jrr, ok := jobResult.JobRunResults[joburl]
if !ok {
jrr = testgridanalysisapi.RawJobRunResult{
Job: job.Name,
JobRunURL: joburl,
}
}
switch {
case test.Name == "Overall":
jrr.Succeeded = true
case strings.HasPrefix(test.Name, testgridanalysisapi.OperatorInstallPrefix):
jrr.InstallOperators = append(jrr.InstallOperators, testgridanalysisapi.OperatorState{
Name: test.Name[len(testgridanalysisapi.OperatorInstallPrefix):],
State: testgridanalysisapi.Success,
})
case strings.HasPrefix(test.Name, testgridanalysisapi.OperatorUpgradePrefix):
jrr.UpgradeOperators = append(jrr.UpgradeOperators, testgridanalysisapi.OperatorState{
Name: test.Name[len(testgridanalysisapi.OperatorUpgradePrefix):],
State: testgridanalysisapi.Success,
})
case strings.HasSuffix(test.Name, "container setup"):
jrr.SetupStatus = testgridanalysisapi.Success
}
jobResult.JobRunResults[joburl] = jrr
}
case 12: // failure
for i := col; i < col+remaining && i < endCol; i++ {
failed++
joburl := fmt.Sprintf("https://prow.svc.ci.openshift.org/view/gcs/%s/%s", job.Query, job.ChangeLists[i])
jrr, ok := jobResult.JobRunResults[joburl]
if !ok {
jrr = testgridanalysisapi.RawJobRunResult{
Job: job.Name,
JobRunURL: joburl,
}
}
// only add the failing test and name if it has predictive value. We excluded all the non-predictive ones above except for these
// which we use to set various JobRunResult markers
if test.Name != "Overall" && !strings.HasSuffix(test.Name, "container setup") {
jrr.FailedTestNames = append(jrr.FailedTestNames, test.Name)
jrr.TestFailures++
}
switch {
case test.Name == "Overall":
jrr.Failed = true
case strings.HasPrefix(test.Name, testgridanalysisapi.OperatorInstallPrefix):
jrr.InstallOperators = append(jrr.InstallOperators, testgridanalysisapi.OperatorState{
Name: test.Name[len(testgridanalysisapi.OperatorInstallPrefix):],
State: testgridanalysisapi.Failure,
})
case strings.HasPrefix(test.Name, testgridanalysisapi.OperatorUpgradePrefix):
jrr.UpgradeOperators = append(jrr.UpgradeOperators, testgridanalysisapi.OperatorState{
Name: test.Name[len(testgridanalysisapi.OperatorUpgradePrefix):],
State: testgridanalysisapi.Failure,
})
case strings.HasSuffix(test.Name, "container setup"):
jrr.SetupStatus = testgridanalysisapi.Failure
}
jobResult.JobRunResults[joburl] = jrr
}
}
col += remaining
}
return
}
func (a *Analyzer) processTest(job testgridv1.JobDetails, platforms []string, test testgridv1.Test, sig string, startCol, endCol int) {
// strip out tests that don't have predictive or diagnostic value
// we have to know about overall to be able to set the global success or failure.
// we have to know about container setup to be able to set infra failures
if test.Name != "Overall" && !strings.HasSuffix(test.Name, "container setup") && ignoreTestRegex.MatchString(test.Name) {
return
}
jobResult, ok := a.RawData.JobResults[job.Name]
if !ok {
jobResult = testgridanalysisapi.RawJobResult{
JobName: job.Name,
TestGridJobUrl: job.TestGridUrl,
JobRunResults: map[string]testgridanalysisapi.RawJobRunResult{},
}
}
passed, failed, flaked := processTestToJobRunResults(jobResult, job, test, startCol, endCol)
// we have mutated, so assign back to our intermediate value
a.RawData.JobResults[job.Name] = jobResult
// our aggregation and markers are correctly set above. We allowed these two tests to be checked, but we don't want
// actual results for them
if test.Name == "Overall" || strings.HasSuffix(test.Name, "container setup") {
return
}
util.AddTestResult("all", a.RawData.ByAll, test.Name, passed, failed, flaked)
util.AddTestResult(job.Name, a.RawData.ByJob, test.Name, passed, failed, flaked)
for _, platform := range platforms {
util.AddTestResult(platform, a.RawData.ByPlatform, test.Name, passed, failed, flaked)
}
util.AddTestResult(sig, a.RawData.BySig, test.Name, passed, failed, flaked)
}
func (a *Analyzer) processJobDetails(job testgridv1.JobDetails) {
startCol, endCol := util.ComputeLookback(a.Options.StartDay, a.Options.EndDay, job.Timestamps)
platforms := util.FindPlatform(job.Name)
for i, test := range job.Tests {
klog.V(4).Infof("Analyzing results from %d to %d from job %s for test %s\n", startCol, endCol, job.Name, test.Name)
test.Name = strings.TrimSpace(TagStripRegex.ReplaceAllString(test.Name, ""))
job.Tests[i] = test
a.processTest(job, platforms, test, util.FindSig(test.Name), startCol, endCol)
}
}
// createSyntheticTests takes the JobRunResult information and produces some pre-analysis by interpreting different types of failures
// and potentially producing synthentic test results and aggregations to better inform sippy.
// This needs to be called after all the JobDetails have been processed.
func (a *Analyzer) createSyntheticTests() {
// make a pass to fill in install, upgrade, and infra synthentic tests.
type synthenticTestResult struct {
name string
pass int
fail int
}
for jobName, jobResults := range a.RawData.JobResults {
for jrrKey, jrr := range jobResults.JobRunResults {
platforms := util.FindPlatform(jrr.Job)
isUpgrade := strings.Contains(jrr.Job, "upgrade")
syntheticTests := map[string]*synthenticTestResult{
testgridanalysisapi.InstallTestName: &synthenticTestResult{name: testgridanalysisapi.InstallTestName},
testgridanalysisapi.UpgradeTestName: &synthenticTestResult{name: testgridanalysisapi.UpgradeTestName},
testgridanalysisapi.InfrastructureTestName: &synthenticTestResult{name: testgridanalysisapi.InfrastructureTestName},
}
installFailed := false
for _, operator := range jrr.InstallOperators {
if operator.State == testgridanalysisapi.Failure {
installFailed = true
break
}
}
upgradeFailed := false
for _, operator := range jrr.UpgradeOperators {
if operator.State == testgridanalysisapi.Failure {
upgradeFailed = true
break
}
}
setupFailed := jrr.SetupStatus != testgridanalysisapi.Success
if installFailed {
jrr.TestFailures++
jrr.FailedTestNames = append(jrr.FailedTestNames, testgridanalysisapi.InstallTestName)
syntheticTests[testgridanalysisapi.InstallTestName].fail = 1
} else {
if !setupFailed { // this will be an undercount, but we only want to count installs that actually worked.
syntheticTests[testgridanalysisapi.InstallTestName].pass = 1
}
}
if setupFailed && len(jrr.InstallOperators) == 0 { // we only want to count it as an infra issue if the install did not start
jrr.TestFailures++
jrr.FailedTestNames = append(jrr.FailedTestNames, testgridanalysisapi.InfrastructureTestName)
syntheticTests[testgridanalysisapi.InfrastructureTestName].fail = 1
} else {
syntheticTests[testgridanalysisapi.InfrastructureTestName].pass = 1
}
if isUpgrade && !setupFailed && !installFailed { // only record upgrade status if we were able to attempt the upgrade
if upgradeFailed || len(jrr.UpgradeOperators) == 0 {
jrr.TestFailures++
jrr.FailedTestNames = append(jrr.FailedTestNames, testgridanalysisapi.UpgradeTestName)
syntheticTests[testgridanalysisapi.UpgradeTestName].fail = 1
} else {
syntheticTests[testgridanalysisapi.UpgradeTestName].pass = 1
}
}
for testName, result := range syntheticTests {
util.AddTestResult("all", a.RawData.ByAll, testName, result.pass, result.fail, 0)
util.AddTestResult(jrr.Job, a.RawData.ByJob, testName, result.pass, result.fail, 0)
for _, platform := range platforms {
util.AddTestResult(platform, a.RawData.ByPlatform, testName, result.pass, result.fail, 0)
}
//util.AddTestResult(sig, a.RawData.BySig, test.Name, passed, failed, flaked)
}
jobResults.JobRunResults[jrrKey] = jrr
}
a.RawData.JobResults[jobName] = jobResults
}
}
func getFailedTestNamesFromJobResults(jobResults map[string]testgridanalysisapi.RawJobResult) sets.String {
failedTestNames := sets.NewString()
for _, jobResult := range jobResults {
for _, jobrun := range jobResult.JobRunResults {
failedTestNames.Insert(jobrun.FailedTestNames...)
}
}
return failedTestNames
}
func (a *Analyzer) analyze() {
for _, details := range a.TestGridJobInfo {
klog.V(2).Infof("processing test details for job %s\n", details.Name)
a.processJobDetails(details)
}
// now that we have all the JobRunResults, use them to create synthetic tests for install, upgrade, and infra
a.createSyntheticTests()
// now that we have all the test failures (remember we added sythentics), use that to update the bugzilla cache
failedTestNamesAcrossAllJobRuns := getFailedTestNamesFromJobResults(a.RawData.JobResults)
err := a.BugCache.UpdateForFailedTests(failedTestNamesAcrossAllJobRuns.List()...)
if err != nil {
klog.Error(err)
a.analysisWarnings = append(a.analysisWarnings, fmt.Sprintf("Bugzilla Lookup Error: an error was encountered looking up existing bugs for failing tests, some test failures may have associated bugs that are not listed below. Lookup error: %v", err.Error()))
}
}
func (a *Analyzer) loadData(releases []string, storagePath string) {
var jobFilter *regexp.Regexp
if len(a.Options.JobFilter) > 0 {
jobFilter = regexp.MustCompile(a.Options.JobFilter)
}
for _, release := range releases {
dashboard := fmt.Sprintf(dashboardTemplate, release, "blocking")
blockingJobs, ts, err := loadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error loading dashboard page %s: %v\n", dashboard, err)
continue
}
a.LastUpdateTime = ts
for jobName, job := range blockingJobs {
if util.RelevantJob(jobName, job.OverallStatus, jobFilter) {
klog.V(4).Infof("Job %s has bad status %s\n", jobName, job.OverallStatus)
details, err := loadJobDetails(dashboard, jobName, storagePath)
if err != nil {
klog.Errorf("Error loading job details for %s: %v\n", jobName, err)
} else {
a.TestGridJobInfo = append(a.TestGridJobInfo, details)
}
}
}
}
for _, release := range releases {
dashboard := fmt.Sprintf(dashboardTemplate, release, "informing")
informingJobs, _, err := loadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error load dashboard page %s: %v\n", dashboard, err)
continue
}
for jobName, job := range informingJobs {
if util.RelevantJob(jobName, job.OverallStatus, jobFilter) {
klog.V(4).Infof("Job %s has bad status %s\n", jobName, job.OverallStatus)
details, err := loadJobDetails(dashboard, jobName, storagePath)
if err != nil {
klog.Errorf("Error loading job details for %s: %v\n", jobName, err)
} else {
a.TestGridJobInfo = append(a.TestGridJobInfo, details)
}
}
}
}
}
func downloadData(releases []string, filter string, storagePath string) {
var jobFilter *regexp.Regexp
if len(filter) > 0 {
jobFilter = regexp.MustCompile(filter)
}
for _, release := range releases {
dashboard := fmt.Sprintf(dashboardTemplate, release, "blocking")
err := downloadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error fetching dashboard page %s: %v\n", dashboard, err)
continue
}
blockingJobs, _, err := loadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error loading dashboard page %s: %v\n", dashboard, err)
continue
}
for jobName, job := range blockingJobs {
if util.RelevantJob(jobName, job.OverallStatus, jobFilter) {
klog.V(4).Infof("Job %s has bad status %s\n", jobName, job.OverallStatus)
err := downloadJobDetails(dashboard, jobName, storagePath)
if err != nil {
klog.Errorf("Error fetching job details for %s: %v\n", jobName, err)
}
}
}
}
for _, release := range releases {
dashboard := fmt.Sprintf(dashboardTemplate, release, "informing")
err := downloadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error fetching dashboard page %s: %v\n", dashboard, err)
continue
}
informingJobs, _, err := loadJobSummaries(dashboard, storagePath)
if err != nil {
klog.Errorf("Error fetching dashboard page %s: %v\n", dashboard, err)
continue
}
for jobName, job := range informingJobs {
if util.RelevantJob(jobName, job.OverallStatus, jobFilter) {
klog.V(4).Infof("Job %s has bad status %s\n", jobName, job.OverallStatus)
err := downloadJobDetails(dashboard, jobName, storagePath)
if err != nil {
klog.Errorf("Error fetching job details for %s: %v\n", jobName, err)
}
}
}
}
}
// returns top ten failing tests w/o a bug and top ten with a bug(in that order)
func getTopFailingTests(result map[string]sippyprocessingv1.SortedAggregateTestsResult, release string, bugCache buganalysis.BugCache) ([]*sippyprocessingv1.TestResult, []*sippyprocessingv1.TestResult) {
topTestsWithoutBug := []*sippyprocessingv1.TestResult{}
topTestsWithBug := []*sippyprocessingv1.TestResult{}
all := result["all"]
withoutbugcount := 0
withbugcount := 0
// look at the top 100 failing tests, try to create a list of the top 20 failures with bugs and without bugs.
// limit to 100 so we don't hammer search.ci too hard if we can't find 20 failures with bugs in the first 100.
for i := 0; (withbugcount < 20 || withoutbugcount < 10) && i < 100 && i < len(all.TestResults); i++ {
test := all.TestResults[i]
test.BugList = bugCache.ListBugs(release, "", test.Name)
// we want the top ten test failures that don't have bugs associated.
// top test failures w/ bugs will be listed, but don't count towards the top ten.
if len(test.BugList) == 0 && withoutbugcount < 10 {
topTestsWithoutBug = append(topTestsWithoutBug, &test)
withoutbugcount++
} else if len(test.BugList) > 0 && withbugcount < 20 {
topTestsWithBug = append(topTestsWithBug, &test)
withbugcount++
}
}
return topTestsWithoutBug, topTestsWithBug
}
func (a *Analyzer) prepareTestReport(prev bool) {
byAll := util.SummarizeTestResults(a.RawData.ByAll, a.BugCache, a.Release, a.Options.MinTestRuns, a.Options.TestSuccessThreshold)
byPlatform := util.SummarizeTestResults(a.RawData.ByPlatform, a.BugCache, a.Release, a.Options.MinTestRuns, a.Options.TestSuccessThreshold)
byJob := util.SummarizeTestResults(a.RawData.ByJob, a.BugCache, a.Release, a.Options.MinTestRuns, a.Options.TestSuccessThreshold)
bySig := util.SummarizeTestResults(a.RawData.BySig, a.BugCache, a.Release, a.Options.MinTestRuns, a.Options.TestSuccessThreshold)
filteredFailureGroups := util.FilterFailureGroups(a.RawData.JobResults, a.BugCache, a.Release, a.Options.FailureClusterThreshold)
jobResults, infrequentJobResults := util.SummarizeJobRunResults(a.RawData.JobResults, byJob, a.BugCache, a.Release, a.Options.EndDay)
bugFailureCounts := util.GenerateSortedBugFailureCounts(a.RawData.JobResults, byAll, a.BugCache, a.Release)
bugzillaComponentResults := util.GenerateJobFailuresByBugzillaComponent(a.RawData.JobResults, byJob)
a.Report = sippyprocessingv1.TestReport{
Release: a.Release,
All: byAll,
ByPlatform: byPlatform,
ByJob: byJob,
BySig: bySig,
FailureGroups: filteredFailureGroups,
JobResults: jobResults,
InfrequentJobResults: infrequentJobResults,
Timestamp: a.LastUpdateTime,
BugsByFailureCount: bugFailureCounts,
JobFailuresByBugzillaComponent: bugzillaComponentResults,
AnalysisWarnings: a.analysisWarnings,
}
if !prev {
topFailingTestsWithoutBug, topFailingTestsWithBug := getTopFailingTests(byAll, a.Release, a.BugCache)
a.Report.TopFailingTestsWithBug = topFailingTestsWithBug
a.Report.TopFailingTestsWithoutBug = topFailingTestsWithoutBug
}
}
func (a *Analyzer) printReport() {
a.prepareTestReport(false)
switch a.Options.Output {
case "json":
a.printJsonReport()
case "text":
a.printTextReport()
case "dashboard":
a.printDashboardReport()
}
}
func (a *Analyzer) printJsonReport() {
enc := json.NewEncoder(os.Stdout)
enc.Encode(a.Report)
}
func (a *Analyzer) printDashboardReport() {
fmt.Println("================== Summary Across All Jobs ==================")
all := a.Report.All["all"]
fmt.Printf("Passing test runs: %d\n", all.Successes)
fmt.Printf("Failing test runs: %d\n", all.Failures)
fmt.Printf("Test Pass Percentage: %0.2f\n", all.TestPassPercentage)
fmt.Println("\n\n================== Top 10 Most Frequently Failing Tests ==================")
count := 0
for i := 0; count < 10 && i < len(all.TestResults); i++ {
test := all.TestResults[i]
if (test.Successes + test.Failures) > a.Options.MinTestRuns {
fmt.Printf("Test Name: %s\n", test.Name)
fmt.Printf("Test Pass Percentage: %0.2f (%d runs)\n", test.PassPercentage, test.Successes+test.Failures)
if test.Successes+test.Failures < 10 {
fmt.Printf("WARNING: Only %d runs for this test\n", test.Successes+test.Failures)
}
count++
fmt.Printf("\n")
}
}
fmt.Println("\n\n================== Top 10 Most Frequently Failing Jobs ==================")
for i, v := range a.Report.JobResults {
fmt.Printf("Job: %s\n", v.Name)
fmt.Printf("Job Pass Percentage: %0.2f%% (%d runs)\n", util.Percent(v.Successes, v.Failures), v.Successes+v.Failures)
if v.Successes+v.Failures < 10 {
fmt.Printf("WARNING: Only %d runs for this job\n", v.Successes+v.Failures)
}
fmt.Printf("\n")
if i == 9 {
break
}
}
fmt.Println("\n\n================== Clustered Test Failures ==================")
count = 0
for _, group := range a.Report.FailureGroups {
count += group.TestFailures
}
if len(a.Report.FailureGroups) != 0 {
fmt.Printf("%d Clustered Test Failures with an average size of %d and median of %d\n", len(a.Report.FailureGroups), count/len(a.Report.FailureGroups), a.Report.FailureGroups[len(a.Report.FailureGroups)/2].TestFailures)
} else {
fmt.Printf("No clustered test failures observed")
}
fmt.Println("\n\n================== Summary By Platform ==================")
jobsByPlatform := util.SummarizeJobsByPlatform(a.Report)
for _, v := range jobsByPlatform {
fmt.Printf("Platform: %s\n", v.Platform)
fmt.Printf("Platform Job Pass Percentage: %0.2f%% (%d runs)\n", util.Percent(v.Successes, v.Failures), v.Successes+v.Failures)
if v.Successes+v.Failures < 10 {
fmt.Printf("WARNING: Only %d runs for this job\n", v.Successes+v.Failures)
}
fmt.Printf("\n")
}
}
func (a *Analyzer) printTextReport() {
fmt.Println("================== Test Summary Across All Jobs ==================")
all := a.Report.All["all"]
fmt.Printf("Passing test runs: %d\n", all.Successes)
fmt.Printf("Failing test runs: %d\n", all.Failures)
fmt.Printf("Test Pass Percentage: %0.2f\n", all.TestPassPercentage)
testCount := 0
testSuccesses := 0
testFailures := 0
for _, test := range all.TestResults {
fmt.Printf("\tTest Name: %s\n", test.Name)
fmt.Printf("\tPassed: %d\n", test.Successes)
fmt.Printf("\tFailed: %d\n", test.Failures)
fmt.Printf("\tTest Pass Percentage: %0.2f\n\n", test.PassPercentage)
testCount++
testSuccesses += test.Successes
testFailures += test.Failures
}
fmt.Println("\n\n\n================== Test Summary By Platform ==================")
for key, by := range a.Report.ByPlatform {
fmt.Printf("Platform: %s\n", key)
// fmt.Printf("Passing test runs: %d\n", platform.Successes)
// fmt.Printf("Failing test runs: %d\n", platform.Failures)
fmt.Printf("Test Pass Percentage: %0.2f\n", by.TestPassPercentage)
for _, test := range by.TestResults {
fmt.Printf("\tTest Name: %s\n", test.Name)
fmt.Printf("\tPassed: %d\n", test.Successes)
fmt.Printf("\tFailed: %d\n", test.Failures)
fmt.Printf("\tTest Pass Percentage: %0.2f\n\n", test.PassPercentage)
}
fmt.Println("")
}
fmt.Println("\n\n\n================== Test Summary By Job ==================")
for key, by := range a.Report.ByJob {
fmt.Printf("Job: %s\n", key)
// fmt.Printf("Passing test runs: %d\n", platform.Successes)
// fmt.Printf("Failing test runs: %d\n", platform.Failures)
fmt.Printf("Test Pass Percentage: %0.2f\n", by.TestPassPercentage)
for _, test := range by.TestResults {
fmt.Printf("\tTest Name: %s\n", test.Name)
fmt.Printf("\tPassed: %d\n", test.Successes)
fmt.Printf("\tFailed: %d\n", test.Failures)
fmt.Printf("\tTest Pass Percentage: %0.2f\n\n", test.PassPercentage)
}
fmt.Println("")
}
fmt.Println("\n\n\n================== Test Summary By Sig ==================")
for key, by := range a.Report.BySig {
fmt.Printf("\nSig: %s\n", key)
// fmt.Printf("Passing test runs: %d\n", platform.Successes)
// fmt.Printf("Failing test runs: %d\n", platform.Failures)
fmt.Printf("Test Pass Percentage: %0.2f\n", by.TestPassPercentage)
for _, test := range by.TestResults {
fmt.Printf("\tTest Name: %s\n", test.Name)
// fmt.Printf("\tPassed: %d\n", test.Successes)
// fmt.Printf("\tFailed: %d\n", test.Failures)
fmt.Printf("\tTest Pass Percentage: %0.2f\n\n", test.PassPercentage)
}
fmt.Println("")
}
fmt.Println("\n\n\n================== Clustered Test Failures ==================")
for _, group := range a.Report.FailureGroups {
fmt.Printf("Job url: %s\n", group.Url)
fmt.Printf("Number of test failures: %d\n\n", group.TestFailures)
}
fmt.Println("\n\n\n================== Job Pass Rates ==================")
jobSuccesses := 0
jobFailures := 0
jobCount := 0
for _, job := range a.Report.JobResults {
fmt.Printf("Job: %s\n", job.Name)
fmt.Printf("Job Successes: %d\n", job.Successes)
fmt.Printf("Job Failures: %d\n", job.Failures)
fmt.Printf("Job Pass Percentage: %0.2f\n\n", job.PassPercentage)
jobSuccesses += job.Successes
jobFailures += job.Failures
jobCount++
}
fmt.Println("\n\n================== Job Summary By Platform ==================")
jobsByPlatform := util.SummarizeJobsByPlatform(a.Report)
for _, v := range jobsByPlatform {
fmt.Printf("Platform: %s\n", v.Platform)
fmt.Printf("Job Succeses: %d\n", v.Successes)
fmt.Printf("Job Failures: %d\n", v.Failures)
fmt.Printf("Platform Job Pass Percentage: %0.2f%% (%d runs)\n", util.Percent(v.Successes, v.Failures), v.Successes+v.Failures)
if v.Successes+v.Failures < 10 {
fmt.Printf("WARNING: Only %d runs for this job\n", v.Successes+v.Failures)
}
fmt.Printf("\n")
}
fmt.Println("")
fmt.Println("\n\n================== Overall Summary ==================")
fmt.Printf("Total Jobs: %d\n", jobCount)
fmt.Printf("Total Job Successes: %d\n", jobSuccesses)
fmt.Printf("Total Job Failures: %d\n", jobFailures)
fmt.Printf("Total Job Pass Percentage: %0.2f\n\n", util.Percent(jobSuccesses, jobFailures))
fmt.Printf("Total Tests: %d\n", testCount)
fmt.Printf("Total Test Successes: %d\n", testSuccesses)
fmt.Printf("Total Test Failures: %d\n", testFailures)
fmt.Printf("Total Test Pass Percentage: %0.2f\n", util.Percent(testSuccesses, testFailures))
}
type Server struct {
bugCache buganalysis.BugCache
analyzers map[string]Analyzer
options *Options
}
func (s *Server) refresh(w http.ResponseWriter, req *http.Request) {
klog.Infof("Refreshing data")
s.bugCache.Clear()
for k, analyzer := range s.analyzers {
analyzer.RawData = testgridanalysisapi.RawData{
ByAll: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByJob: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByPlatform: make(map[string]testgridanalysisapi.AggregateTestsResult),
BySig: make(map[string]testgridanalysisapi.AggregateTestsResult),
JobResults: make(map[string]testgridanalysisapi.RawJobResult),
}
analyzer.loadData([]string{analyzer.Release}, analyzer.Options.LocalData)
analyzer.analyze()
analyzer.prepareTestReport(strings.Contains(k, "-prev"))
s.analyzers[k] = analyzer
}
w.Header().Set("Content-Type", "text/html;charset=UTF-8")
w.WriteHeader(http.StatusOK)
klog.Infof("Refresh complete")
}
func (s *Server) printHtmlReport(w http.ResponseWriter, req *http.Request) {
release := req.URL.Query().Get("release")
if _, ok := s.analyzers[release]; !ok {
html.WriteLandingPage(w, s.options.Releases)
return
}
html.PrintHtmlReport(w, req, s.analyzers[release].Report, s.analyzers[release+"-prev"].Report, s.options.EndDay, 15)
}
func (s *Server) printJSONReport(w http.ResponseWriter, req *http.Request) {
release := req.URL.Query().Get("release")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
releaseReports := make(map[string][]sippyprocessingv1.TestReport)
if release == "all" {
// return all available json reports
// store [currentReport, prevReport] in a slice
for _, r := range s.options.Releases {
if _, ok := s.analyzers[r]; ok {
releaseReports[r] = []sippyprocessingv1.TestReport{s.analyzers[r].Report, s.analyzers[r+"-prev"].Report}
} else {
klog.Errorf("unable to load test report for release version %s", r)
continue
}
}
api.PrintJSONReport(w, req, releaseReports, s.options.EndDay, 15)
return
} else if _, ok := s.analyzers[release]; !ok {
// return a 404 error along with the list of available releases in the detail section
errMsg := map[string]interface{}{
"code": "404",
"detail": fmt.Sprintf("No valid release specified, valid releases are: %v", s.options.Releases),
}
errMsgBytes, _ := json.Marshal(errMsg)
w.WriteHeader(http.StatusNotFound)
w.Write(errMsgBytes)
return
}
releaseReports[release] = []sippyprocessingv1.TestReport{s.analyzers[release].Report, s.analyzers[release+"-prev"].Report}
api.PrintJSONReport(w, req, releaseReports, s.options.EndDay, 15)
}
func (s *Server) detailed(w http.ResponseWriter, req *http.Request) {
release := "4.5"
t := req.URL.Query().Get("release")
if t != "" {
release = t
}
startDay := 0
t = req.URL.Query().Get("startDay")
if t != "" {
startDay, _ = strconv.Atoi(t)
}
endDay := startDay + 7
t = req.URL.Query().Get("endDay")
if t != "" {
endDay, _ = strconv.Atoi(t)
}
testSuccessThreshold := 98.0
t = req.URL.Query().Get("testSuccessThreshold")
if t != "" {
testSuccessThreshold, _ = strconv.ParseFloat(t, 64)
}
jobFilter := ""
t = req.URL.Query().Get("jobFilter")
if t != "" {
jobFilter = t
}
minTestRuns := 10
t = req.URL.Query().Get("minTestRuns")
if t != "" {
minTestRuns, _ = strconv.Atoi(t)
}
fct := 10
t = req.URL.Query().Get("failureClusterThreshold")
if t != "" {
fct, _ = strconv.Atoi(t)
}
jobTestCount := math.MaxInt32
t = req.URL.Query().Get("jobTestCount")
if t != "" {
jobTestCount, _ = strconv.Atoi(t)
}
opt := &Options{
StartDay: startDay,
EndDay: endDay,
TestSuccessThreshold: testSuccessThreshold,
JobFilter: jobFilter,
MinTestRuns: minTestRuns,
FailureClusterThreshold: fct,
}
analyzer := Analyzer{
Release: release,
Options: opt,
RawData: testgridanalysisapi.RawData{
ByAll: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByJob: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByPlatform: make(map[string]testgridanalysisapi.AggregateTestsResult),
BySig: make(map[string]testgridanalysisapi.AggregateTestsResult),
JobResults: make(map[string]testgridanalysisapi.RawJobResult),
},
BugCache: s.bugCache,
}
analyzer.loadData([]string{release}, s.options.LocalData)
analyzer.analyze()
analyzer.prepareTestReport(false)
// prior 7 day period
optCopy := *opt
optCopy.StartDay = endDay + 1
optCopy.EndDay = endDay + 8
prevAnalyzer := Analyzer{
Release: release,
Options: &optCopy,
RawData: testgridanalysisapi.RawData{
ByAll: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByJob: make(map[string]testgridanalysisapi.AggregateTestsResult),
ByPlatform: make(map[string]testgridanalysisapi.AggregateTestsResult),
BySig: make(map[string]testgridanalysisapi.AggregateTestsResult),
JobResults: make(map[string]testgridanalysisapi.RawJobResult),
},
BugCache: s.bugCache,
}
prevAnalyzer.loadData([]string{release}, s.options.LocalData)
prevAnalyzer.analyze()
prevAnalyzer.prepareTestReport(true)
html.PrintHtmlReport(w, req, analyzer.Report, prevAnalyzer.Report, opt.EndDay, jobTestCount)
}
func (s *Server) serve(opts *Options) {
http.DefaultServeMux.HandleFunc("/", s.printHtmlReport)
http.DefaultServeMux.HandleFunc("/json", s.printJSONReport)
http.DefaultServeMux.HandleFunc("/detailed", s.detailed)
http.DefaultServeMux.HandleFunc("/refresh", s.refresh)
//go func() {
klog.Infof("Serving reports on %s ", opts.ListenAddr)
if err := http.ListenAndServe(opts.ListenAddr, nil); err != nil {
klog.Exitf("Server exited: %v", err)
}
//}()
}
type Options struct {
LocalData string
Releases []string
StartDay int
EndDay int
TestSuccessThreshold float64
JobFilter string
MinTestRuns int
Output string
FailureClusterThreshold int
FetchData string
ListenAddr string
Server bool
}
func main() {
opt := &Options{
EndDay: 7,
TestSuccessThreshold: 99.99,
MinTestRuns: 10,
Output: "json",
FailureClusterThreshold: 10,
StartDay: 0,
ListenAddr: ":8080",
Releases: []string{"4.4"},
}
klog.InitFlags(nil)
flag.CommandLine.Set("skip_headers", "true")
cmd := &cobra.Command{
Run: func(cmd *cobra.Command, arguments []string) {
if err := opt.Run(); err != nil {
klog.Exitf("error: %v", err)
}
},
}
flags := cmd.Flags()
flags.StringVar(&opt.LocalData, "local-data", opt.LocalData, "Path to testgrid data from local disk")
flags.StringArrayVar(&opt.Releases, "release", opt.Releases, "Which releases to analyze (one per arg instance)")
flags.IntVar(&opt.StartDay, "start-day", opt.StartDay, "Analyze data starting from this day")
flags.IntVar(&opt.EndDay, "end-day", opt.EndDay, "Look at job runs going back to this day")
flags.Float64Var(&opt.TestSuccessThreshold, "test-success-threshold", opt.TestSuccessThreshold, "Filter results for tests that are more than this percent successful")
flags.StringVar(&opt.JobFilter, "job-filter", opt.JobFilter, "Only analyze jobs that match this regex")
flags.StringVar(&opt.FetchData, "fetch-data", opt.FetchData, "Download testgrid data to directory specified for future use with --local-data")
flags.IntVar(&opt.MinTestRuns, "min-test-runs", opt.MinTestRuns, "Ignore tests with less than this number of runs")
flags.IntVar(&opt.FailureClusterThreshold, "failure-cluster-threshold", opt.FailureClusterThreshold, "Include separate report on job runs with more than N test failures, -1 to disable")
flags.StringVarP(&opt.Output, "output", "o", opt.Output, "Output format for report: json, text")
flag.StringVar(&opt.ListenAddr, "listen", opt.ListenAddr, "The address to serve analysis reports on")
flags.BoolVar(&opt.Server, "server", opt.Server, "Run in web server mode (serve reports over http)")
flags.AddGoFlag(flag.CommandLine.Lookup("v"))
flags.AddGoFlag(flag.CommandLine.Lookup("skip_headers"))
if err := cmd.Execute(); err != nil {