Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix redact log #8415

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/storage/kv"
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -333,7 +334,7 @@
if waitRegionSplit {
ranges := keyspaceRule.Data.([]*labeler.KeyRangeRule)
if len(ranges) < 2 {
log.Warn("[keyspace] failed to split keyspace region with insufficient range", zap.Any("label-rule", keyspaceRule))
log.Warn("[keyspace] failed to split keyspace region with insufficient range", logutil.ZapRedactString("label-rule", keyspaceRule.String()))

Check warning on line 337 in pkg/keyspace/keyspace.go

View check run for this annotation

Codecov / codecov/patch

pkg/keyspace/keyspace.go#L337

Added line #L337 was not covered by tests
return ErrRegionSplitFailed
}
rawLeftBound, rawRightBound := ranges[0].StartKey, ranges[0].EndKey
Expand Down Expand Up @@ -382,7 +383,7 @@

log.Info("[keyspace] added region label for keyspace",
zap.Uint32("keyspace-id", id),
zap.Any("label-rule", keyspaceRule),
logutil.ZapRedactString("label-rule", keyspaceRule.String()),
zap.Duration("takes", time.Since(start)),
)
return
Expand Down
39 changes: 39 additions & 0 deletions pkg/schedule/labeler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"encoding/json"
"fmt"
"reflect"
"strings"
"time"

"github.com/pingcap/failpoint"
Expand All @@ -38,6 +39,10 @@
expire *time.Time
}

func (l *RegionLabel) String() string {
return fmt.Sprintf("key: %s, value: %s", l.Key, l.Value)
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 @@ -49,6 +54,36 @@
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("]")
}
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{}
Expand Down Expand Up @@ -78,6 +113,10 @@
EndKeyHex string `json:"end_key"` // hex format end key, for marshal/unmarshal
}

func (r *KeyRangeRule) String() string {
return fmt.Sprintf("startKey: %s, endKey: %s", r.StartKeyHex, r.EndKeyHex)

Check warning on line 117 in pkg/schedule/labeler/rules.go

View check run for this annotation

Codecov / codecov/patch

pkg/schedule/labeler/rules.go#L116-L117

Added lines #L116 - L117 were not covered by tests
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
}

// LabelRulePatch is the patch to update the label rules.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type LabelRulePatch struct {
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 @@ -238,7 +238,7 @@
err := checkSplitRegions(regions)
if err != nil {
log.Warn("report batch split region is invalid",
zap.Stringer("region-meta", hrm),
logutil.ZapRedactStringer("region-meta", hrm),

Check warning on line 241 in server/cluster/cluster_worker.go

View check run for this annotation

Codecov / codecov/patch

server/cluster/cluster_worker.go#L241

Added line #L241 was not covered by tests
errs.ZapError(err))
return nil, err
}
Expand All @@ -247,7 +247,7 @@
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