Skip to content

ci: Support configuring the logging level for the splitter package #2579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
25 changes: 16 additions & 9 deletions test/e2e/split/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
"regexp"
"sort"
"strings"
)

// TODO: configurable log verbosity.
"github.com/sirupsen/logrus"
)

type options struct {
numChunks int
printChunk int
printDebug bool
writer io.Writer
logLevel string
}

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

if opts.printChunk >= opts.numChunks {
Expand Down Expand Up @@ -60,7 +62,14 @@ func exitIfErr(err error) {
}

func (opts options) run(dir string) error {
describes, err := findDescribes(dir)
level, err := logrus.ParseLevel(opts.logLevel)
if err != nil {
return fmt.Errorf("failed to parse the %s log level: %v", opts.logLevel, err)
}
logger := logrus.New()
logger.SetLevel(level)

describes, err := findDescribes(logger, dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -88,7 +97,7 @@ func (opts options) run(dir string) error {
// like https://github.com/operator-framework/operator-lifecycle-manager/pull/1476 does.
var topDescribeRE = regexp.MustCompile(`var _ = Describe\("(.+)", func\(.*`)

func findDescribes(dir string) ([]string, error) {
func findDescribes(logger logrus.FieldLogger, dir string) ([]string, error) {
// Find all Ginkgo specs in dir's test files.
// These can be grouped independently.
describeTable := make(map[string]struct{})
Expand All @@ -103,14 +112,14 @@ func findDescribes(dir string) ([]string, error) {
}
specNames := topDescribeRE.FindAllSubmatch(b, -1)
if len(specNames) == 0 {
log.Printf("%s: found no top level describes, skipping", match)
logger.Warnf("%s: found no top level describes, skipping", match)
Copy link
Member Author

Choose a reason for hiding this comment

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

Another implementation: we could also just remove logging from this package entirely. It's nice for debugging this package while developing locally, but provides little value when running in CI environments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's not getting in the way, I'd say leave it. Logging is helpful during development. Though a debugger is also nice...

continue
}
for _, possibleNames := range specNames {
if len(possibleNames) != 2 {
log.Printf("%s: expected to find 2 submatch, found %d:", match, len(possibleNames))
logger.Debugf("%s: expected to find 2 submatch, found %d:", match, len(possibleNames))
for _, name := range possibleNames {
log.Printf("\t%s\n", string(name))
logger.Debugf("\t%s\n", string(name))
}
continue
}
Expand All @@ -129,7 +138,6 @@ func findDescribes(dir string) ([]string, error) {
}

func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error) {

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

func findMinimalWordPrefixes(specs []string) (prefixes []string) {

// Create a word trie of all spec strings.
t := make(wordTrie)
for _, spec := range specs {
Expand Down