Skip to content

Commit

Permalink
Merge pull request kubernetes#111669 from pohly/trim_report_framework
Browse files Browse the repository at this point in the history
e2e: trim junit report for Spyglass
  • Loading branch information
k8s-ci-robot committed Aug 4, 2022
2 parents b661944 + c299a12 commit feec955
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions test/e2e/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/ginkgo/v2/types"

restclient "k8s.io/client-go/rest"
Expand Down Expand Up @@ -356,14 +357,6 @@ func CreateGinkgoConfig() (types.SuiteConfig, types.ReporterConfig) {
suiteConfig.RandomizeAllSpecs = true
// Turn on verbose by default to get spec names
reporterConfig.Verbose = true
// Enable JUnit output to the result directory, but only if not already specified
// via -junit-report.
if reporterConfig.JUnitReport == "" && TestContext.ReportDir != "" {
// With Ginkgo v1, we used to write one file per parallel node. Now Ginkgo v2 automatically
// merges all results into a single file for us. The 01 suffix is kept in case that users
// expect files to be called "junit_<prefix><number>.xml".
reporterConfig.JUnitReport = path.Join(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
}
// Disable skipped tests unless they are explicitly requested.
if len(suiteConfig.FocusStrings) == 0 && len(suiteConfig.SkipStrings) == 0 {
suiteConfig.SkipStrings = []string{`\[Flaky\]|\[Feature:.+\]`}
Expand Down Expand Up @@ -561,4 +554,54 @@ func AfterReadingAllFlags(t *TestContextType) {
}
os.Exit(1)
}

if TestContext.ReportDir != "" {
ginkgo.ReportAfterSuite("Kubernetes e2e JUnit report", writeJUnitReport)
}
}

// writeJUnitReport generates a JUnit file in the e2e report directory that is
// shorter than the one normally written by `ginkgo --junit-report`. This is
// needed because the full report can become too large for tools like Spyglass
// (https://github.com/kubernetes/kubernetes/issues/111510).
//
// Users who want the full report can use `--junit-report`.
func writeJUnitReport(report ginkgo.Report) {
trimmedReport := report
trimmedReport.SpecReports = nil
for _, specReport := range report.SpecReports {
// Remove details for any spec that hasn't failed. In Prow,
// the test output captured in build-log.txt has all of this
// information, so we don't need it in the XML.
if specReport.State != types.SpecStateFailed {
specReport.CapturedGinkgoWriterOutput = ""
specReport.CapturedStdOutErr = ""
}

// Remove report entries generated by ginkgo.By("doing
// something") because those are not useful (just have the
// start time) and cause Spyglass to show an additional "open
// stdout" button with a summary of the steps, which usually
// doesn't help. We don't remove all entries because other
// measurements also get reported this way.
//
// Removing the report entries is okay because message text was
// already added to the test output when ginkgo.By was called.
reportEntries := specReport.ReportEntries
specReport.ReportEntries = nil
for _, reportEntry := range reportEntries {
if reportEntry.Name != "By Step" {
specReport.ReportEntries = append(specReport.ReportEntries, reportEntry)
}
}

trimmedReport.SpecReports = append(trimmedReport.SpecReports, specReport)
}

// With Ginkgo v1, we used to write one file per parallel node. Now
// Ginkgo v2 automatically merges all results into a report for us. The
// 01 suffix is kept in case that users expect files to be called
// "junit_<prefix><number>.xml".
junitReport := path.Join(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
reporters.GenerateJUnitReport(trimmedReport, junitReport)
}

0 comments on commit feec955

Please sign in to comment.