Skip to content

Commit

Permalink
cmd/greplogs: associate known issues by regex
Browse files Browse the repository at this point in the history
Add a flag --known issue that associates issues with log entries based
on regexp matches. It's used like this:

--known-issue='#53456=TestDebugLines'

Which results in the check box for that log being pre-checked, and the
text '#53456' being added, which turns into a pretty link on GitHub.

It might be nice to group issues as well, but I didn't want to mess with
the chronological ordering.

For golang/go#52653.

Change-Id: If4615cd798ba72c1c1ee3cb43f1d1ad6d4319528
Reviewed-on: https://go-review.googlesource.com/c/build/+/425075
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
  • Loading branch information
heschi authored and gopherbot committed Aug 25, 2022
1 parent 8424680 commit 542f302
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
49 changes: 48 additions & 1 deletion cmd/greplogs/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package main

import "regexp"
import (
"fmt"
"regexp"
"sort"
"strings"
)

type regexpList []*regexp.Regexp

Expand Down Expand Up @@ -58,3 +63,45 @@ func (x *regexpList) Matches(data []byte) [][]int {
}
return matches
}

type regexpMap map[string]*regexp.Regexp

func (x *regexpMap) Set(s string) error {
if *x == nil {
*x = regexpMap{}
}
k, v, ok := strings.Cut(s, "=")
if !ok {
return fmt.Errorf("missing key, expected key=value in %q", s)
}
re, err := regexp.Compile("(?m)" + v)
if err != nil {
// Get an error without our modifications.
_, err2 := regexp.Compile(v)
if err2 != nil {
err = err2
}
return err
}
(*x)[k] = re
return nil
}

func (x *regexpMap) String() string {
var result []string
for k, v := range *x {
result = append(result, fmt.Sprintf("%v=%v", k, v))
}
return strings.Join(result, ",")
}

func (x *regexpMap) Matches(data []byte) []string {
var matches []string
for k, r := range *x {
if r.Match(data) {
matches = append(matches, k)
}
}
sort.Strings(matches)
return matches
}
11 changes: 10 additions & 1 deletion cmd/greplogs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
fileRegexps regexpList
failRegexps regexpList
omit regexpList
knownIssues regexpMap

flagDashboard = flag.Bool("dashboard", true, "search dashboard logs from fetchlogs")
flagMD = flag.Bool("md", true, "output in Markdown")
Expand All @@ -69,6 +70,7 @@ var brokenBuilders []string
func main() {
// XXX What I want right now is just to point it at a bunch of
// logs and have it extract the failures.
flag.Var(&knownIssues, "known-issue", "add an issue=regexp mapping; if a log matches regexp it will be categorized under issue. One mapping per flag.")
flag.Var(&fileRegexps, "e", "show files matching `regexp`; if provided multiple times, files must match all regexps")
flag.Var(&failRegexps, "E", "show only errors matching `regexp`; if provided multiple times, an error must match all regexps")
flag.Var(&omit, "omit", "omit results for builder names and/or revisions matching `regexp`; if provided multiple times, logs matching any regexp are omitted")
Expand Down Expand Up @@ -244,10 +246,17 @@ func process(path, nicePath string) (found bool, err error) {
}

printPath := nicePath
kiMatches := 0
if *flagMD && logURL != "" {
prefix := ""
if *flagTriage {
prefix = "- [ ] "
matches := knownIssues.Matches(data)
if len(matches) == 0 {
prefix = "- [ ] "
} else {
kiMatches++
prefix = fmt.Sprintf("- [x] (%v) ", strings.Join(matches, ", "))
}
}
printPath = fmt.Sprintf("%s[%s](%s)", prefix, nicePath, logURL)
}
Expand Down

0 comments on commit 542f302

Please sign in to comment.