-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for MySQL Connection Attributes #1241
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 support for MySQL Connection Attributes #1241
Conversation
* master: (93 commits) return unsigned in database type name when necessary (#1238) add an invalid DSN test case (#1235) refactoring (*textRows).readRow in a more clear way (#1230) use utf8mb4 instead of utf8 in TestCharset (#1228) improve readability follows go-staticcheck (#1227) support Is comparison on MySQLError (#1210) Wording correction in README (#1218) noCopy implements sync.Locker (#1216) Fix readme: MaxIdle is same or less than MaxOpen (#1215) Drop support of Go 1.12 (#1211) Release v1.6.0 (#1197) add Go 1.16 to the build matrix (#1198) Implement driver.Validator interface (#1174) handling decoding pem error (#1192) stop rounding times (#1172) improve GitHub Actions workflows (#1190) Move tests from Travis to Actions (#1183) Fix go vet error (#1173) README: Make usage code more friendly (#1170) Fix a broken link to cleartext client side plugin (#1165) ...
I added a small example to showcase / use this feature: https://github.com/andygrunwald/your-connection-deserves-a-name/blob/mysql-go/mysql/go/main.go This code is using my fork, and I can confirm that this feature is working as expected. |
@methane @shogo82148 Just checking if there is any update on this or if you found time to have a look at this pull request? |
…m/go-sql-driver/mysql"
This behaviour is very similar to the native C# MySQL driver. See https://github.com/mysql/mysql-connector-net/blob/502d718bed8ca9cf81a3a0397574f24ec41b25ba/MySQL.Data/src/X/Sessions/XInternalSession.cs#L450-L469
I found out that the test
Re-running the workflow (without any additional changes) succeeded. If you wish that I create a dedicated ticket for this, please let me know. |
…e it is always set
Andy Co-Authored the PR for MySQL Connection Attributes, based on the work from Vasily Fedoseyev
|
||
// To specify a db name | ||
if n := len(mc.cfg.DBName); n > 0 { | ||
if n := len(mc.cfg.DBName); mc.flags&clientConnectWithDB != 0 && n > 0 { |
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.
revert this.
@@ -312,9 +321,42 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string | |||
} | |||
|
|||
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 + len(authRespLEI) + len(authResp) + 21 + 1 | |||
if clientFlags&clientSecureConn == 0 || clientFlags&clientPluginAuthLenEncClientData == 0 { | |||
pktLen++ | |||
} |
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 is this if
block needed?
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.
@andygrunwald – any context on this one? Tests pass correctly without this block. I'll dig in deeper if you don't remember why this was needed.
} else if clientFlags&clientSecureConn != 0 { | ||
data[pos] = uint8(len(authResp)) | ||
pos++ | ||
} |
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 is this needed?
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.
@andygrunwald – do you remember any context on this one? I tried removing this block and confirmed many tests fail. I'll dig in deeper tomorrow, but wanted to start off seeing if you remembered this code.
@andygrunwald – Any updates on support for connection attributes? We'd love to see this feature land and would be happy to help out if needed. I've reintegrated master with this branch locally – no conflicts and I can confirm all tests are still passing. @methane and @dolmen – any advice for moving this forward? I'm happy to take over in another PR if needed. Seems like this is really close and would be a helpful feature to land. |
This pull request contains many changes unrelating to the feature requested. |
@fulghum @methane Your comments are fair and I should have done a better job here. It might be a good thing to re-do this again and compare the changes here to the MySQL spec and see what is really needed. Right now, I am not able to do this, due to limited time available. Just a heads up to set expectations. If someone is reading this and eager to jump in it: Go for it. |
Summary: In order to be able track Go client usage we enable sending connection attributes as specified in https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_handshake_response.html (CLIENT_CONNECT_ATTRS). This commit is based on PR go-sql-driver#1241 which is based on PR go-sql-driver#737 (which are still open as of 11.04.2023) Test Plan: manual integration test will be added to the main repo Reviewers: amakarovych-ua, okramarenko-ua Reviewed By: okramarenko-ua Subscribers: engineering-list Differential Revision: https://grizzly.internal.memcompute.com/D61981
Description
This Pull Request adds support for sending connection attributes, which are used for identifying individual connections in MySQL.
See MySQL docs: Performance Schema Connection Attribute Tables.
This feature is supported since MySQL v 5.6.6.
The main work of this pull request was done by @Vasfed in #737.
This Pull Request reintegrates #737 with the current master and gets all unit tests running.
Checklist
-> Not applicable
-> Skipped, because my work was minimal