Skip to content

Commit b7c918e

Browse files
authoredJan 21, 2022
ci: Support configuring the logging level for the splitter package (#2579)
Update the split package and add support for configuring the logging level to avoid CI interpretting info-level logging as error messages. Signed-off-by: timflannagan <[email protected]>
1 parent a07e3cc commit b7c918e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed
 

‎test/e2e/split/main.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212
"regexp"
1313
"sort"
1414
"strings"
15-
)
1615

17-
// TODO: configurable log verbosity.
16+
"github.com/sirupsen/logrus"
17+
)
1818

1919
type options struct {
2020
numChunks int
2121
printChunk int
2222
printDebug bool
2323
writer io.Writer
24+
logLevel string
2425
}
2526

2627
func main() {
@@ -30,6 +31,7 @@ func main() {
3031
flag.IntVar(&opts.numChunks, "chunks", 1, "Number of chunks to create focus regexps for")
3132
flag.IntVar(&opts.printChunk, "print-chunk", 0, "Chunk to print a regexp for")
3233
flag.BoolVar(&opts.printDebug, "print-debug", false, "Print all spec prefixes in non-regexp format. Use for debugging")
34+
flag.StringVar(&opts.logLevel, "log-level", logrus.ErrorLevel.String(), "Configure the logging level")
3335
flag.Parse()
3436

3537
if opts.printChunk >= opts.numChunks {
@@ -60,7 +62,14 @@ func exitIfErr(err error) {
6062
}
6163

6264
func (opts options) run(dir string) error {
63-
describes, err := findDescribes(dir)
65+
level, err := logrus.ParseLevel(opts.logLevel)
66+
if err != nil {
67+
return fmt.Errorf("failed to parse the %s log level: %v", opts.logLevel, err)
68+
}
69+
logger := logrus.New()
70+
logger.SetLevel(level)
71+
72+
describes, err := findDescribes(logger, dir)
6473
if err != nil {
6574
return err
6675
}
@@ -88,7 +97,7 @@ func (opts options) run(dir string) error {
8897
// like https://github.com/operator-framework/operator-lifecycle-manager/pull/1476 does.
8998
var topDescribeRE = regexp.MustCompile(`var _ = Describe\("(.+)", func\(.*`)
9099

91-
func findDescribes(dir string) ([]string, error) {
100+
func findDescribes(logger logrus.FieldLogger, dir string) ([]string, error) {
92101
// Find all Ginkgo specs in dir's test files.
93102
// These can be grouped independently.
94103
describeTable := make(map[string]struct{})
@@ -103,14 +112,14 @@ func findDescribes(dir string) ([]string, error) {
103112
}
104113
specNames := topDescribeRE.FindAllSubmatch(b, -1)
105114
if len(specNames) == 0 {
106-
log.Printf("%s: found no top level describes, skipping", match)
115+
logger.Warnf("%s: found no top level describes, skipping", match)
107116
continue
108117
}
109118
for _, possibleNames := range specNames {
110119
if len(possibleNames) != 2 {
111-
log.Printf("%s: expected to find 2 submatch, found %d:", match, len(possibleNames))
120+
logger.Debugf("%s: expected to find 2 submatch, found %d:", match, len(possibleNames))
112121
for _, name := range possibleNames {
113-
log.Printf("\t%s\n", string(name))
122+
logger.Debugf("\t%s\n", string(name))
114123
}
115124
continue
116125
}
@@ -129,7 +138,6 @@ func findDescribes(dir string) ([]string, error) {
129138
}
130139

131140
func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error) {
132-
133141
numSpecs := len(specs)
134142
if numSpecs < numChunks {
135143
return "", fmt.Errorf("have more desired chunks (%d) than specs (%d)", numChunks, numSpecs)
@@ -170,7 +178,6 @@ func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error
170178
}
171179

172180
func findMinimalWordPrefixes(specs []string) (prefixes []string) {
173-
174181
// Create a word trie of all spec strings.
175182
t := make(wordTrie)
176183
for _, spec := range specs {

0 commit comments

Comments
 (0)
Please sign in to comment.