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 initial support for connection attributes. #333

Closed
wants to merge 1 commit into from

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Apr 26, 2015

This sets attribute _client_name with the value "Go MySQL Driver"

Here processlist_id=58 is the connection from the Go MySQL Driver.

mysql> select * from performance_schema.session_connect_attrs; show processlist;
+----------------+-----------------+------------------+------------------+
| PROCESSLIST_ID | ATTR_NAME       | ATTR_VALUE       | ORDINAL_POSITION |
+----------------+-----------------+------------------+------------------+
|              3 | _os             | Linux            |                0 |
|              3 | _client_name    | libmysql         |                1 |
|              3 | _pid            | 3891             |                2 |
|              3 | _client_version | 5.7.7-rc         |                3 |
|              3 | _platform       | x86_64           |                4 |
|              3 | program_name    | Slave I/O Thread |                5 |
|              3 | channel_name    | NULL             |                6 |
|              6 | _os             | Linux            |                0 |
|              6 | _client_name    | libmysql         |                1 |
|              6 | _pid            | 3618             |                2 |
|              6 | _client_version | 5.7.7-rc         |                3 |
|              6 | _platform       | x86_64           |                4 |
|              6 | program_name    | Slave I/O Thread |                5 |
|              6 | channel_name    | testc1           |                6 |
|             58 | _client_name    | Go MySQL Driver  |                0 |
|             59 | _os             | Linux            |                0 |
|             59 | _client_name    | libmysql         |                1 |
|             59 | _pid            | 14429            |                2 |
|             59 | _client_version | 5.7.7-rc         |                3 |
|             59 | _platform       | x86_64           |                4 |
|             59 | program_name    | mysql            |                5 |
+----------------+-----------------+------------------+------------------+
21 rows in set (0.00 sec)

This could later be extended to:

  • Send more information
    • _os
    • _client_version
    • _pid
    • _platform
    • program_name
  • Send custom information
    • e.g. Key/Value pairs

The attributes send by the C library use _ and the application using the C library usually sets program_name to $0

@julienschmidt
Copy link
Member

How is this useful?

clientPsMultiResults
clientPluginAuth
clientConnectAttrs
clientExpiredPassword
Copy link
Member

Choose a reason for hiding this comment

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

You forgot CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA

@dveeden
Copy link
Contributor Author

dveeden commented May 3, 2015

@julienschmidt this is not really useful as this only sends one key/value pair.
To make this more useful it should send more information by default (driver version, pid etc) and should allow applications to define custom attributes.

Some uses:

  • Enrich audit logs by sending the end-user for which the application is working (like the X-Forwarded-For header in HTTP)
  • Make it easier to identify which client application is using a connection (e.g. program_name=my_long_running_cron_job) and use this to whitelist/blacklist it from something which automatically kills long running queries.
  • Have statistics on which end user, application, etc. uses the database.

@dveeden
Copy link
Contributor Author

dveeden commented May 3, 2015

Added the missing CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA

@dveeden
Copy link
Contributor Author

dveeden commented May 6, 2015

Rebased as the client attributes were updated in #336

This sets attribute _client_name with the value "Go MySQL Driver"
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.

2 participants