Skip to content

NO-JIRA: Update e2e diagnostics#488

Open
theobarberbany wants to merge 1 commit intoopenshift:mainfrom
theobarberbany:tb/fix-e2e-diag
Open

NO-JIRA: Update e2e diagnostics#488
theobarberbany wants to merge 1 commit intoopenshift:mainfrom
theobarberbany:tb/fix-e2e-diag

Conversation

@theobarberbany
Copy link
Contributor

@theobarberbany theobarberbany commented Mar 5, 2026

Don't double print diagnostics, bypassing GinkgoWriter entirely to avoid duplication. Relying on CapturedGinkgoWriterOutput was causing the dupes.

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced diagnostic collection and reporting in end-to-end tests. Improved how failure diagnostics are gathered and integrated into test failure messages for better visibility during troubleshooting.

Don't double print diagnostics, bypassing GinkgoWriter entirely to avoid
duplication. Relying on CapturedGinkgoWriterOutput was causing the
dupes.
@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@theobarberbany theobarberbany changed the title Update e2e diagnostics NO-JIRA: Update e2e diagnostics Mar 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

The changes refactor diagnostic collection in e2e tests: instead of immediately dumping tracked resources to GinkgoWriter on failure, diagnostics are now collected into a per-spec map and injected into JUnit reports during post-suite processing, with stderr logging added for panic scenarios.

Changes

Cohort / File(s) Summary
Diagnostic Collection Refactoring
e2e/e2e_common.go
Replaces dumpTrackedResources() with collectTrackedResourceDiagnostics() that returns a string instead of writing to GinkgoWriter. Adds os import, introduces specDiagnostics map for per-spec storage, and implements stderr logging for panics.
Test Report Integration
e2e/e2e_test.go
Adapts test failure handling to collect diagnostics upfront into specDiagnostics map and injects them into JUnit failure descriptions during ReportAfterSuite, replacing direct GinkgoWriter output augmentation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Diagnostics now dance in a stored up delight,
No more urgent dumps in the test's darkest night,
They gather and wait in a map so pristine,
Then gracefully join the reports in between!
A refactor so clean, the best we have seen!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Update e2e diagnostics' is vague and generic, using non-descriptive language that doesn't clearly convey the specific nature of the changes (removing duplicate diagnostic output via GinkgoWriter bypass). Consider a more specific title like 'Refactor e2e diagnostics to avoid duplication' or 'Bypass GinkgoWriter to prevent duplicate diagnostics' that better captures the main objective.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 5, 2026
@openshift-ci-robot
Copy link

@theobarberbany: This pull request explicitly references no jira issue.

Details

In response to this:

Don't double print diagnostics, bypassing GinkgoWriter entirely to avoid duplication. Relying on CapturedGinkgoWriterOutput was causing the dupes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from RadekManak and chrischdi March 5, 2026 17:20
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 5, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign racheljpg for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e/e2e_common.go`:
- Around line 71-73: The comment for specDiagnostics is inaccurate: it says the
map is keyed by “spec text” but the code keys entries by
LeafNodeLocation.String(); update the comment for specDiagnostics to state that
entries are keyed by the spec's LeafNodeLocation.String() (or simply “leaf node
location string”) and mention that ReportAfterEach populates it and
ReportAfterSuite reads it, so future maintainers won't assume spec text is the
key.

In `@e2e/e2e_test.go`:
- Around line 39-40: Replace the weak map key using only
report.LeafNodeLocation.String() when populating specDiagnostics (where diag :=
collectTrackedResourceDiagnostics() and
specDiagnostics[report.LeafNodeLocation.String()] = diag) with a composite key
that includes the leaf location plus the spec's unique text (e.g., combine
report.LeafNodeLocation.String() and report.FullText() or equivalent) so each
spec instance is unique; apply the same change to the other occurrence around
the specDiagnostics assignment at the later location (the lines referenced as
68-69) to prevent overwriting diagnostics for table-driven or helper-generated
specs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 33c5a4e8-e29b-454b-af86-9e5a52c242eb

📥 Commits

Reviewing files that changed from the base of the PR and between db34340 and 07fcbc1.

📒 Files selected for processing (2)
  • e2e/e2e_common.go
  • e2e/e2e_test.go

Comment on lines +71 to +73
// specDiagnostics stores per-spec diagnostic output keyed by spec text.
// ReportAfterEach populates it on failure; ReportAfterSuite reads it to
// append diagnostics to the JUnit failure message.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Comment/key mismatch for specDiagnostics can mislead future changes.

Line 71 says the map is keyed by “spec text”, but current usage keys by LeafNodeLocation.String(). Please align the comment to the implemented key to avoid maintenance mistakes.

✏️ Suggested comment fix
-// specDiagnostics stores per-spec diagnostic output keyed by spec text.
+// specDiagnostics stores per-spec diagnostic output keyed by leaf node location.
 // ReportAfterEach populates it on failure; ReportAfterSuite reads it to
 // append diagnostics to the JUnit failure message.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// specDiagnostics stores per-spec diagnostic output keyed by spec text.
// ReportAfterEach populates it on failure; ReportAfterSuite reads it to
// append diagnostics to the JUnit failure message.
// specDiagnostics stores per-spec diagnostic output keyed by leaf node location.
// ReportAfterEach populates it on failure; ReportAfterSuite reads it to
// append diagnostics to the JUnit failure message.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/e2e_common.go` around lines 71 - 73, The comment for specDiagnostics is
inaccurate: it says the map is keyed by “spec text” but the code keys entries by
LeafNodeLocation.String(); update the comment for specDiagnostics to state that
entries are keyed by the spec's LeafNodeLocation.String() (or simply “leaf node
location string”) and mention that ReportAfterEach populates it and
ReportAfterSuite reads it, so future maintainers won't assume spec text is the
key.

Comment on lines +39 to +40
diag := collectTrackedResourceDiagnostics()
specDiagnostics[report.LeafNodeLocation.String()] = diag
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check Go version in go.mod
head -5 go.mod | grep -i "^go "

Repository: openshift/cluster-capi-operator

Length of output: 84


🏁 Script executed:

# Read the relevant sections of e2e_test.go to understand the context
wc -l e2e/e2e_test.go && echo "---" && sed -n '30,50p' e2e/e2e_test.go && echo "---" && sed -n '60,75p' e2e/e2e_test.go

Repository: openshift/cluster-capi-operator

Length of output: 1209


🏁 Script executed:

# Check if FullText() method is available in the code
rg "FullText" e2e/e2e_test.go -A 2 -B 2

Repository: openshift/cluster-capi-operator

Length of output: 57


🏁 Script executed:

# Find the import of Ginkgo to determine exact version
rg "github.com/onsi/ginkgo" go.mod

Repository: openshift/cluster-capi-operator

Length of output: 143


🌐 Web query:

Ginkgo v2.2.0 SpecReport LeafNodeLocation uniqueness guarantee table-driven tests

💡 Result:

In Ginkgo v2.2.0, types.SpecReport.LeafNodeLocation is just a types.CodeLocation (i.e., FileName, LineNumber, optional stack trace / custom message) pointing at where Ginkgo believes the leaf node (typically an It, or the generated leaf node for a table Entry) was declared—it is not documented as a uniqueness guarantee. So you should expect duplicates any time multiple specs resolve to the same callsite/line (common with helpers/wrappers, loops that generate nodes, or table entries that end up sharing a single declaration location). [1][2]

For table-driven tests specifically: each Entry(...) becomes its own spec, but LeafNodeLocation is still only a source location, not an ID, so it’s not safe to use it as a unique key for entries/specs. [1][2]

If you need stable uniqueness, prefer deriving a key from the spec’s text (e.g., report.FullText() / hierarchy + LeafNodeText), or explicitly set a distinct location/message via the types.CodeLocation decorator (e.g. types.NewCustomCodeLocation("...")) when constructing nodes. [2]

Sources:
[1] Ginkgo types.SpecReport / LeafNodeLocation field docs (pkg.go.dev) (pkg.go.dev)
[2] Ginkgo docs: CodeLocation decorator / types.NewCustomCodeLocation (onsi.github.io)

Citations:


Use a stronger diagnostics key to prevent collisions across failed specs.

Using only LeafNodeLocation.String() as a map key risks collisions when multiple specs share the same source location—this occurs with table-driven tests (multiple Entry calls at one line) or specs generated by helpers. This will cause one spec's diagnostics to overwrite another's, attaching the wrong diagnostic text to failures in the JUnit output at lines 39-40 and 68-69.

A composite key combining LeafNodeLocation.String() with FullText() (or equivalent) ensures uniqueness per spec.

🔧 Suggested fix
 var _ = ReportAfterEach(func(report SpecReport) {
 	if report.Failed() {
 		diag := collectTrackedResourceDiagnostics()
-		specDiagnostics[report.LeafNodeLocation.String()] = diag
+		specDiagnostics[diagnosticKey(report)] = diag
 	}

 	resourcesUnderTest = nil
 })
+
+func diagnosticKey(sr SpecReport) string {
+	return fmt.Sprintf("%s|%s", sr.LeafNodeLocation.String(), sr.FullText())
+}
@@
-		if diag, ok := specDiagnostics[sr.LeafNodeLocation.String()]; ok {
+		if diag, ok := specDiagnostics[diagnosticKey(*sr)]; ok {
 			sr.Failure.Message += "\n\n" + diag
 		}

Also applies to: 68-69

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/e2e_test.go` around lines 39 - 40, Replace the weak map key using only
report.LeafNodeLocation.String() when populating specDiagnostics (where diag :=
collectTrackedResourceDiagnostics() and
specDiagnostics[report.LeafNodeLocation.String()] = diag) with a composite key
that includes the leaf location plus the spec's unique text (e.g., combine
report.LeafNodeLocation.String() and report.FullText() or equivalent) so each
spec instance is unique; apply the same change to the other occurrence around
the specDiagnostics assignment at the later location (the lines referenced as
68-69) to prevent overwriting diagnostics for table-driven or helper-generated
specs.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 5, 2026

@theobarberbany: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants