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

session: use the uniform log format for session #9517

Merged
merged 9 commits into from
Mar 21, 2019

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Mar 1, 2019

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

  • Unit test

Code changes

  • Has exported function/method change

Related changes

  • Need to cherry-pick to the release branch

@jackysp jackysp added type/enhancement The issue or PR belongs to an enhancement. component/session labels Mar 1, 2019
@jackysp jackysp requested a review from zimulala March 1, 2019 06:03
@jackysp
Copy link
Member Author

jackysp commented Mar 1, 2019

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Mar 1, 2019

pingcap/parser#227 merge it first.

@jackysp
Copy link
Member Author

jackysp commented Mar 1, 2019

/run-all-tests

1 similar comment
@cwen0
Copy link
Member

cwen0 commented Mar 1, 2019

/run-all-tests

@codecov-io
Copy link

codecov-io commented Mar 1, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@1da14b9). Click here to learn what that means.
The diff coverage is 64.1025%.

@@             Coverage Diff             @@
##             master      #9517   +/-   ##
===========================================
  Coverage          ?   69.7115%           
===========================================
  Files             ?        381           
  Lines             ?      89090           
  Branches          ?          0           
===========================================
  Hits              ?      62106           
  Misses            ?      21846           
  Partials          ?       5138

log.Error("[Upgrade] upgrade error",
zap.Int64("from", ver),
zap.Int("to", currentBootstrapVersion))
log.Fatal(err.Error())
Copy link
Contributor

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)),
Copy link
Contributor

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.

@@ -238,7 +239,7 @@ const (
func bootstrap(s Session) {
b, err := checkBootstrapped(s)
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
Copy link
Contributor

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?

Copy link
Member Author

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.

@@ -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()))
Copy link
Member

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)

@jackysp jackysp dismissed a stale review via fdb5f6c March 10, 2019 04:34
@jackysp jackysp force-pushed the session_log branch 2 times, most recently from fdb5f6c to 0c44729 Compare March 10, 2019 04:37
@jackysp
Copy link
Member Author

jackysp commented Mar 11, 2019

PTAL @lysu @zimulala

@@ -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()))
Copy link
Contributor

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.

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()),
Copy link
Contributor

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()))
Copy link
Contributor

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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zap.Stringer

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Domain/domain

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Store/store

@@ -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",
Copy link
Contributor

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.

i, sqlForLog(st.OriginText()), sessVars.GetExecuteArgumentsInfo())
logutil.Logger(ctx).Warn("Retrying",
zap.Int64("schemaVersion", schemaVersion),
zap.Uint("retry_cnt", retryCnt),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/retry_cnt/retryCnt

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala
Copy link
Contributor

PTAL @lysu @winoros

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 21, 2019
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jackysp jackysp added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 21, 2019
@jackysp jackysp merged commit 4a5b3c2 into pingcap:master Mar 21, 2019
jackysp added a commit to jackysp/tidb that referenced this pull request Apr 2, 2019
@jackysp jackysp deleted the session_log branch April 4, 2019 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/session status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants