Skip to content

Commit

Permalink
kvflowcontrol: fix Tokens type redaction
Browse files Browse the repository at this point in the history
The strings inside Tokens.SafeFormat() were not marked as safe, and
caused the value being printed as redactable.

Epic: none
Release note: none
  • Loading branch information
pav-kv committed Dec 19, 2024
1 parent 76ed91e commit 205fb8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvflowcontrol/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ go_library(
"//pkg/settings/cluster",
"//pkg/util/admission/admissionpb",
"//pkg/util/ctxutil",
"//pkg/util/humanizeutil",
"@com_github_cockroachdb_redact//:redact",
"@com_github_dustin_go_humanize//:go-humanize",
],
)
11 changes: 5 additions & 6 deletions pkg/kv/kvserver/kvflowcontrol/kvflowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/ctxutil"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/cockroachdb/redact"
"github.com/dustin/go-humanize"
)

// Enabled determines whether we use flow control for replication traffic in KV.
Expand Down Expand Up @@ -415,13 +415,12 @@ func (t Tokens) String() string {
}

// SafeFormat implements the redact.SafeFormatter interface.
func (t Tokens) SafeFormat(p redact.SafePrinter, verb rune) {
sign := "+"
func (t Tokens) SafeFormat(p redact.SafePrinter, _ rune) {
if t < 0 {
sign = "-"
t = -t
p.SafeString(humanizeutil.IBytes(int64(t)))
return
}
p.Printf("%s%s", sign, humanize.IBytes(uint64(t)))
p.Printf("+%s", humanizeutil.IBytes(int64(t)))
}

func (s Stream) String() string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/kvflowcontrol/replica_rac2/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ func (p *processorImpl) AdmitRaftEntriesRaftMuLocked(ctx context.Context, e rac2
if isV2Encoding {
log.Infof(ctx,
"decoded v2 raft admission meta below-raft: pri=%v create-time=%d "+
"proposer=n%v receiver=[n%d,s%v] tenant=t%d tokens≈%d "+
"proposer=n%v receiver=[n%d,s%v] tenant=t%d tokens≈%v "+
"sideloaded=%t raft-entry=%d/%d lead-v2=%v",
raftpb.Priority(meta.AdmissionPriority),
meta.AdmissionCreateTime,
Expand All @@ -939,7 +939,7 @@ func (p *processorImpl) AdmitRaftEntriesRaftMuLocked(ctx context.Context, e rac2
} else {
log.Infof(ctx,
"decoded v1 raft admission meta below-raft: pri=%v create-time=%d "+
"proposer=n%v receiver=[n%d,s%v] tenant=t%d tokens≈%d "+
"proposer=n%v receiver=[n%d,s%v] tenant=t%d tokens≈%v "+
"sideloaded=%t raft-entry=%d/%d lead-v2=%v",
admissionpb.WorkPriority(meta.AdmissionPriority),
meta.AdmissionCreateTime,
Expand Down

0 comments on commit 205fb8e

Please sign in to comment.