Skip to content

Commit

Permalink
*: fix redact log (#8415) (#8571)
Browse files Browse the repository at this point in the history
close #8419

Signed-off-by: ti-chi-bot <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ryan Leung <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 5231919 commit 7904d55
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/storage/kv"
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -262,7 +263,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32) error {
}
log.Info("[keyspace] added region label for keyspace",
zap.Uint32("keyspaceID", id),
zap.Any("LabelRule", keyspaceRule),
logutil.ZapRedactString("label-rule", keyspaceRule.String()),
)
return nil
}
Expand Down
47 changes: 47 additions & 0 deletions pkg/schedule/labeler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package labeler
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
"strings"
"time"

"github.com/pingcap/failpoint"
Expand All @@ -37,6 +39,10 @@ type RegionLabel struct {
expire *time.Time
}

func (l *RegionLabel) String() string {
return fmt.Sprintf("key: %s, value: %s", l.Key, l.Value)
}

// LabelRule is the rule to assign labels to a region.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type LabelRule struct {
Expand All @@ -48,6 +54,47 @@ type LabelRule struct {
minExpire *time.Time
}

func (rule *LabelRule) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("id: %s, index: %d, type: %s", rule.ID, rule.Index, rule.RuleType))
b.WriteString(", labels: ")
for i, l := range rule.Labels {
if i == 0 {
b.WriteString("[")
}
b.WriteString(l.String())
if i == len(rule.Labels)-1 {
b.WriteString("]")
} else {
b.WriteString(", ")
}
}
b.WriteString(", data: ")
ranges := rule.Data.([]*KeyRangeRule)
for i, r := range ranges {
if i == 0 {
b.WriteString("[")
}
b.WriteString(fmt.Sprintf("startKey: {%s}, endKey: {%s}", r.StartKeyHex, r.EndKeyHex))
if i == len(ranges)-1 {
b.WriteString("]")
} else {
b.WriteString(", ")
}
}
return b.String()
}

// NewLabelRuleFromJSON creates a label rule from the JSON data.
func NewLabelRuleFromJSON(data []byte) (*LabelRule, error) {
lr := &LabelRule{}
err := json.Unmarshal(data, lr)
if err != nil {
return nil, err
}
return lr, nil
}

const (
// KeyRange is the rule type that specifies a list of key ranges.
KeyRange = "key-range"
Expand Down
4 changes: 2 additions & 2 deletions server/cluster/cluster_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (c *RaftCluster) HandleBatchReportSplit(request *pdpb.ReportBatchSplitReque
err := c.checkSplitRegions(regions)
if err != nil {
log.Warn("report batch split region is invalid",
zap.Stringer("region-meta", hrm),
logutil.ZapRedactStringer("region-meta", hrm),
errs.ZapError(err))
return nil, err
}
Expand All @@ -236,7 +236,7 @@ func (c *RaftCluster) HandleBatchReportSplit(request *pdpb.ReportBatchSplitReque
hrm = core.RegionsToHexMeta(regions[:last])
log.Info("region batch split, generate new regions",
zap.Uint64("region-id", originRegion.GetId()),
zap.Stringer("origin", hrm),
logutil.ZapRedactStringer("origin", hrm),
zap.Int("total", last))
return &pdpb.ReportBatchSplitResponse{}, nil
}
Expand Down

0 comments on commit 7904d55

Please sign in to comment.