-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
session: use the uniform log format for session #9517
Conversation
/run-all-tests |
pingcap/parser#227 merge it first. |
/run-all-tests |
1 similar comment
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #9517 +/- ##
===========================================
Coverage ? 69.7115%
===========================================
Files ? 381
Lines ? 89090
Branches ? 0
===========================================
Hits ? 62106
Misses ? 21846
Partials ? 5138 |
session/bootstrap.go
Outdated
log.Error("[Upgrade] upgrade error", | ||
zap.Int64("from", ver), | ||
zap.Int("to", currentBootstrapVersion)) | ||
log.Fatal(err.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.
Could we put these two logs together?
session/txn.go
Outdated
zap.String("TxnState", st.GoString()), | ||
zap.String("mutations", fmt.Sprintf("%#v", st.mutations)), | ||
zap.String("dirtyTableOP", fmt.Sprintf("%#v", st.dirtyTableOP)), | ||
zap.String("buf", fmt.Sprintf("%#v", st.buf)), |
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.
Could we add the String()
for buf
? Maybe other places will use it too.
session/bootstrap.go
Outdated
@@ -238,7 +239,7 @@ const ( | |||
func bootstrap(s Session) { | |||
b, err := checkBootstrapped(s) | |||
if err != nil { | |||
log.Fatal(err) | |||
log.Fatal(err.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.
Do we need to add more information to these logs?
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.
There're too many of them. It is better to do it in another PR.
session/session.go
Outdated
@@ -267,13 +268,13 @@ func (s *session) StoreQueryFeedback(feedback interface{}) { | |||
if s.statsCollector != nil { | |||
do, err := GetDomain(s.store) | |||
if err != nil { | |||
log.Debug("domain not found: ", err) | |||
log.Debug("Domain not found", zap.String("error", err.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.
We can directly use zap.Error(err)
fdb5f6c
to
0c44729
Compare
session/session.go
Outdated
@@ -1191,7 +1223,8 @@ func (s *session) Auth(user *auth.UserIdentity, authentication []byte, salt []by | |||
} | |||
} | |||
|
|||
log.Errorf("User connection verification failed %s", user) | |||
log.Error("User connection verification failed", | |||
zap.String("user", user.String())) |
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.
zap.Stringer
can avoid String()
call if error log level isnt' enable.
session/session.go
Outdated
log.Warnf("[%s] con:%d session:%v, err:%v in retry", label, connID, s, err) | ||
logutil.Logger(ctx).Warn("SQL", | ||
zap.String("label", label), | ||
zap.String("session", s.String()), |
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.
zap.Stringer
logutil.Logger(ctx).Warn("SQL", | ||
zap.String("label", s.getSQLLabel()), | ||
zap.Error(err), | ||
zap.String("txn", s.txn.GoString())) |
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 we can make another PR to let zap support zap.GoStringer
😆
session/tidb.go
Outdated
log.Info("New domain", | ||
zap.String("store", store.UUID()), | ||
zap.String("ddl lease", ddlLease.String()), | ||
zap.String("stats lease", statisticLease.String())) |
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.
zap.Stringer
session/session.go
Outdated
@@ -267,13 +268,13 @@ func (s *session) StoreQueryFeedback(feedback interface{}) { | |||
if s.statsCollector != nil { | |||
do, err := GetDomain(s.store) | |||
if err != nil { | |||
log.Debug("domain not found: ", err) | |||
logutil.Logger(context.Background()).Debug("Domain not found", 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.
s/Domain/domain
session/session.go
Outdated
metrics.StoreQueryFeedbackCounter.WithLabelValues(metrics.LblError).Inc() | ||
return | ||
} | ||
err = s.statsCollector.StoreQueryFeedback(feedback, do.StatsHandle()) | ||
if err != nil { | ||
log.Debug("store query feedback error: ", err) | ||
logutil.Logger(context.Background()).Debug("Store query feedback", 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.
s/Store/store
session/session.go
Outdated
@@ -408,7 +412,9 @@ func (s *session) doCommitWithRetry(ctx context.Context) error { | |||
} | |||
|
|||
if err != nil { | |||
log.Warnf("con:%d finished txn:%#v, %v", s.sessionVars.ConnectionID, &s.txn, err) | |||
logutil.Logger(ctx).Warn("Commit failed", |
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.
s/Commit/commit
Please update other places as well.
session/session.go
Outdated
i, sqlForLog(st.OriginText()), sessVars.GetExecuteArgumentsInfo()) | ||
logutil.Logger(ctx).Warn("Retrying", | ||
zap.Int64("schemaVersion", schemaVersion), | ||
zap.Uint("retry_cnt", retryCnt), |
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.
s/retry_cnt/retryCnt
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.
LGTM
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.
lgtm
What problem does this PR solve?
Use the uniform log format for session.
What is changed and how it works?
Use the uniform log format for session.
Check List
Tests
Code changes
Related changes