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

errs: remove redundant FastGenWithCause in ZapError (#7497) #7545

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion client/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
ErrClientGetMultiResponse = errors.Normalize("get invalid value response %v, must only one", errors.RFCCodeText("PD:client:ErrClientGetMultiResponse"))
ErrClientGetServingEndpoint = errors.Normalize("get serving endpoint failed", errors.RFCCodeText("PD:client:ErrClientGetServingEndpoint"))
ErrClientFindGroupByKeyspaceID = errors.Normalize("can't find keyspace group by keyspace id", errors.RFCCodeText("PD:client:ErrClientFindGroupByKeyspaceID"))
ErrClientWatchGCSafePointV2Stream = errors.Normalize("watch gc safe point v2 stream failed, %s", errors.RFCCodeText("PD:client:ErrClientWatchGCSafePointV2Stream"))
ErrClientWatchGCSafePointV2Stream = errors.Normalize("watch gc safe point v2 stream failed", errors.RFCCodeText("PD:client:ErrClientWatchGCSafePointV2Stream"))
)

// grpcutil errors
Expand Down
2 changes: 1 addition & 1 deletion client/errs/errs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ZapError(err error, causeError ...error) zap.Field {
}
if e, ok := err.(*errors.Error); ok {
if len(causeError) >= 1 {
err = e.Wrap(causeError[0]).FastGenWithCause()
err = e.Wrap(causeError[0])
} else {
err = e.FastGenByArgs()
}
Expand Down
6 changes: 3 additions & 3 deletions client/tso_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ tsoBatchLoop:
} else {
log.Error("[tso] fetch pending tso requests error",
zap.String("dc-location", dc),
errs.ZapError(errs.ErrClientGetTSO.FastGenByArgs("when fetch pending tso requests"), err))
errs.ZapError(errs.ErrClientGetTSO, err))
}
return
}
Expand Down Expand Up @@ -490,10 +490,10 @@ tsoBatchLoop:
default:
}
c.svcDiscovery.ScheduleCheckMemberChanged()
log.Error("[tso] getTS error",
log.Error("[tso] getTS error after processing requests",
zap.String("dc-location", dc),
zap.String("stream-addr", streamAddr),
errs.ZapError(errs.ErrClientGetTSO.FastGenByArgs("after processing requests"), err))
errs.ZapError(errs.ErrClientGetTSO, err))
// Set `stream` to nil and remove this stream from the `connectionCtxs` due to error.
connectionCtxs.Delete(streamAddr)
cancel()
Expand Down
2 changes: 1 addition & 1 deletion errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ get min TSO failed, %v

["PD:client:ErrClientGetTSO"]
error = '''
get TSO failed, %v
get TSO failed
'''

["PD:client:ErrClientGetTSOTimeout"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoscaling/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (prom *PrometheusQuerier) queryMetricsFromPrometheus(query string, timestam
resp, warnings, err := prom.api.Query(ctx, query, timestamp)

if err != nil {
return nil, errs.ErrPrometheusQuery.Wrap(err).FastGenWithCause()
return nil, errs.ErrPrometheusQuery.Wrap(err)
}

if len(warnings) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var (
var (
ErrClientCreateTSOStream = errors.Normalize("create TSO stream failed, %s", errors.RFCCodeText("PD:client:ErrClientCreateTSOStream"))
ErrClientGetTSOTimeout = errors.Normalize("get TSO timeout", errors.RFCCodeText("PD:client:ErrClientGetTSOTimeout"))
ErrClientGetTSO = errors.Normalize("get TSO failed, %v", errors.RFCCodeText("PD:client:ErrClientGetTSO"))
ErrClientGetTSO = errors.Normalize("get TSO failed", errors.RFCCodeText("PD:client:ErrClientGetTSO"))
ErrClientGetLeader = errors.Normalize("get leader failed, %v", errors.RFCCodeText("PD:client:ErrClientGetLeader"))
ErrClientGetMember = errors.Normalize("get member failed", errors.RFCCodeText("PD:client:ErrClientGetMember"))
ErrClientGetMinTSO = errors.Normalize("get min TSO failed, %v", errors.RFCCodeText("PD:client:ErrClientGetMinTSO"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/errs/errs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ZapError(err error, causeError ...error) zap.Field {
}
if e, ok := err.(*errors.Error); ok {
if len(causeError) >= 1 {
err = e.Wrap(causeError[0]).FastGenWithCause()
err = e.Wrap(causeError[0])
} else {
err = e.FastGenByArgs()
}
Expand Down
35 changes: 25 additions & 10 deletions pkg/errs/errs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ func TestError(t *testing.T) {
log.Error("test", zap.Error(ErrEtcdLeaderNotFound.FastGenByArgs()))
re.Contains(lg.Message(), rfc)
err := errors.New("test error")
log.Error("test", ZapError(ErrEtcdLeaderNotFound, err))
rfc = `[error="[PD:member:ErrEtcdLeaderNotFound]test error`
re.Contains(lg.Message(), rfc)
// use Info() because of no stack for comparing.
log.Info("test", ZapError(ErrEtcdLeaderNotFound, err))
rfc = `[error="[PD:member:ErrEtcdLeaderNotFound]etcd leader not found: test error`
m1 := lg.Message()
re.Contains(m1, rfc)
log.Info("test", zap.Error(ErrEtcdLeaderNotFound.Wrap(err)))
m2 := lg.Message()
idx1 := strings.Index(m1, "[error")
idx2 := strings.Index(m2, "[error")
re.Equal(m1[idx1:], m2[idx2:])
log.Info("test", zap.Error(ErrEtcdLeaderNotFound.Wrap(err).FastGenWithCause()))
m3 := lg.Message()
re.NotContains(m3, rfc)
}

func TestErrorEqual(t *testing.T) {
Expand All @@ -94,24 +104,24 @@ func TestErrorEqual(t *testing.T) {
re.True(errors.ErrorEqual(err1, err2))

err := errors.New("test")
err1 = ErrSchedulerNotFound.Wrap(err).FastGenWithCause()
err2 = ErrSchedulerNotFound.Wrap(err).FastGenWithCause()
err1 = ErrSchedulerNotFound.Wrap(err)
err2 = ErrSchedulerNotFound.Wrap(err)
re.True(errors.ErrorEqual(err1, err2))

err1 = ErrSchedulerNotFound.FastGenByArgs()
err2 = ErrSchedulerNotFound.Wrap(err).FastGenWithCause()
err2 = ErrSchedulerNotFound.Wrap(err)
re.False(errors.ErrorEqual(err1, err2))

err3 := errors.New("test")
err4 := errors.New("test")
err1 = ErrSchedulerNotFound.Wrap(err3).FastGenWithCause()
err2 = ErrSchedulerNotFound.Wrap(err4).FastGenWithCause()
err1 = ErrSchedulerNotFound.Wrap(err3)
err2 = ErrSchedulerNotFound.Wrap(err4)
re.True(errors.ErrorEqual(err1, err2))

err3 = errors.New("test1")
err4 = errors.New("test")
err1 = ErrSchedulerNotFound.Wrap(err3).FastGenWithCause()
err2 = ErrSchedulerNotFound.Wrap(err4).FastGenWithCause()
err1 = ErrSchedulerNotFound.Wrap(err3)
err2 = ErrSchedulerNotFound.Wrap(err4)
re.False(errors.ErrorEqual(err1, err2))
}

Expand All @@ -135,11 +145,16 @@ func TestErrorWithStack(t *testing.T) {
m1 := lg.Message()
log.Error("test", zap.Error(errors.WithStack(err)))
m2 := lg.Message()
log.Error("test", ZapError(ErrStrconvParseInt.GenWithStackByCause(), err))
m3 := lg.Message()
// This test is based on line number and the first log is in line 141, the second is in line 142.
// So they have the same length stack. Move this test to another place need to change the corresponding length.
idx1 := strings.Index(m1, "[stack=")
re.GreaterOrEqual(idx1, -1)
idx2 := strings.Index(m2, "[stack=")
re.GreaterOrEqual(idx2, -1)
idx3 := strings.Index(m3, "[stack=")
re.GreaterOrEqual(idx3, -1)
re.Len(m2[idx2:], len(m1[idx1:]))
re.Len(m3[idx3:], len(m1[idx1:]))
}
2 changes: 1 addition & 1 deletion pkg/schedule/hbstream/heartbeat_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *HeartbeatStreams) run() {
if stream, ok := s.streams[storeID]; ok {
if err := stream.Send(msg); err != nil {
log.Error("send heartbeat message fail",
zap.Uint64("region-id", msg.GetRegionId()), errs.ZapError(errs.ErrGRPCSend.Wrap(err).GenWithStackByArgs()))
zap.Uint64("region-id", msg.GetRegionId()), errs.ZapError(errs.ErrGRPCSend, err))
delete(s.streams, storeID)
heartbeatStreamCounter.WithLabelValues(storeAddress, storeLabel, "push", "err").Inc()
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/schedule/plugin_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ func (p *PluginInterface) GetFunction(path string, funcName string) (plugin.Symb
// open plugin
filePath, err := filepath.Abs(path)
if err != nil {
return nil, errs.ErrFilePathAbs.Wrap(err).FastGenWithCause()
return nil, errs.ErrFilePathAbs.Wrap(err)
}
log.Info("open plugin file", zap.String("file-path", filePath))
plugin, err := plugin.Open(filePath)
if err != nil {
return nil, errs.ErrLoadPlugin.Wrap(err).FastGenWithCause()
return nil, errs.ErrLoadPlugin.Wrap(err)
}
p.pluginMap[path] = plugin
}
// get func from plugin
f, err := p.pluginMap[path].Lookup(funcName)
if err != nil {
return nil, errs.ErrLookupPluginFunc.Wrap(err).FastGenWithCause()
return nil, errs.ErrLookupPluginFunc.Wrap(err)
}
return f, nil
}
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (conf *evictLeaderSchedulerConfig) BuildWithArgs(args []string) error {

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}
ranges, err := getKeyRanges(args[1:])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (conf *grantLeaderSchedulerConfig) BuildWithArgs(args []string) error {

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}
ranges, err := getKeyRanges(args[1:])
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/schedule/schedulers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func schedulersRegister() {

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}

ranges, err := getKeyRanges(args[1:])
Expand Down Expand Up @@ -179,14 +179,14 @@ func schedulersRegister() {
}
leaderID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}

storeIDs := make([]uint64, 0)
for _, id := range strings.Split(args[1], ",") {
storeID, err := strconv.ParseUint(id, 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}
storeIDs = append(storeIDs, storeID)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func schedulersRegister() {

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}
ranges, err := getKeyRanges(args[1:])
if err != nil {
Expand Down Expand Up @@ -364,7 +364,7 @@ func schedulersRegister() {
if len(args) == 1 {
limit, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return errs.ErrStrconvParseUint.Wrap(err).FastGenWithCause()
return errs.ErrStrconvParseUint.Wrap(err)
}
conf.Limit = limit
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/schedule/schedulers/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Scheduler interface {
func EncodeConfig(v interface{}) ([]byte, error) {
marshaled, err := json.Marshal(v)
if err != nil {
return nil, errs.ErrJSONMarshal.Wrap(err).FastGenWithCause()
return nil, errs.ErrJSONMarshal.Wrap(err)
}
return marshaled, nil
}
Expand All @@ -61,7 +61,7 @@ func EncodeConfig(v interface{}) ([]byte, error) {
func DecodeConfig(data []byte, v interface{}) error {
err := json.Unmarshal(data, v)
if err != nil {
return errs.ErrJSONUnmarshal.Wrap(err).FastGenWithCause()
return errs.ErrJSONUnmarshal.Wrap(err)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/schedule/schedulers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ func getKeyRanges(args []string) ([]core.KeyRange, error) {
for len(args) > 1 {
startKey, err := url.QueryUnescape(args[0])
if err != nil {
return nil, errs.ErrQueryUnescape.Wrap(err).FastGenWithCause()
return nil, errs.ErrQueryUnescape.Wrap(err)
}
endKey, err := url.QueryUnescape(args[1])
if err != nil {
return nil, errs.ErrQueryUnescape.Wrap(err).FastGenWithCause()
return nil, errs.ErrQueryUnescape.Wrap(err)
}
args = args[2:]
ranges = append(ranges, core.NewKeyRange(startKey, endKey))
Expand Down
2 changes: 1 addition & 1 deletion pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (kgm *KeyspaceGroupManager) InitializeGroupWatchLoop() error {
putFn := func(kv *mvccpb.KeyValue) error {
group := &endpoint.KeyspaceGroup{}
if err := json.Unmarshal(kv.Value, group); err != nil {
return errs.ErrJSONUnmarshal.Wrap(err).FastGenWithCause()
return errs.ErrJSONUnmarshal.Wrap(err)
}
kgm.updateKeyspaceGroup(group)
if group.ID == mcsutils.DefaultKeyspaceGroupID {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/logutil/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func StringToZapLogLevel(level string) zapcore.Level {
func SetupLogger(logConfig log.Config, logger **zap.Logger, logProps **log.ZapProperties, enabled ...bool) error {
lg, p, err := log.InitLogger(&logConfig, zap.AddStacktrace(zapcore.FatalLevel))
if err != nil {
return errs.ErrInitLogger.Wrap(err).FastGenWithCause()
return errs.ErrInitLogger.Wrap(err)
}
*logger = lg
*logProps = p
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/tempurl/check_env_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func checkAddr(addr string) (bool, error) {
return s.RemoteAddr.String() == addr || s.LocalAddr.String() == addr
})
if err != nil {
return false, errs.ErrNetstatTCPSocks.Wrap(err).FastGenWithCause()
return false, errs.ErrNetstatTCPSocks.Wrap(err)
}
return len(tabs) < 1, nil
}
2 changes: 1 addition & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (h *Handler) PluginLoad(pluginPath string) error {
// make sure path is in data dir
filePath, err := filepath.Abs(pluginPath)
if err != nil || !isPathInDirectory(filePath, h.s.GetConfig().DataDir) {
return errs.ErrFilePathAbs.Wrap(err).FastGenWithCause()
return errs.ErrFilePathAbs.Wrap(err)
}

c.LoadPlugin(pluginPath, ch)
Expand Down
Loading