Skip to content

Commit

Permalink
Add ignorable restore error logs and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaovilai committed Aug 12, 2023
1 parent 3c0365c commit 8bf081a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
32 changes: 10 additions & 22 deletions tests/e2e/lib/velero_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ var errorIgnorePatterns = []string{
"blob unknown",
"num errors=0",
"level=debug", // debug logs may contain the text error about recoverable errors so ignore them

// Ignore managed fields errors per https://github.com/vmware-tanzu/velero/pull/6110 and avoid e2e failure.
// https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/openshift_oadp-operator/1126/pull-ci-openshift-oadp-operator-master-4.10-operator-e2e-aws/1690109468546699264#1:build-log.txt%3A686
"level=error msg=\"error patch for managed fields ",
}

func recoverFromPanicLogs(veleroNamespace string, panicReason interface{}, panicFrom string) string {
Expand All @@ -178,37 +182,21 @@ func recoverFromPanicLogs(veleroNamespace string, panicReason interface{}, panic

func BackupErrorLogs(ocClient client.Client, backup velero.Backup) []string {
bl := BackupLogs(ocClient, backup)
errorRegex, err := regexp.Compile("error|Error")
if err != nil {
return []string{"could not compile regex: ", err.Error()}
}
logLines := []string{}
for _, line := range strings.Split(bl, "\n") {
if errorRegex.MatchString(line) {
// ignore some expected errors
ignoreLine := false
for _, ignore := range errorIgnorePatterns {
ignoreLine, _ = regexp.MatchString(ignore, line)
if ignoreLine {
break
}
}
if !ignoreLine {
logLines = append(logLines, line)
}
}
}
return logLines
return errorLogsExcludingIgnored(bl)
}

func RestoreErrorLogs(ocClient client.Client, restore velero.Restore) []string {
rl := RestoreLogs(ocClient, restore)
return errorLogsExcludingIgnored(rl)
}

func errorLogsExcludingIgnored(logs string) []string {
errorRegex, err := regexp.Compile("error|Error")
if err != nil {
return []string{"could not compile regex: ", err.Error()}
}
logLines := []string{}
for _, line := range strings.Split(rl, "\n") {
for _, line := range strings.Split(logs, "\n") {
if errorRegex.MatchString(line) {
// ignore some expected errors
ignoreLine := false
Expand Down
37 changes: 37 additions & 0 deletions tests/e2e/lib/velero_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lib

import (
"reflect"
"testing"
)

func Test_errorLogsExcludingIgnored(t *testing.T) {
type args struct {
logs string
}
tests := []struct {
name string
args args
want []string
}{
{
// sample from https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/openshift_oadp-operator/1126/pull-ci-openshift-oadp-operator-master-4.10-operator-e2e-aws/1690109468546699264#1:build-log.txt%3A686
name: "error patch for managed fields are ignored",
args: args{
logs: `time="2023-08-11T22:02:39Z" level=debug msg="status field for endpointslices.discovery.k8s.io: exists: false, should restore: false" logSource="pkg/restore/restore.go:1487" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d
time="2023-08-11T22:02:39Z" level=error msg="error patch for managed fields mysql-persistent/mysql-6ztv6: endpointslices.discovery.k8s.io \"mysql-6ztv6\" not found" logSource="pkg/restore/restore.go:1516" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d
time="2023-08-11T22:02:39Z" level=info msg="Restored 40 items out of an estimated total of 50 (estimate will change throughout the restore)" logSource="pkg/restore/restore.go:669" name=mysql-6ztv6 namespace=mysql-persistent progress= resource=endpointslices.discovery.k8s.io restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d
time="2023-08-11T22:02:39Z" level=info msg="restore status includes excludes: <nil>" logSource="pkg/restore/restore.go:1189" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d
time="2023-08-11T22:02:39Z" level=debug msg="Skipping action because it does not apply to this resource" logSource="pkg/plugin/framework/action_resolver.go:61" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d`,
},
want: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := errorLogsExcludingIgnored(tt.args.logs); !reflect.DeepEqual(got, tt.want) {
t.Errorf("errorLogsExcludingIgnored() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 8bf081a

Please sign in to comment.