diff --git a/pkg/util/allstacks/BUILD.bazel b/pkg/util/allstacks/BUILD.bazel index 44af32d43d24..449fc97d14e0 100644 --- a/pkg/util/allstacks/BUILD.bazel +++ b/pkg/util/allstacks/BUILD.bazel @@ -5,4 +5,5 @@ go_library( srcs = ["allstacks.go"], importpath = "github.com/cockroachdb/cockroach/pkg/util/allstacks", visibility = ["//visibility:public"], + deps = ["//pkg/util/debugutil"], ) diff --git a/pkg/util/allstacks/allstacks.go b/pkg/util/allstacks/allstacks.go index 367bc3287ed4..1ae61c261246 100644 --- a/pkg/util/allstacks/allstacks.go +++ b/pkg/util/allstacks/allstacks.go @@ -5,18 +5,22 @@ package allstacks -import "runtime" +import ( + "runtime" + + "github.com/cockroachdb/cockroach/pkg/util/debugutil" +) // Get returns all stacks, except if that takes more than 512mb of memory, in // which case it returns only 512mb worth of stacks (clipping the last stack // if necessary). -func Get() []byte { +func Get() debugutil.SafeStack { return GetWithBuf(nil) } // GetWithBuf is like Get, but tries to use the provided slice first, allocating // a new, larger, slice only if necessary. -func GetWithBuf(buf []byte) []byte { +func GetWithBuf(buf []byte) debugutil.SafeStack { buf = buf[:cap(buf)] // We don't know how big the traces are, so grow a few times if they don't // fit. Start large, though. diff --git a/pkg/util/debugutil/debugutil.go b/pkg/util/debugutil/debugutil.go index effc8fa1b79a..11d7541eb2e6 100644 --- a/pkg/util/debugutil/debugutil.go +++ b/pkg/util/debugutil/debugutil.go @@ -45,6 +45,9 @@ func init() { }(os.Getppid())) } +// SafeStack is an alias for []byte that handles redaction. Use this type +// instead of []byte when you are sure that the stack trace does not contain +// sensitive information. type SafeStack []byte func (s SafeStack) SafeValue() {}