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

*: Add system variable tidb_session_alias to log a custom field session_alias in session log #46072

Merged
merged 6 commits into from
Aug 18, 2023

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Aug 14, 2023

What problem does this PR solve?

Issue Number: close #46071

What is changed and how it works?

A new system variable tidb_session_alias with session scope is added. After this PR, we can trace some session in log identified by this field. for example:

> set @@tidb_session_alias='custom_session1';
> select * from tnoexist; -- select from a not exist table

Some log will be printed and you can see session_alias in it.

[2023/08/14 17:48:50.766 +08:00] [WARN] [session.go:2255] ["compile SQL failed"] [conn=2097154] [session_alias=custom_session1] [error="[schema:1146]Table 'test.tnoexist' doesn't exist"] [SQL="select * from tnoexist"]
[2023/08/14 17:48:50.766 +08:00] [INFO] [conn.go:1096] ["command dispatched failed"] [conn=2097154] [session_alias=custom_session1] [connInfo="id:2097154, addr:127.0.0.1:61498 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="select * from tnoexist"] [txn_mode=PESSIMISTIC] [timestamp=0] [err="[schema:1146]Table 'test.tnoexist' doesn't exist"]

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Add system variable `tidb_session_alias` to log a custom field `session_alias` in session log

@lcwangchao lcwangchao requested a review from a team as a code owner August 14, 2023 09:50
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 14, 2023
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #46072 (f5a6976) into master (5f41a0f) will decrease coverage by 2.0678%.
Report is 14 commits behind head on master.
The diff coverage is 80.5825%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46072        +/-   ##
================================================
- Coverage   74.7886%   72.7208%   -2.0678%     
================================================
  Files          1297       1306         +9     
  Lines        398784     400621      +1837     
================================================
- Hits         298245     291335      -6910     
- Misses        81155      90790      +9635     
+ Partials      19384      18496       -888     
Flag Coverage Δ
integration 25.5950% <31.2500%> (-20.6533%) ⬇️
unit 73.4025% <80.5825%> (+0.0241%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 85.0765% <0.0000%> (ø)
br 47.8865% <ø> (-16.6485%) ⬇️

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 15, 2023
lcwangchao and others added 3 commits August 17, 2023 16:03
Co-authored-by: bb7133 <bb7133@gmail.com>
Co-authored-by: bb7133 <bb7133@gmail.com>
Co-authored-by: bb7133 <bb7133@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 17, 2023
@lcwangchao lcwangchao force-pushed the tidb_session_alias branch 2 times, most recently from 53399d1 to 0a6e2a0 Compare August 17, 2023 11:34
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 18, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 18, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-08-15 10:35:13.299620691 +0000 UTC m=+627277.848636663: ☑️ agreed by CbcWestwolf.
  • 2023-08-18 03:27:36.041872637 +0000 UTC m=+860820.590888624: ☑️ agreed by bb7133.

@lcwangchao
Copy link
Collaborator Author

/approve

@easonn7
Copy link

easonn7 commented Aug 18, 2023

/approve

@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 18, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, CbcWestwolf, easonn7, lcwangchao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Aug 18, 2023
@lcwangchao
Copy link
Collaborator Author

/retest

@tiprow
Copy link

tiprow bot commented Aug 18, 2023

@lcwangchao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tiprow_fast_test f5a6976 link true /test tiprow_fast_test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot merged commit ddb7b36 into pingcap:master Aug 18, 2023
@lcwangchao lcwangchao deleted the tidb_session_alias branch August 18, 2023 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a new system variable tidb_session_alias to print some custom trace info in log
4 participants