Skip to content

Commit edb1350

Browse files
test: add regexp log parser (#904)
add regexp log filter --------- Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent 7ecc0cc commit edb1350

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

tests/e2e/config/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path/filepath"
2525
"reflect"
26+
"regexp"
2627
"slices"
2728
"strconv"
2829

@@ -130,6 +131,7 @@ type Config struct {
130131
Namespace string `yaml:"namespaceSuffix"`
131132
TestData TestData `yaml:"testData"`
132133
LogFilter []string `yaml:"logFilter"`
134+
RegexpLogFilter []regexp.Regexp `yaml:"regexpLogFilter"`
133135
StorageClass StorageClass
134136
}
135137

@@ -278,7 +280,7 @@ func (k *Kustomize) SetParams(filePath, namespace, namePrefix string) error {
278280
return readErr
279281
}
280282

281-
unmarshalErr := yamlv3.Unmarshal([]byte(data), &kustomizeFile)
283+
unmarshalErr := yamlv3.Unmarshal(data, &kustomizeFile)
282284
if unmarshalErr != nil {
283285
return unmarshalErr
284286
}
@@ -310,7 +312,7 @@ func (k *Kustomize) GetNamespace(filePath string) (string, error) {
310312
return "", fmt.Errorf("cannot get namespace from %s: %w", filePath, readErr)
311313
}
312314

313-
unmarshalErr := yamlv3.Unmarshal([]byte(data), &kustomizeFile)
315+
unmarshalErr := yamlv3.Unmarshal(data, &kustomizeFile)
314316
if unmarshalErr != nil {
315317
return "", fmt.Errorf("cannot get namespace from %s: %w", filePath, unmarshalErr)
316318
}
@@ -326,7 +328,7 @@ func (k *Kustomize) ExcludeResource(filePath, resourceName string) error {
326328
return readErr
327329
}
328330

329-
unmarshalErr := yamlv3.Unmarshal([]byte(data), &kustomizeFile)
331+
unmarshalErr := yamlv3.Unmarshal(data, &kustomizeFile)
330332
if unmarshalErr != nil {
331333
return unmarshalErr
332334
}

tests/e2e/default_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ logFilter:
5151
- "does not have a pvc reference" # "err": "kvvm head-345e7b6a-testcases-image-hotplug/head-345e7b6a-vm-image-hotplug spec volume vi-head-345e7b6a-vi-alpine-http does not have a pvc reference"
5252
- "get storage class specified in spec: storage class not found" # Err.
5353
- "lastTransitionTime: Required value" # Err.
54+
regexpLogFilter:
55+
- "failed to detach: .* not found" # "err" "failed to detach: virtualmachine.kubevirt.io \"head-497d17b-vm-automatic-with-hotplug\" not found",
56+
- "error patching .* not found" # "err" "error patching *** virtualimages.virtualization.deckhouse.io \"head-497d17b-vi-pvc-oref-vi-oref-vd\" not found",

tests/e2e/errlogger/errlogger.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"io"
2626
"io/fs"
2727
"os/exec"
28+
"regexp"
2829
"strings"
2930
"sync"
3031
"syscall"
@@ -97,7 +98,7 @@ func (l *LogStream) ParseStderr() {
9798
parseScanError(scanner.Err(), "STDERR")
9899
}
99100

100-
func (l *LogStream) ParseStdout(exludedPatterns []string, startTime time.Time) {
101+
func (l *LogStream) ParseStdout(excludedPatterns []string, excludedRegexpPattens []regexp.Regexp, startTime time.Time) {
101102
GinkgoHelper()
102103
defer GinkgoRecover()
103104
defer l.LogStreamWaitGroup.Done()
@@ -109,7 +110,7 @@ func (l *LogStream) ParseStdout(exludedPatterns []string, startTime time.Time) {
109110
rawEntry := strings.TrimPrefix(scanner.Text(), "0")
110111
err := json.Unmarshal([]byte(rawEntry), &entry)
111112
Expect(err).NotTo(HaveOccurred(), "error parsing JSON")
112-
if entry.Level == LevelError && !isMsgIgnoredByPattern(rawEntry, exludedPatterns) {
113+
if entry.Level == LevelError && !isMsgIgnoredByPattern(rawEntry, excludedPatterns, excludedRegexpPattens) {
113114
errTime, err := time.Parse(time.RFC3339, entry.Time)
114115
Expect(err).NotTo(HaveOccurred(), "failed to parse error timestamp")
115116
if errTime.After(startTime) {
@@ -168,12 +169,17 @@ func formatMessage(header, msg, color string) string {
168169
)
169170
}
170171

171-
func isMsgIgnoredByPattern(msg string, patterns []string) bool {
172+
func isMsgIgnoredByPattern(msg string, patterns []string, regexpPatterns []regexp.Regexp) bool {
172173
for _, s := range patterns {
173174
if strings.Contains(msg, s) {
174175
return true
175176
}
176177
}
178+
for _, r := range regexpPatterns {
179+
if r.MatchString(msg) {
180+
return true
181+
}
182+
}
177183
return false
178184
}
179185

tests/e2e/tests_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func StartV12nControllerLogStream(logStreamByPod map[string]*el.LogStream) {
282282
logStream.LogStreamWaitGroup.Add(1)
283283
go logStream.ParseStderr()
284284
logStream.LogStreamWaitGroup.Add(1)
285-
go logStream.ParseStdout(conf.LogFilter, startTime)
285+
go logStream.ParseStdout(conf.LogFilter, conf.RegexpLogFilter, startTime)
286286
}
287287
}
288288

0 commit comments

Comments
 (0)