From 406ac73e78ba1c1c30863346a766064874ee5e06 Mon Sep 17 00:00:00 2001 From: Renato Costa Date: Tue, 13 Jun 2023 16:00:24 -0400 Subject: [PATCH] logic: keep cockroach-go logs in case of failure This commit makes use of the new `CockroachLogsDirOpt` option introduced in [1] to pass a custom directory where cockroach logs will be stored. This directory is relative to TMPDIR, which is part of the artifacts path when the test runs in CI. With this change, when a logic test using the cockroach-go config fails, we'll be able to see both the test logs as well as the cockroach logs themselves. The latter will be in the `cockroach.stderr` file. [1] https://github.com/cockroachdb/cockroach-go/pull/170 Epic: none Release note: None --- DEPS.bzl | 6 +++--- build/bazelutil/distdir_files.bzl | 2 +- go.mod | 2 +- go.sum | 4 ++-- pkg/sql/logictest/logic.go | 19 +++++++++++++++++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 8ae23f702a4e..503e614d200f 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -1482,10 +1482,10 @@ def go_deps(): name = "com_github_cockroachdb_cockroach_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/cockroachdb/cockroach-go/v2", - sha256 = "25ae716dc921dce8336555cbc52b98243b8f1e5e33716afcd351cfd9c2538777", - strip_prefix = "github.com/cockroachdb/cockroach-go/v2@v2.3.3", + sha256 = "70860a2615f3df73f7d00b4801b1fffe30a3306ae1cda1e9bf5245bb74e86d9a", + strip_prefix = "github.com/cockroachdb/cockroach-go/v2@v2.3.5", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/cockroach-go/v2/com_github_cockroachdb_cockroach_go_v2-v2.3.3.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/cockroach-go/v2/com_github_cockroachdb_cockroach_go_v2-v2.3.5.zip", ], ) go_repository( diff --git a/build/bazelutil/distdir_files.bzl b/build/bazelutil/distdir_files.bzl index 57bce652909d..e770c9dd2f2d 100644 --- a/build/bazelutil/distdir_files.bzl +++ b/build/bazelutil/distdir_files.bzl @@ -306,7 +306,7 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/bubbletea/com_github_cockroachdb_bubbletea-v0.23.1-bracketed-paste2.zip": "d7916a0e7d8d814566e8f8d162c3764aea947296396a0a669564ff3ee53414bc", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/circuitbreaker/com_github_cockroachdb_circuitbreaker-v2.2.2-0.20190114160014-a614b14ccf63+incompatible.zip": "52fdb5ba6a60e9a2f1db42d5b3c4c13cc5bb3947d5ce7f1bba9b0a14de71813a", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/cmux/com_github_cockroachdb_cmux-v0.0.0-20170110192607-30d10be49292.zip": "88f6f9cf33eb535658540b46f6222f029398e590a3ff9cc873d7d561ac6debf0", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/cockroach-go/v2/com_github_cockroachdb_cockroach_go_v2-v2.3.3.zip": "25ae716dc921dce8336555cbc52b98243b8f1e5e33716afcd351cfd9c2538777", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/cockroach-go/v2/com_github_cockroachdb_cockroach_go_v2-v2.3.5.zip": "70860a2615f3df73f7d00b4801b1fffe30a3306ae1cda1e9bf5245bb74e86d9a", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/crlfmt/com_github_cockroachdb_crlfmt-v0.0.0-20221214225007-b2fc5c302548.zip": "fedc01bdd6d964da0425d5eaac8efadc951e78e13f102292cc0774197f09ab63", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/datadriven/com_github_cockroachdb_datadriven-v1.0.3-0.20230413201302-be42291fc80f.zip": "f6de9c180e1ea80c602d98247b8e8fe89f491648ab1425417b9aca082697cbc0", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/errors/com_github_cockroachdb_errors-v1.9.1.zip": "eeec411c969fb66b63af83527677cb84cceb50ed5003c51209e6bd76f1103a0b", diff --git a/go.mod b/go.mod index 6f68520028b3..c27307e5980e 100644 --- a/go.mod +++ b/go.mod @@ -109,7 +109,7 @@ require ( github.com/cockroachdb/apd/v3 v3.2.0 github.com/cockroachdb/circuitbreaker v2.2.2-0.20190114160014-a614b14ccf63+incompatible github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292 - github.com/cockroachdb/cockroach-go/v2 v2.3.3 + github.com/cockroachdb/cockroach-go/v2 v2.3.5 github.com/cockroachdb/crlfmt v0.0.0-20221214225007-b2fc5c302548 github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f github.com/cockroachdb/errors v1.9.1 diff --git a/go.sum b/go.sum index f1ef2f6f025a..8b82c833d38d 100644 --- a/go.sum +++ b/go.sum @@ -469,8 +469,8 @@ github.com/cockroachdb/circuitbreaker v2.2.2-0.20190114160014-a614b14ccf63+incom github.com/cockroachdb/circuitbreaker v2.2.2-0.20190114160014-a614b14ccf63+incompatible/go.mod h1:v3T8+rm/HmCL0D1BwDcGaHHAQDuFPW7EsnYs2nBRqUo= github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292 h1:dzj1/xcivGjNPwwifh/dWTczkwcuqsXXFHY1X/TZMtw= github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4= -github.com/cockroachdb/cockroach-go/v2 v2.3.3 h1:fNmtG6XhoA1DhdDCIu66YyGSsNb1szj4CaAsbDxRmy4= -github.com/cockroachdb/cockroach-go/v2 v2.3.3/go.mod h1:1wNJ45eSXW9AnOc3skntW9ZUZz6gxrQK3cOj3rK+BC8= +github.com/cockroachdb/cockroach-go/v2 v2.3.5 h1:Khtm8K6fTTz/ZCWPzU9Ne3aOW9VyAnj4qIPCJgKtwK0= +github.com/cockroachdb/cockroach-go/v2 v2.3.5/go.mod h1:1wNJ45eSXW9AnOc3skntW9ZUZz6gxrQK3cOj3rK+BC8= github.com/cockroachdb/crlfmt v0.0.0-20221214225007-b2fc5c302548 h1:i0bnjanlWAvM50wHMT7EFyxlt5HQusznWrkwl+HBIsU= github.com/cockroachdb/crlfmt v0.0.0-20221214225007-b2fc5c302548/go.mod h1:qtkxNlt5i3rrdirfJE/bQeW/IeLajKexErv7jEIV+Uc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index 171d47bc5f19..dd8878310695 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -1254,7 +1254,19 @@ var _ = ((*logicTest)(nil)).newTestServerCluster // bootstrapBinaryPath is given by the config's CockroachGoBootstrapVersion. // upgradeBinaryPath is given by the config's CockroachGoUpgradeVersion, or // is the locally built version if CockroachGoUpgradeVersion was not specified. -func (t *logicTest) newTestServerCluster(bootstrapBinaryPath string, upgradeBinaryPath string) { +func (t *logicTest) newTestServerCluster(bootstrapBinaryPath, upgradeBinaryPath string) func() { + logsDir, err := os.MkdirTemp("", "cockroach-logs*") + if err != nil { + t.Fatal(err) + } + cleanupFunc := func() { + if t.rootT.Failed() { + fmt.Fprintf(os.Stderr, "cockroach logs captured in: %s\n", logsDir) + } else { + _ = os.RemoveAll(logsDir) + } + } + // During config initialization, NumNodes is required to be 3. opts := []testserver.TestServerOpt{ testserver.ThreeNodeOpt(), @@ -1262,6 +1274,7 @@ func (t *logicTest) newTestServerCluster(bootstrapBinaryPath string, upgradeBina testserver.CockroachBinaryPathOpt(bootstrapBinaryPath), testserver.UpgradeCockroachBinaryPathOpt(upgradeBinaryPath), testserver.PollListenURLTimeoutOpt(120), + testserver.CockroachLogsDirOpt(logsDir), } if strings.Contains(upgradeBinaryPath, "cockroach-short") { // If we're using a cockroach-short binary, that means it was @@ -1287,6 +1300,7 @@ func (t *logicTest) newTestServerCluster(bootstrapBinaryPath string, upgradeBina t.clusterCleanupFuncs = append(t.clusterCleanupFuncs, ts.Stop) t.setUser(username.RootUser, 0 /* nodeIdx */) + return cleanupFunc } // newCluster creates a new cluster. It should be called after the logic tests's @@ -1862,7 +1876,8 @@ func (t *logicTest) setup( if !found { t.Fatal(errors.New("cockroach binary not found")) } - t.newTestServerCluster(bootstrapBinaryPath, upgradeBinaryPath) + cleanupTestCluster := t.newTestServerCluster(bootstrapBinaryPath, upgradeBinaryPath) + t.testCleanupFuncs = append(t.testCleanupFuncs, cleanupTestCluster) } else { t.newCluster(serverArgs, t.clusterOpts, t.knobOpts, t.toa) }