Skip to content

Commit c917a6b

Browse files
craig[bot]rafiss
andcommitted
107444: issues: use prefix match to check for existing issue r=renatolabs,tbg a=rafiss It is conventional to annotate a test failure issue title with some additional information about the failure cause. The previous logic was too strict in requiring an exact title match. Now it will match as long as the title matches exactly OR if the prefix matches and is followed by whitespace. Example: I added a suffix to [`sql/tests: TestRandomSyntaxFunctions failed [panic in request_job_execution_details]`](cockroachdb#106970) since the issue was with a function the jobs team added. But the next day cockroachdb#107237 was opened anew. This PR would prevent that from happening. Epic: None Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents 06fb4c1 + 77f32c4 commit c917a6b

20 files changed

+62
-60
lines changed

pkg/cmd/internal/issues/issues.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"log"
1717
"net/url"
1818
"os"
19+
"regexp"
1920
"strings"
2021

2122
"github.com/cockroachdb/cockroach/pkg/build"
@@ -316,7 +317,7 @@ func (p *poster) post(origCtx context.Context, formatter IssueFormatter, req Pos
316317
rRelated = &github.IssuesSearchResult{}
317318
}
318319

319-
existingIssues := filterByExactTitleMatch(rExisting, title)
320+
existingIssues := filterByPrefixTitleMatch(rExisting, title)
320321
var foundIssue *int
321322
if len(existingIssues) > 0 {
322323
// We found an existing issue to post a comment into.
@@ -327,7 +328,7 @@ func (p *poster) post(origCtx context.Context, formatter IssueFormatter, req Pos
327328
data.MentionOnCreate = nil
328329
}
329330

330-
data.RelatedIssues = filterByExactTitleMatch(rRelated, title)
331+
data.RelatedIssues = filterByPrefixTitleMatch(rRelated, title)
331332
data.InternalLog = ctx.Builder.String()
332333
r := &Renderer{}
333334
if err := formatter.Body(r, data); err != nil {
@@ -486,18 +487,19 @@ func HelpCommandAsLink(title, href string) func(r *Renderer) {
486487
}
487488
}
488489

489-
// filterByExactTitleMatch filters the search result passed and
490-
// removes any issues where the title does not match the expected
491-
// title exactly. This is done because the GitHub API does not support
492-
// searching by exact title; as a consequence, without this function,
493-
// there is a chance we would group together test failures for two
494-
// similarly named tests. That is confusing and undesirable behavior.
495-
func filterByExactTitleMatch(
490+
// filterByPrefixTitleMatch filters the search result passed and removes any
491+
// issues where the title does not match the expected title, optionally followed
492+
// by whitespace. This is done because the GitHub API does not support searching
493+
// by exact title; as a consequence, without this function, there is a chance we
494+
// would group together test failures for two similarly named tests. That is
495+
// confusing and undesirable behavior.
496+
func filterByPrefixTitleMatch(
496497
result *github.IssuesSearchResult, expectedTitle string,
497498
) []github.Issue {
499+
expectedTitleRegex := regexp.MustCompile(`^` + expectedTitle + `(\s+|$)`)
498500
var issues []github.Issue
499501
for _, issue := range result.Issues {
500-
if title := issue.Title; title != nil && *title == expectedTitle {
502+
if title := issue.Title; title != nil && expectedTitleRegex.MatchString(*title) {
501503
issues = append(issues, issue)
502504
}
503505
}

pkg/cmd/internal/issues/issues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ test logs left over in: /go/src/github.com/cockroachdb/cockroach/artifacts/logTe
185185
issueNum = *base.Number
186186
}
187187
return github.Issue{
188-
Title: github.String(fmt.Sprintf("%s: %s%s failed", packageName, testName, suffix)),
188+
Title: github.String(fmt.Sprintf("%s: %s%s failed [failure reason]", packageName, testName, suffix)),
189189
Number: &issueNum,
190190
Labels: base.Labels,
191191
}
@@ -213,7 +213,7 @@ test logs left over in: /go/src/github.com/cockroachdb/cockroach/artifacts/logTe
213213
relatedIssue := github.Issue{
214214
// Title is generated during the test using the test case's
215215
// package and test names
216-
Number: github.Int(issueNumber + 1),
216+
Number: github.Int(issueNumber + 10),
217217
Labels: []github.Label{{
218218
Name: github.String("C-test-failure"),
219219
URL: github.String("fake"),

pkg/cmd/internal/issues/testdata/post/failure-matching-and-related-issue.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
post
22
----
33
----
4-
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" label:branch-release-0.1 -label:X-noreuse: [github.Issue{Number:31, Title:"storage: TestReplicateQueueRebalance-similar failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]} github.Issue{Number:30, Title:"storage: TestReplicateQueueRebalance failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]}]
5-
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" -label:branch-release-0.1: [github.Issue{Number:31, Title:"storage: TestReplicateQueueRebalance failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]}]
4+
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" label:branch-release-0.1 -label:X-noreuse: [github.Issue{Number:31, Title:"storage: TestReplicateQueueRebalance-similar failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]} github.Issue{Number:30, Title:"storage: TestReplicateQueueRebalance failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]}]
5+
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" -label:branch-release-0.1: [github.Issue{Number:40, Title:"storage: TestReplicateQueueRebalance failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]}]
66
createComment owner=cockroachdb repo=cockroach issue=30:
77

88
storage.TestReplicateQueueRebalance [failed](https://teamcity.example.com/buildConfiguration/nightly123/8008135?buildTab=log) on release-0.1 @ [abcd123](https://github.com/cockroachdb/cockroach/commits/abcd123):
@@ -24,7 +24,7 @@ See also: [How To Investigate a Go Test Failure \(internal\)](https://cockroachl
2424
<details><summary>Same failure on other branches</summary>
2525
<p>
2626

27-
- #31 storage: TestReplicateQueueRebalance failed [C-test-failure O-robot release-0.2]
27+
- #40 storage: TestReplicateQueueRebalance failed [failure reason] [C-test-failure O-robot release-0.2]
2828
</p>
2929
</details>
3030
<sub>
@@ -33,6 +33,6 @@ See also: [How To Investigate a Go Test Failure \(internal\)](https://cockroachl
3333
</sub>
3434

3535

36-
Rendered: https://github.com/cockroachdb/cockroach/issues/new?body=storage.TestReplicateQueueRebalance+%5Bfailed%5D%28https%3A%2F%2Fteamcity.example.com%2FbuildConfiguration%2Fnightly123%2F8008135%3FbuildTab%3Dlog%29+on+release-0.1+%40+%5Babcd123%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Fcommits%2Fabcd123%29%3A%0A%0A%0A%60%60%60%0A%09%3Cautogenerated%3E%3A12%3A+storage%2Freplicate_queue_test.go%3A103%2C+condition+failed+to+evaluate+within+45s%3A+not+balanced%3A+%5B10+1+10+1+8%5D%0A%60%60%60%0A%3Cp%3EParameters%3A+%3Ccode%3EGOFLAGS%3Drace%3C%2Fcode%3E%0A%2C+%3Ccode%3EROACHTEST_cloud%3Dgce%3C%2Fcode%3E%0A%2C+%3Ccode%3ETAGS%3Ddeadlock%3C%2Fcode%3E%0A%3C%2Fp%3E%0A%3Cdetails%3E%3Csummary%3EHelp%3C%2Fsummary%3E%0A%3Cp%3E%0A%0ASee+also%3A+%5BHow+To+Investigate+a+Go+Test+Failure+%5C%28internal%5C%29%5D%28https%3A%2F%2Fcockroachlabs.atlassian.net%2Fl%2Fc%2FHgfXfJgM%29%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Cdetails%3E%3Csummary%3ESame+failure+on+other+branches%3C%2Fsummary%3E%0A%3Cp%3E%0A%0A-+%2331+storage%3A+TestReplicateQueueRebalance+failed+%5BC-test-failure+O-robot+release-0.2%5D%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Csub%3E%0A%0A%5BThis+test+on+roachdash%5D%28https%3A%2F%2Froachdash.crdb.dev%2F%3Ffilter%3Dstatus%3Aopen%2520t%3A.%2ATestReplicateQueueRebalance.%2A%26sort%3Dtitle%2Bcreated%26display%3Dlastcommented%2Bproject%29+%7C+%5BImprove+this+report%21%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Ftree%2Fmaster%2Fpkg%2Fcmd%2Finternal%2Fissues%29%0A%3C%2Fsub%3E%0A&title=%3Ccomment%3E
36+
Rendered: https://github.com/cockroachdb/cockroach/issues/new?body=storage.TestReplicateQueueRebalance+%5Bfailed%5D%28https%3A%2F%2Fteamcity.example.com%2FbuildConfiguration%2Fnightly123%2F8008135%3FbuildTab%3Dlog%29+on+release-0.1+%40+%5Babcd123%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Fcommits%2Fabcd123%29%3A%0A%0A%0A%60%60%60%0A%09%3Cautogenerated%3E%3A12%3A+storage%2Freplicate_queue_test.go%3A103%2C+condition+failed+to+evaluate+within+45s%3A+not+balanced%3A+%5B10+1+10+1+8%5D%0A%60%60%60%0A%3Cp%3EParameters%3A+%3Ccode%3EGOFLAGS%3Drace%3C%2Fcode%3E%0A%2C+%3Ccode%3EROACHTEST_cloud%3Dgce%3C%2Fcode%3E%0A%2C+%3Ccode%3ETAGS%3Ddeadlock%3C%2Fcode%3E%0A%3C%2Fp%3E%0A%3Cdetails%3E%3Csummary%3EHelp%3C%2Fsummary%3E%0A%3Cp%3E%0A%0ASee+also%3A+%5BHow+To+Investigate+a+Go+Test+Failure+%5C%28internal%5C%29%5D%28https%3A%2F%2Fcockroachlabs.atlassian.net%2Fl%2Fc%2FHgfXfJgM%29%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Cdetails%3E%3Csummary%3ESame+failure+on+other+branches%3C%2Fsummary%3E%0A%3Cp%3E%0A%0A-+%2340+storage%3A+TestReplicateQueueRebalance+failed+%5Bfailure+reason%5D+%5BC-test-failure+O-robot+release-0.2%5D%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Csub%3E%0A%0A%5BThis+test+on+roachdash%5D%28https%3A%2F%2Froachdash.crdb.dev%2F%3Ffilter%3Dstatus%3Aopen%2520t%3A.%2ATestReplicateQueueRebalance.%2A%26sort%3Dtitle%2Bcreated%26display%3Dlastcommented%2Bproject%29+%7C+%5BImprove+this+report%21%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Ftree%2Fmaster%2Fpkg%2Fcmd%2Finternal%2Fissues%29%0A%3C%2Fsub%3E%0A&title=%3Ccomment%3E
3737
----
3838
----

pkg/cmd/internal/issues/testdata/post/failure-matching-issue.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
post
22
----
33
----
4-
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" label:branch-release-0.1 -label:X-noreuse: [github.Issue{Number:30, Title:"storage: TestReplicateQueueRebalance failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]} github.Issue{Number:32, Title:"storage: TestReplicateQueueRebalance-similar failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]}]
4+
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" label:branch-release-0.1 -label:X-noreuse: [github.Issue{Number:30, Title:"storage: TestReplicateQueueRebalance failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]} github.Issue{Number:32, Title:"storage: TestReplicateQueueRebalance-similar failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.1"}]}]
55
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" -label:branch-release-0.1: []
66
createComment owner=cockroachdb repo=cockroach issue=30:
77

pkg/cmd/internal/issues/testdata/post/failure-related-issue.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ post
22
----
33
----
44
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" label:branch-release-0.1 -label:X-noreuse: []
5-
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" -label:branch-release-0.1: [github.Issue{Number:32, Title:"storage: TestReplicateQueueRebalance-similar failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]} github.Issue{Number:31, Title:"storage: TestReplicateQueueRebalance failed", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]}]
5+
searchIssue repo:"cockroach" user:"cockroachdb" is:issue is:open in:title label:"C-test-failure" sort:created-desc "storage: TestReplicateQueueRebalance failed" -label:branch-release-0.1: [github.Issue{Number:41, Title:"storage: TestReplicateQueueRebalance-similar failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]} github.Issue{Number:40, Title:"storage: TestReplicateQueueRebalance failed [failure reason]", Labels:[github.Label{URL:"fake", Name:"C-test-failure"} github.Label{URL:"fake", Name:"O-robot"} github.Label{URL:"fake", Name:"release-0.2"}]}]
66
getBinaryVersion: result v3.3.0
77
listMilestones owner=cockroachdb repo=cockroach: result [github.Milestone{Number:2, Title:"3.3"} github.Milestone{Number:1, Title:"3.2"}]
88
createIssue owner=cockroachdb repo=cockroach:
@@ -29,7 +29,7 @@ See also: [How To Investigate a Go Test Failure \(internal\)](https://cockroachl
2929
<details><summary>Same failure on other branches</summary>
3030
<p>
3131

32-
- #31 storage: TestReplicateQueueRebalance failed [C-test-failure O-robot release-0.2]
32+
- #40 storage: TestReplicateQueueRebalance failed [failure reason] [C-test-failure O-robot release-0.2]
3333
</p>
3434
</details>
3535
/cc @cockroachdb/idonotexistbecausethisisatest
@@ -39,6 +39,6 @@ See also: [How To Investigate a Go Test Failure \(internal\)](https://cockroachl
3939
</sub>
4040

4141

42-
Rendered: https://github.com/cockroachdb/cockroach/issues/new?body=storage.TestReplicateQueueRebalance+%5Bfailed%5D%28https%3A%2F%2Fteamcity.example.com%2FbuildConfiguration%2Fnightly123%2F8008135%3FbuildTab%3Dlog%29+on+release-0.1+%40+%5Babcd123%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Fcommits%2Fabcd123%29%3A%0A%0A%0A%60%60%60%0A%09%3Cautogenerated%3E%3A12%3A+storage%2Freplicate_queue_test.go%3A103%2C+condition+failed+to+evaluate+within+45s%3A+not+balanced%3A+%5B10+1+10+1+8%5D%0A%60%60%60%0A%3Cp%3EParameters%3A+%3Ccode%3EGOFLAGS%3Drace%3C%2Fcode%3E%0A%2C+%3Ccode%3EROACHTEST_cloud%3Dgce%3C%2Fcode%3E%0A%2C+%3Ccode%3ETAGS%3Ddeadlock%3C%2Fcode%3E%0A%3C%2Fp%3E%0A%3Cdetails%3E%3Csummary%3EHelp%3C%2Fsummary%3E%0A%3Cp%3E%0A%0ASee+also%3A+%5BHow+To+Investigate+a+Go+Test+Failure+%5C%28internal%5C%29%5D%28https%3A%2F%2Fcockroachlabs.atlassian.net%2Fl%2Fc%2FHgfXfJgM%29%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Cdetails%3E%3Csummary%3ESame+failure+on+other+branches%3C%2Fsummary%3E%0A%3Cp%3E%0A%0A-+%2331+storage%3A+TestReplicateQueueRebalance+failed+%5BC-test-failure+O-robot+release-0.2%5D%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%2Fcc+%40cockroachdb%2Fidonotexistbecausethisisatest%0A%3Csub%3E%0A%0A%5BThis+test+on+roachdash%5D%28https%3A%2F%2Froachdash.crdb.dev%2F%3Ffilter%3Dstatus%3Aopen%2520t%3A.%2ATestReplicateQueueRebalance.%2A%26sort%3Dtitle%2Bcreated%26display%3Dlastcommented%2Bproject%29+%7C+%5BImprove+this+report%21%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Ftree%2Fmaster%2Fpkg%2Fcmd%2Finternal%2Fissues%29%0A%3C%2Fsub%3E%0A&title=storage%3A+TestReplicateQueueRebalance+failed
42+
Rendered: https://github.com/cockroachdb/cockroach/issues/new?body=storage.TestReplicateQueueRebalance+%5Bfailed%5D%28https%3A%2F%2Fteamcity.example.com%2FbuildConfiguration%2Fnightly123%2F8008135%3FbuildTab%3Dlog%29+on+release-0.1+%40+%5Babcd123%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Fcommits%2Fabcd123%29%3A%0A%0A%0A%60%60%60%0A%09%3Cautogenerated%3E%3A12%3A+storage%2Freplicate_queue_test.go%3A103%2C+condition+failed+to+evaluate+within+45s%3A+not+balanced%3A+%5B10+1+10+1+8%5D%0A%60%60%60%0A%3Cp%3EParameters%3A+%3Ccode%3EGOFLAGS%3Drace%3C%2Fcode%3E%0A%2C+%3Ccode%3EROACHTEST_cloud%3Dgce%3C%2Fcode%3E%0A%2C+%3Ccode%3ETAGS%3Ddeadlock%3C%2Fcode%3E%0A%3C%2Fp%3E%0A%3Cdetails%3E%3Csummary%3EHelp%3C%2Fsummary%3E%0A%3Cp%3E%0A%0ASee+also%3A+%5BHow+To+Investigate+a+Go+Test+Failure+%5C%28internal%5C%29%5D%28https%3A%2F%2Fcockroachlabs.atlassian.net%2Fl%2Fc%2FHgfXfJgM%29%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%3Cdetails%3E%3Csummary%3ESame+failure+on+other+branches%3C%2Fsummary%3E%0A%3Cp%3E%0A%0A-+%2340+storage%3A+TestReplicateQueueRebalance+failed+%5Bfailure+reason%5D+%5BC-test-failure+O-robot+release-0.2%5D%0A%3C%2Fp%3E%0A%3C%2Fdetails%3E%0A%2Fcc+%40cockroachdb%2Fidonotexistbecausethisisatest%0A%3Csub%3E%0A%0A%5BThis+test+on+roachdash%5D%28https%3A%2F%2Froachdash.crdb.dev%2F%3Ffilter%3Dstatus%3Aopen%2520t%3A.%2ATestReplicateQueueRebalance.%2A%26sort%3Dtitle%2Bcreated%26display%3Dlastcommented%2Bproject%29+%7C+%5BImprove+this+report%21%5D%28https%3A%2F%2Fgithub.com%2Fcockroachdb%2Fcockroach%2Ftree%2Fmaster%2Fpkg%2Fcmd%2Finternal%2Fissues%29%0A%3C%2Fsub%3E%0A&title=storage%3A+TestReplicateQueueRebalance+failed
4343
----
4444
----

0 commit comments

Comments
 (0)