Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions test/framework/functional/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
yaml "sigs.k8s.io/yaml"

log "github.com/ViaQ/logerr/v2/log/static"
"github.com/onsi/gomega"
"github.com/openshift/cluster-logging-operator/internal/constants"
"github.com/openshift/cluster-logging-operator/internal/utils"
"github.com/openshift/cluster-logging-operator/test/client"
Expand Down Expand Up @@ -129,20 +130,34 @@ func (f *CollectorFunctionalFramework) AddSecret(secret *corev1.Secret) *Collect
}

func (f *CollectorFunctionalFramework) Cleanup() {
if g, ok := test.GinkgoCurrentTest(); ok && g.Failed() {
for _, container := range f.Pod.Spec.Containers {
log.Info("Dumping logs for container", "container", container.Name)
logs, err := oc.Logs().WithNamespace(f.Namespace).WithPod(f.Pod.Name).WithContainer(container.Name).Run()
if err != nil {
log.Error(err, "Unable to retrieve logs", "container", container.Name)
defer f.closeClient()

if g, ok := test.GinkgoCurrentTest(); ok {
if g.Failed() {
for _, container := range f.Pod.Spec.Containers {
log.Info("Dumping logs for container", "container", container.Name)
logs, err := oc.Logs().WithNamespace(f.Namespace).WithPod(f.Pod.Name).WithContainer(container.Name).Run()
if err != nil {
log.Error(err, "Unable to retrieve logs", "container", container.Name)
}
if _, err = fmt.Fprintln(f.delayedWriter, logs); err != nil {
log.Error(err, "Error writing", "container", container.Name)
}
}
if _, err = fmt.Fprintln(f.delayedWriter, logs); err != nil {
log.Error(err, "Error writing", "container", container.Name)
f.delayedWriter.FlushToArtifactsDir(fmt.Sprintf("%s_%d.log", g.FileName(), g.LineNumber()))
}

if !g.Failed() {
if collectorLogs, err := f.ReadCollectorLogs(); err != nil {
log.Error(err, "Unable to read collector logs for VRL warning check")
} else if strings.Contains(collectorLogs, "VRL compilation warning") {
log.Info("VRL compilation warning detected in collector logs")
fmt.Fprintln(f.delayedWriter, collectorLogs)
f.delayedWriter.FlushToArtifactsDir(fmt.Sprintf("%s_%d.log", g.FileName(), g.LineNumber()))
gomega.Expect(collectorLogs).ToNot(gomega.ContainSubstring("VRL compilation warning"))
Comment on lines +150 to +157

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Capture failure artifacts when the warning assertion fails.

g.Failed() is evaluated before gomega.Expect. If a VRL warning is the first failure, the assertion marks the test failed after the artifact-dump branch was skipped, so FlushToArtifactsDir is never called. Run the warning check before failure-artifact handling, or explicitly flush artifacts before asserting.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/framework/functional/framework.go` around lines 150 - 155, The VRL
warning assertion in the collector-log handling occurs after the g.Failed()
check, so its first failure skips artifact collection. Update the flow around
ReadCollectorLogs and the warning Expect to perform the warning check before
failure-artifact handling, or flush artifacts immediately before asserting,
ensuring FlushToArtifactsDir runs when this assertion fails.

}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
f.delayedWriter.FlushToArtifactsDir(fmt.Sprintf("%s_%d.log", g.FileName(), g.LineNumber()))
}
f.closeClient()
}

func (f *CollectorFunctionalFramework) GetMaxReadDuration() time.Duration {
Expand Down
Loading