e2e framework: truncate too long failure messages when writing JUnit

Our tooling cannot handle very long failure messages well:
- when unfolding a test in the spyglass UI, it fills the entire screen
- failure correlation for http://go.k8s.io/triage has resource constraints

We cannot enforce that all tests only produce short failure messages and even
if we could, depending on the test failure, including more information may be
useful to understand it.

To achieve both goals (summary for correlation and overview, all details
available when digging deeper), too longer failure messages now get truncated,
with the full message guaranteed to be captured in the test output.

"Too long" is arbitrarily chosen to be similar to the gomega.MaxLength because
that has been a limit for failure message size in the past.
This commit is contained in:
Patrick Ohly 2022-10-24 18:12:41 +02:00
parent b3f4cd66cd
commit 023baa5e45

View File

@ -530,6 +530,14 @@ func AfterReadingAllFlags(t *TestContextType) {
}
}
const (
// This is the traditional gomega.Format default of 4000 for an object
// dump plus some extra room for the message.
maxFailureMessageSize = 5000
truncatedMsg = "\n[... see output for full dump ...]\n"
)
// 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
@ -546,6 +554,18 @@ func writeJUnitReport(report ginkgo.Report) {
if specReport.State != types.SpecStateFailed {
specReport.CapturedGinkgoWriterOutput = ""
specReport.CapturedStdOutErr = ""
} else {
// Truncate the failure message if it is too large.
msgLen := len(specReport.Failure.Message)
if msgLen > maxFailureMessageSize {
// Insert full message at the beginning where it is easy to find.
specReport.CapturedGinkgoWriterOutput =
"Full failure message:\n" +
specReport.Failure.Message + "\n\n" +
strings.Repeat("=", 70) + "\n\n" +
specReport.CapturedGinkgoWriterOutput
specReport.Failure.Message = specReport.Failure.Message[0:maxFailureMessageSize/2] + truncatedMsg + specReport.Failure.Message[msgLen-maxFailureMessageSize/2:msgLen]
}
}
// Remove report entries generated by ginkgo.By("doing