Skip to content

Commit

Permalink
roachtest: include link to testeng grafana in issue posts
Browse files Browse the repository at this point in the history
This adds a link, populated with relevant cluster name and test timeframe,
to the testeng grafana instance for failed roachtests.

Fixes: cockroachdb#105894
Release note: None
  • Loading branch information
annrpom committed Aug 3, 2023
1 parent 83089ea commit 350f13f
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 13 deletions.
2 changes: 2 additions & 0 deletions pkg/cmd/roachtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ go_test(
"test_test.go",
],
args = ["-test.timeout=55s"],
data = glob(["testdata/**"]),
embed = [":roachtest_lib"],
deps = [
"//pkg/cmd/internal/issues",
Expand All @@ -91,6 +92,7 @@ go_test(
"//pkg/roachprod/logger",
"//pkg/roachprod/vm",
"//pkg/testutils",
"//pkg/testutils/echotest",
"//pkg/util/quotapool",
"//pkg/util/stop",
"//pkg/util/syncutil",
Expand Down
36 changes: 26 additions & 10 deletions pkg/cmd/roachtest/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ func roachtestPrefix(p string) string {
return "ROACHTEST_" + p
}

// generateHelpCommand creates a HelpCommand for createPostRequest
func generateHelpCommand(
clusterName string, start time.Time, end time.Time,
) func(renderer *issues.Renderer) {
return func(renderer *issues.Renderer) {
issues.HelpCommandAsLink(
"roachtest README",
"https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md",
)(renderer)
issues.HelpCommandAsLink(
"How To Investigate (internal)",
"https://cockroachlabs.atlassian.net/l/c/SSSBr8c7",
)(renderer)
// An empty clusterName corresponds to a cluster creation failure
if clusterName != "" {
issues.HelpCommandAsLink(
"Grafana",
fmt.Sprintf("https://go.crdb.dev/p/roachfana/%s/%d/%d", clusterName, start.UnixMilli(), end.UnixMilli()),
)(renderer)
}
}
}

// postIssueCondition encapsulates a condition that causes issue
// posting to be skipped. The `reason` field contains a textual
// description as to why issue posting was skipped.
Expand Down Expand Up @@ -111,6 +134,7 @@ func (g *githubIssues) createPostRequest(

issueOwner := spec.Owner
issueName := testName
issueClusterName := ""

messagePrefix := ""
// Overrides to shield eng teams from potential flakes
Expand Down Expand Up @@ -178,6 +202,7 @@ func (g *githubIssues) createPostRequest(
// N.B. when Arch is specified, it cannot differ from cluster's arch.
// Hence, we only emit when arch was unspecified.
clusterParams[roachtestPrefix("arch")] = string(g.cluster.arch)
issueClusterName = g.cluster.name
}
}

Expand All @@ -190,16 +215,7 @@ func (g *githubIssues) createPostRequest(
Artifacts: artifacts,
ExtraLabels: labels,
ExtraParams: clusterParams,
HelpCommand: func(renderer *issues.Renderer) {
issues.HelpCommandAsLink(
"roachtest README",
"https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md",
)(renderer)
issues.HelpCommandAsLink(
"How To Investigate (internal)",
"https://cockroachlabs.atlassian.net/l/c/SSSBr8c7",
)(renderer)
},
HelpCommand: generateHelpCommand(issueClusterName, start, end),
}, nil
}

Expand Down
26 changes: 23 additions & 3 deletions pkg/cmd/roachtest/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"context"
"errors"
"fmt"
"path/filepath"
"strings"
"testing"
"time"

"github.com/cockroachdb/cockroach/pkg/cmd/internal/issues"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
Expand All @@ -25,6 +27,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/internal/team"
rperrors "github.com/cockroachdb/cockroach/pkg/roachprod/errors"
"github.com/cockroachdb/cockroach/pkg/roachprod/vm"
"github.com/cockroachdb/cockroach/pkg/testutils/echotest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -103,6 +106,16 @@ func TestShouldPost(t *testing.T) {
}
}

func TestGenerateHelpCommand(t *testing.T) {
start := time.Date(2023, time.July, 21, 16, 34, 3, 817, time.UTC)
end := time.Date(2023, time.July, 21, 16, 42, 13, 137, time.UTC)

r := &issues.Renderer{}
generateHelpCommand("foo-cluster", start, end)(r)

echotest.Require(t, r.String(), filepath.Join("testdata", "help_command.txt"))
}

func TestCreatePostRequest(t *testing.T) {
createFailure := func(ref error) failure {
return failure{squashedErr: ref}
Expand Down Expand Up @@ -173,11 +186,13 @@ func TestCreatePostRequest(t *testing.T) {
}

ti := &testImpl{
spec: testSpec,
l: nilLogger(),
spec: testSpec,
l: nilLogger(),
start: time.Date(2023, time.July, 21, 16, 34, 3, 817, time.UTC),
end: time.Date(2023, time.July, 21, 16, 42, 13, 137, time.UTC),
}

testClusterImpl := &clusterImpl{spec: clusterSpec, arch: vm.ArchAMD64}
testClusterImpl := &clusterImpl{spec: clusterSpec, arch: vm.ArchAMD64, name: "foo"}
vo := vm.DefaultCreateOpts()
vmOpts := &vo

Expand Down Expand Up @@ -209,6 +224,11 @@ func TestCreatePostRequest(t *testing.T) {
req, err := github.createPostRequest("github_test", ti.start, ti.end, testSpec, c.failure, "message")
assert.NoError(t, err, "Expected no error in createPostRequest")

r := &issues.Renderer{}
req.HelpCommand(r)
file := fmt.Sprintf("help_command_createpost_%d.txt", idx+1)
echotest.Require(t, r.String(), filepath.Join("testdata", file))

if c.expectedParams != nil {
require.Equal(t, c.expectedParams, req.ExtraParams)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/cmd/roachtest/testdata/help_command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
echo
----
----


See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)



See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)



See: [Grafana](https://go.crdb.dev/p/roachfana/foo-cluster/1689957243000/1689957733000)

----
----
17 changes: 17 additions & 0 deletions pkg/cmd/roachtest/testdata/help_command_createpost_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
echo
----
----


See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)



See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)



See: [Grafana](https://go.crdb.dev/p/roachfana/foo/1689957243000/1689957733000)

----
----
13 changes: 13 additions & 0 deletions pkg/cmd/roachtest/testdata/help_command_createpost_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo
----
----


See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)



See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)

----
----
13 changes: 13 additions & 0 deletions pkg/cmd/roachtest/testdata/help_command_createpost_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo
----
----


See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)



See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)

----
----
17 changes: 17 additions & 0 deletions pkg/cmd/roachtest/testdata/help_command_createpost_5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
echo
----
----


See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)



See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)



See: [Grafana](https://go.crdb.dev/p/roachfana/foo/1689957243000/1689957733000)

----
----

0 comments on commit 350f13f

Please sign in to comment.