diff --git a/pkg/kv/kvpb/api.go b/pkg/kv/kvpb/api.go index 2fd1b9cf1060..79f3f39cb3b7 100644 --- a/pkg/kv/kvpb/api.go +++ b/pkg/kv/kvpb/api.go @@ -194,6 +194,33 @@ type Request interface { flags() flag } +// SafeFormatterRequest is an optional extension interface used to allow request to do custom formatting. +type SafeFormatterRequest interface { + Request + redact.SafeFormatter +} + +var _ SafeFormatterRequest = (*GetRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (gr GetRequest) SafeFormat(s redact.SafePrinter, _ rune) { + s.Printf("[lockStrength=%s lockingDurability=%s]", gr.KeyLockingStrength, gr.KeyLockingDurability) +} + +var _ SafeFormatterRequest = (*ScanRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (sr ScanRequest) SafeFormat(s redact.SafePrinter, _ rune) { + s.Printf("[lockStrength=%s lockingDurability=%s]", sr.KeyLockingStrength, sr.KeyLockingDurability) +} + +var _ SafeFormatterRequest = (*ReverseScanRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (rsr ReverseScanRequest) SafeFormat(s redact.SafePrinter, _ rune) { + s.Printf("[lockStrength=%s lockingDurability=%s]", rsr.KeyLockingStrength, rsr.KeyLockingDurability) +} + // LockingReadRequest is an interface used to expose the key-level locking // strength of a read-only request. type LockingReadRequest interface { diff --git a/pkg/kv/kvpb/batch.go b/pkg/kv/kvpb/batch.go index 4f57063274d6..1e7a08a7fb91 100644 --- a/pkg/kv/kvpb/batch.go +++ b/pkg/kv/kvpb/batch.go @@ -795,7 +795,7 @@ func (ba BatchRequest) Split(canSplitET bool) [][]RequestUnion { // SafeFormat implements redact.SafeFormatter. // It gives a brief summary of the contained requests and keys in the batch. -func (ba BatchRequest) SafeFormat(s redact.SafePrinter, _ rune) { +func (ba BatchRequest) SafeFormat(s redact.SafePrinter, verb rune) { for count, arg := range ba.Requests { // Limit the strings to provide just a summary. Without this limit // a log message with a BatchRequest can be very long. @@ -845,6 +845,9 @@ func (ba BatchRequest) SafeFormat(s redact.SafePrinter, _ rune) { s.Print(req.Method()) } s.Printf(" [%s,%s)", h.Key, h.EndKey) + if safeFormatterReq, ok := req.(SafeFormatterRequest); ok { + safeFormatterReq.SafeFormat(s, verb) + } } } {