Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pkg/monitortestlibrary/allowedalerts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var AllowedAlertNames = []string{
"Watchdog",
"AlertmanagerReceiversNotConfigured",
"PrometheusRemoteWriteDesiredShards",
"KubeJobFailingSRE", // https://issues.redhat.com/browse/OCPBUGS-55635
"KubeJobFailingSRE", // https://issues.redhat.com/browse/OCPBUGS-55635
"CreateMustGather.*", // https://issues.redhat.com/browse/SREP-4796

// indicates a problem in the external Telemeter service, presently very common, does not impact our ability to e2e test:
"TelemeterClientFailures",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package legacytestframeworkmonitortests
import (
"context"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -239,7 +240,7 @@ func runBackstopTest(
func isSkippedAlert(alertName string) bool {
// Some alerts we always skip over in CI:
for _, a := range allowedalerts.AllowedAlertNames {
if a == alertName {
if matched, _ := regexp.MatchString("^"+a+"$", alertName); matched {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Verify ignored regexp errors in isSkippedAlert:"
rg -n --type=go 'regexp\.MatchString\(' pkg/monitortests/testframework/legacytestframeworkmonitortests/alerts.go
rg -n --type=go 'if matched,\s*_\s*:=' pkg/monitortests/testframework/legacytestframeworkmonitortests/alerts.go

echo
echo "Inspect AllowedAlertNames patterns to audit regex validity/intent:"
awk '/AllowedAlertNames/,/\}/ {print NR ":" $0}' pkg/monitortestlibrary/allowedalerts/types.go

Repository: openshift/origin

Length of output: 1156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check imports in the alerts.go file
echo "Checking imports in alerts.go:"
head -20 pkg/monitortests/testframework/legacytestframeworkmonitortests/alerts.go

echo
echo "Checking full isSkippedAlert function:"
sed -n '238,260p' pkg/monitortests/testframework/legacytestframeworkmonitortests/alerts.go

Repository: openshift/origin

Length of output: 1577


Handle regex errors explicitly in isSkippedAlert.

Line 243 ignores regexp.MatchString errors, so an invalid allowlist pattern fails silently and can cause hard-to-debug invariant test failures. Since AllowedAlertNames contains regex patterns like "CreateMustGather.*", malformed patterns must be caught early. Please fail fast instead of dropping the error.

Proposed fix
 func isSkippedAlert(alertName string) bool {
 	// Some alerts we always skip over in CI:
 	for _, a := range allowedalerts.AllowedAlertNames {
-		if matched, _ := regexp.MatchString("^"+a+"$", alertName); matched {
+		pattern := "^" + a + "$"
+		matched, err := regexp.MatchString(pattern, alertName)
+		if err != nil {
+			panic(fmt.Sprintf("invalid allowed alert regex %q: %v", pattern, err))
+		}
+		if matched {
 			return true
 		}
 	}
📝 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
if matched, _ := regexp.MatchString("^"+a+"$", alertName); matched {
pattern := "^" + a + "$"
matched, err := regexp.MatchString(pattern, alertName)
if err != nil {
panic(fmt.Sprintf("invalid allowed alert regex %q: %v", pattern, err))
}
if matched {
return true
}
🤖 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 `@pkg/monitortests/testframework/legacytestframeworkmonitortests/alerts.go` at
line 243, The loop in isSkippedAlert currently ignores the error from
regexp.MatchString which hides malformed regexes in AllowedAlertNames; change
isSkippedAlert to check the error returned by regexp.MatchString("^"+a+"$",
alertName) and fail fast by returning the error (i.e., change signature to
isSkippedAlert(...) (bool, error) or panic/log.Fatalf in test code), update all
callers accordingly to propagate or handle the error, and ensure any malformed
pattern causes an immediate test failure rather than being silently skipped.

return true
}
}
Expand Down