-
Notifications
You must be signed in to change notification settings - Fork 727
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
server: refine package server error log format in RFC #2713
Conversation
server/member/leader.go
Outdated
@@ -248,10 +249,10 @@ func (m *Member) CampaignLeader(lease *LeaderLease, leaseTimeout int64) error { | |||
Then(clientv3.OpPut(leaderKey, m.memberValue, clientv3.WithLease(lease.ID))). | |||
Commit() | |||
if err != nil { | |||
return errors.WithStack(err) | |||
return errs.ErrEtcdLeaderSave.FastGenByArgs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe return err directly, we need to know the actual error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fix it, PTAL @nolouch
/run-all-tests |
server/handler.go
Outdated
@@ -223,7 +224,7 @@ func (h *Handler) RemoveScheduler(name string) error { | |||
return err | |||
} | |||
if err = c.RemoveScheduler(name); err != nil { | |||
log.Error("can not remove scheduler", zap.String("scheduler-name", name), zap.Error(err)) | |||
log.Error("can not remove scheduler", zap.Error(errs.ErrSchedulerOperation.FastGenByArgs(name)), zap.NamedError("cause", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the error already is an RFC error? cc @rleungx
Please resolve the conflicts. |
199d8f0
to
1657e05
Compare
@@ -1094,7 +1095,7 @@ func (s *Server) campaignLeader() { | |||
zap.String("campaign-pd-leader-name", s.Name()), | |||
zap.String("purpose", s.member.Leadership.Purpose)) | |||
if err := s.member.Leadership.Campaign(s.cfg.LeaderLease, s.member.GetLeaderPath(), s.member.MemberValue()); err != nil { | |||
log.Error("campaign pd leader meet error", zap.Error(err)) | |||
log.Error("campaign pd leader meet error", errs.ZapError(errs.ErrCampaignLeader, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this is already a RFC error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It is a local error caused by lease or etcd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to wrap the third error to RFC error in member
package rather than in the server package. if the error is not returned by a third-party package, just print the log directly or return the error directly.
@@ -1112,18 +1113,18 @@ func (s *Server) campaignLeader() { | |||
|
|||
log.Info("initialize the global TSO allocator") | |||
if err := s.tsoAllocator.Initialize(); err != nil { | |||
log.Error("failed to initialize the global TSO allocator", zap.Error(err)) | |||
log.Error("failed to initialize the global TSO allocator", errs.ZapError(errs.ErrCreateTSOStream, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz directly use RFC error.
server/grpc_service.go
Outdated
@@ -395,7 +396,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error { | |||
|
|||
region := core.RegionFromHeartbeat(request) | |||
if region.GetLeader() == nil { | |||
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request)) | |||
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the err
come from?
@@ -209,9 +210,9 @@ func (h *Handler) AddScheduler(name string, args ...string) error { | |||
} | |||
log.Info("create scheduler", zap.String("scheduler-name", s.GetName())) | |||
if err = c.AddScheduler(s, args...); err != nil { | |||
log.Error("can not add scheduler", zap.String("scheduler-name", s.GetName()), zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the scheduler-name
?
server/heartbeat_streams.go
Outdated
@@ -87,15 +88,15 @@ func (s *heartbeatStreams) run() { | |||
if store == nil { | |||
log.Error("failed to get store", | |||
zap.Uint64("region-id", msg.RegionId), | |||
zap.Uint64("store-id", storeID)) | |||
errs.ZapError(errs.ErrStoreNotFound, nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the store-id
?
server/grpc_service.go
Outdated
@@ -396,7 +396,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error { | |||
|
|||
region := core.RegionFromHeartbeat(request) | |||
if region.GetLeader() == nil { | |||
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, err)) | |||
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to change the ZapError
to make the cause error as an optional parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sign-off DCO. The rest LGTM
286c58f
to
60facde
Compare
Signed-off-by: ZenoTan <[email protected]>
Signed-off-by: ZenoTan <[email protected]>
Why change the file permission? |
// ZapError is used to make the log output easier. | ||
func ZapError(err *errors.Error, causeError ...error) zap.Field { | ||
var e interface{} | ||
if len(causeError) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the len > 1?
@@ -1094,7 +1095,7 @@ func (s *Server) campaignLeader() { | |||
zap.String("campaign-pd-leader-name", s.Name()), | |||
zap.String("purpose", s.member.Leadership.Purpose)) | |||
if err := s.member.Leadership.Campaign(s.cfg.LeaderLease, s.member.GetLeaderPath(), s.member.MemberValue()); err != nil { | |||
log.Error("campaign pd leader meet error", zap.Error(err)) | |||
log.Error("campaign pd leader meet error", errs.ZapError(errs.ErrCampaignLeader, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to wrap the third error to RFC error in member
package rather than in the server package. if the error is not returned by a third-party package, just print the log directly or return the error directly.
What problem does this PR solve?
Solve #2704
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
Release note