forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/util/debugutil: introduce debug.Stack() wrapper
Until now, all stack traces were treated as untyped strings and hence redacted. Stack traces don't need to be redacted. Because they don't contain any PII. This commit introduces a new function, Stack(), in the debugutil package as a replacement for the standard debug.Stack(). The new function wraps the stack trace contents in a []byte-aliased type "SafeStack" that implements the SafeValue interface, ensuring it is not redacted. This function can be used as a drop-in replacement for debug.Stack(). Part of: CRDB-15292 Epic: CRDB-37533 Release note: None
- Loading branch information
1 parent
683618f
commit 5d83c6c
Showing
5 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "debugutil", | ||
srcs = ["debugutil.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/util/debugutil", | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_github_elastic_gosigar//:gosigar"], | ||
deps = [ | ||
"@com_github_cockroachdb_redact//:redact", | ||
"@com_github_cockroachdb_redact//interfaces", | ||
"@com_github_elastic_gosigar//:gosigar", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "debugutil_test", | ||
srcs = ["debugutil_test.go"], | ||
embed = [":debugutil"], | ||
deps = [ | ||
"@com_github_cockroachdb_redact//:redact", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the CockroachDB Software License | ||
// included in the /LICENSE file. | ||
|
||
package debugutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/redact" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStack(t *testing.T) { | ||
var buf redact.StringBuilder | ||
buf.Print(Stack()) | ||
buf.Printf("%s", Stack()) | ||
buf.Printf("%v", Stack()) | ||
out := buf.RedactableString() | ||
|
||
require.NotContains(t, out, "‹") | ||
require.NotContains(t, out, "›") | ||
} |