Skip to content

Commit

Permalink
Merge #134617
Browse files Browse the repository at this point in the history
134617: kvprober: unredact leaseholder information in kvprober logs r=dhartunian a=VishalJaishankar

Previously, this is the log line seeing in datadog `...r=393210 having likely leaseholder=‹×› returned success...`

The leaseholder info is not a PII and does not serve any purpose if redacted

This PR makes it redact safe.

Epic: none

Release note: None

Co-authored-by: Vishal Jaishankar <[email protected]>
  • Loading branch information
craig[bot] and VishalJaishankar committed Dec 23, 2024
2 parents b63a736 + 17ae278 commit bea204f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/kv/kvprober/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//pkg/util/tracing/tracingpb",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_logtags//:logtags",
"@com_github_cockroachdb_redact//:redact",
],
)

Expand Down
5 changes: 3 additions & 2 deletions pkg/kv/kvprober/kvprober.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/logtags"
"github.com/cockroachdb/redact"
)

const putValue = "thekvproberwrotethis"
Expand Down Expand Up @@ -533,7 +534,7 @@ func (p *Prober) quarantineProbe(ctx context.Context, pl planner) {
// log messages indicating leaseholder information, extracts leaseholder
// node ID, and returns this information. Returns an empty string if
// leaseholder information is not found.
func (p *Prober) returnLeaseholderInfo(recording tracingpb.Recording) string {
func (p *Prober) returnLeaseholderInfo(recording tracingpb.Recording) redact.SafeString {
// The leaseholder is determined by the kvclient in dist_sender.go,
// which decides the node to handle the request and sends it. The log
// entry with "node received request" shows the leaseholder acknowledging
Expand All @@ -551,7 +552,7 @@ func (p *Prober) returnLeaseholderInfo(recording tracingpb.Recording) string {
leaseholder := leaseRegex.FindStringSubmatch(informationLog)
// Return leaseholder node ID if found.
if len(leaseholder) == 2 {
return leaseholder[1]
return redact.SafeString(leaseholder[1])
}
}
return ""
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvprober/kvprober_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestReturnLeaseholderInfo(t *testing.T) {
m := &mock{t: t, read: true}
p := initTestProber(ctx, m)
// Expected leaseholder information is node 1.
require.Equal(t, "1", p.returnLeaseholderInfo(mockRecording))
require.Equal(t, "1", string(p.returnLeaseholderInfo(mockRecording)))
})

t.Run("traces do not contain leaseholder information", func(t *testing.T) {
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestReturnLeaseholderInfo(t *testing.T) {
m := &mock{t: t, read: true}
p := initTestProber(ctx, m)
// Since no leaseholder information is present, the function is expected to return an empty string.
require.Equal(t, "", p.returnLeaseholderInfo(mockRecording))
require.Equal(t, "", string(p.returnLeaseholderInfo(mockRecording)))
})
}

Expand Down

0 comments on commit bea204f

Please sign in to comment.