Skip to content

Commit 542f302

Browse files
heschigopherbot
authored andcommitted
cmd/greplogs: associate known issues by regex
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 <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 8424680 commit 542f302

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

cmd/greplogs/flags.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
package main
66

7-
import "regexp"
7+
import (
8+
"fmt"
9+
"regexp"
10+
"sort"
11+
"strings"
12+
)
813

914
type regexpList []*regexp.Regexp
1015

@@ -58,3 +63,45 @@ func (x *regexpList) Matches(data []byte) [][]int {
5863
}
5964
return matches
6065
}
66+
67+
type regexpMap map[string]*regexp.Regexp
68+
69+
func (x *regexpMap) Set(s string) error {
70+
if *x == nil {
71+
*x = regexpMap{}
72+
}
73+
k, v, ok := strings.Cut(s, "=")
74+
if !ok {
75+
return fmt.Errorf("missing key, expected key=value in %q", s)
76+
}
77+
re, err := regexp.Compile("(?m)" + v)
78+
if err != nil {
79+
// Get an error without our modifications.
80+
_, err2 := regexp.Compile(v)
81+
if err2 != nil {
82+
err = err2
83+
}
84+
return err
85+
}
86+
(*x)[k] = re
87+
return nil
88+
}
89+
90+
func (x *regexpMap) String() string {
91+
var result []string
92+
for k, v := range *x {
93+
result = append(result, fmt.Sprintf("%v=%v", k, v))
94+
}
95+
return strings.Join(result, ",")
96+
}
97+
98+
func (x *regexpMap) Matches(data []byte) []string {
99+
var matches []string
100+
for k, r := range *x {
101+
if r.Match(data) {
102+
matches = append(matches, k)
103+
}
104+
}
105+
sort.Strings(matches)
106+
return matches
107+
}

cmd/greplogs/main.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
fileRegexps regexpList
4747
failRegexps regexpList
4848
omit regexpList
49+
knownIssues regexpMap
4950

5051
flagDashboard = flag.Bool("dashboard", true, "search dashboard logs from fetchlogs")
5152
flagMD = flag.Bool("md", true, "output in Markdown")
@@ -69,6 +70,7 @@ var brokenBuilders []string
6970
func main() {
7071
// XXX What I want right now is just to point it at a bunch of
7172
// logs and have it extract the failures.
73+
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.")
7274
flag.Var(&fileRegexps, "e", "show files matching `regexp`; if provided multiple times, files must match all regexps")
7375
flag.Var(&failRegexps, "E", "show only errors matching `regexp`; if provided multiple times, an error must match all regexps")
7476
flag.Var(&omit, "omit", "omit results for builder names and/or revisions matching `regexp`; if provided multiple times, logs matching any regexp are omitted")
@@ -244,10 +246,17 @@ func process(path, nicePath string) (found bool, err error) {
244246
}
245247

246248
printPath := nicePath
249+
kiMatches := 0
247250
if *flagMD && logURL != "" {
248251
prefix := ""
249252
if *flagTriage {
250-
prefix = "- [ ] "
253+
matches := knownIssues.Matches(data)
254+
if len(matches) == 0 {
255+
prefix = "- [ ] "
256+
} else {
257+
kiMatches++
258+
prefix = fmt.Sprintf("- [x] (%v) ", strings.Join(matches, ", "))
259+
}
251260
}
252261
printPath = fmt.Sprintf("%s[%s](%s)", prefix, nicePath, logURL)
253262
}

0 commit comments

Comments
 (0)