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 support for MySQL Connection Attributes #1241

Closed

Conversation

andygrunwald
Copy link

@andygrunwald andygrunwald commented Jul 31, 2021

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

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
    -> Not applicable
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file
    -> Skipped, because my work was minimal

Vasfed and others added 10 commits June 18, 2018 17:52
* 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)
  ...
@andygrunwald
Copy link
Author

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.

@andygrunwald
Copy link
Author

@methane @shogo82148 Just checking if there is any update on this or if you found time to have a look at this pull request?

packets.go Outdated Show resolved Hide resolved
packets.go Outdated Show resolved Hide resolved
@andygrunwald
Copy link
Author

I found out that the test TestRawBytesAreNotModified doesn't seem to be stable / a bit flaky.
In the test run 1606512033 it failed:

[...]
=== RUN   TestRawBytesAreNotModified
    driver_test.go:3075: context canceled
--- FAIL: TestRawBytesAreNotModified (0.31s)
[...]

Re-running the workflow (without any additional changes) succeeded.

If you wish that I create a dedicated ticket for this, please let me know.

packets.go Outdated Show resolved Hide resolved
Andy Co-Authored the PR for MySQL Connection Attributes,
based on the work from Vasily Fedoseyev
* master:
  Go 1.17 and MariaDB 10.6 are released (#1253)
  Fix sha256_password auth plugin on unix transport (#1246)
@andygrunwald
Copy link
Author

@dolmen @methane Thanks for your reviews so far. I incorporated your feedback and re-integrated this branch with master.
I kindly ask for a re-review. Let me know if there is anything else

driver_test.go Show resolved Hide resolved
driver_test.go Show resolved Hide resolved

// 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 {
Copy link
Member

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++
}
Copy link
Member

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?

Copy link

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++
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link

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.

@fulghum
Copy link

fulghum commented Jun 21, 2022

@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.

@methane
Copy link
Member

methane commented Jun 22, 2022

This pull request contains many changes unrelating to the feature requested.
That made both of author and me tired.
Please make PR minimum next time. But I can't say when I can review and merge it.

@andygrunwald
Copy link
Author

@fulghum @methane Your comments are fair and I should have done a better job here.
This PR is not (fully) my work. I grabbed the work from @Vasfed in #737 and try to adjust it to the latest main.

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.
Otherwise, I will take this on once I have a bit of spare time.

@Daemonxiao Daemonxiao mentioned this pull request Jan 31, 2023
5 tasks
pmishchenko-ua added a commit to memsql/go-singlestore-driver that referenced this pull request Apr 11, 2023
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
@methane methane closed this May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants